server/api/auth.go

58 lines
1.0 KiB
Go

package api
import (
"net/http"
"git.tek.govt.hu/dowerx/chat/server/controller"
"github.com/gin-gonic/gin"
)
func isLoggedIn(c *gin.Context) {
}
func register(c *gin.Context) {
type registerTransaction struct {
Username string `form:"username"`
Password string `form:"password"`
RepeatPassword string `form:"repeatPassword"`
}
transaction := registerTransaction{}
if err := c.Bind(&transaction); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"error": err.Error(),
})
return
}
userController, err := controller.MakeUserController()
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
"error": err.Error(),
})
return
}
err = userController.Register(transaction.Username, transaction.Password, transaction.RepeatPassword)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"error": err.Error(),
})
return
}
c.JSON(http.StatusOK, gin.H{
"message": "sucessful register",
})
}
func login(c *gin.Context) {
}
func logout(c *gin.Context) {
}