1
0

Made registration work

This commit is contained in:
konrad
2018-06-10 11:34:59 +02:00
committed by kolaente
parent 2ca4c521aa
commit 1bee67cac7
6 changed files with 14 additions and 20 deletions

View File

@ -1,4 +1,4 @@
package routes
package v1
import (
"crypto/md5"
@ -29,11 +29,9 @@ func Login(c echo.Context) error {
// Set claims
claims := token.Claims.(jwt.MapClaims)
claims["name"] = user.Name
claims["username"] = user.Username
claims["email"] = user.Email
claims["id"] = user.ID
claims["admin"] = user.IsAdmin
claims["exp"] = time.Now().Add(time.Hour * 72).Unix()
avatar := md5.Sum([]byte(user.Email))

View File

@ -7,6 +7,7 @@ import (
"net/http"
"strconv"
"strings"
"fmt"
)
// UserAddOrUpdate is the handler to add a user
@ -51,18 +52,14 @@ func UserAddOrUpdate(c echo.Context) error {
return c.JSON(http.StatusInternalServerError, models.Message{"Could not check if the user exists."})
}
// Get the doer options
doer, err := models.GetCurrentUser(c)
if err != nil {
return err
}
fmt.Println(exists)
// Insert or update the user
var newUser models.User
if exists {
newUser, err = models.UpdateUser(*datUser, &doer)
newUser, err = models.UpdateUser(*datUser)
} else {
newUser, err = models.CreateUser(*datUser, &doer)
newUser, err = models.CreateUser(*datUser)
}
if err != nil {

View File

@ -39,10 +39,12 @@ func RegisterRoutes(e *echo.Echo) {
// CORS_SHIT
a.OPTIONS("/login", SetCORSHeader)
a.OPTIONS("/register", SetCORSHeader)
a.OPTIONS("/users", SetCORSHeader)
a.OPTIONS("/users/:id", SetCORSHeader)
a.POST("/login", Login)
a.POST("/login", apiv1.Login)
a.POST("/register", apiv1.UserAddOrUpdate)
// ===== Routes with Authetification =====
// Authetification