📚 The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.
Vue dockergolangkanbanknowledge-baseknowledge-managementmarkdownnote-takingnotesnotes-appnotionnuxtnuxtjsoffline-firstoidcpwaselfhostedssovuevuejswiki
Fix user patch & auth
Smaug6739a9e8628e492d
diff --git a/backend/controllers/authentification.controller.go b/backend/controllers/authentification.controller.goindex 70c81948..6b713bfd 100644--- a/backend/controllers/authentification.controller.go+++ b/backend/controllers/authentification.controller.go@@ -84,7 +84,7 @@ func (dc *AuthControllerImpl) Login(c *gin.Context) {c.SetCookie("Authorization", tokenString, 1800, "/", "localhost", false, true)c.SetCookie("RefreshToken", session.RefreshToken, int(time.Duration(dc.app.Config.Auth.RefreshTokenExpiry).Seconds()), "/", "localhost", false, true)-+ user.Password = ""c.JSON(200, utils.Success(user))}diff --git a/backend/controllers/users.controller.go b/backend/controllers/users.controller.goindex 629ffd71..59f40443 100644--- a/backend/controllers/users.controller.go+++ b/backend/controllers/users.controller.go@@ -3,7 +3,7 @@ package controllersimport ("Smaug6739/Alexandrie/app""Smaug6739/Alexandrie/models"- service "Smaug6739/Alexandrie/services"+ "Smaug6739/Alexandrie/services""Smaug6739/Alexandrie/utils""net/http""strconv"@@ -23,12 +23,12 @@ type UserController interface {}type UserControllerImpl struct {Controller- user_service service.UserService+ user_service services.UserService}func NewUserController(app *app.App) UserController {return &UserControllerImpl{- user_service: service.NewUserService(app.DB),+ user_service: services.NewUserService(app.DB),Controller: Controller{app: app,},@@ -115,6 +115,10 @@ func (ctr *UserControllerImpl) CreateUser(c *gin.Context) {c.JSON(http.StatusBadRequest, utils.Error(err.Error()))return}+ if len(user.Password) == 0 {+ c.JSON(http.StatusBadRequest, utils.Error("Password must be provided."))+ return+ }hash, err := bcrypt.GenerateFromPassword([]byte(user.Password), bcrypt.DefaultCost)if err != nil {c.JSON(http.StatusInternalServerError, utils.Error("Failed to hash password"))@@ -133,10 +137,7 @@ func (ctr *UserControllerImpl) CreateUser(c *gin.Context) {UpdatedTimestamp: time.Now().UnixMilli(),}// Specific validation for username and password- if len(user.Password) == 0 {- c.JSON(http.StatusBadRequest, utils.Error("Password must be provided."))- return- }+exists := ctr.user_service.CheckUsernameExists(user.Username)if exists {c.JSON(http.StatusBadRequest, utils.Error("Username already exists."))@@ -183,11 +184,11 @@ func (ctr *UserControllerImpl) UpdateUser(c *gin.Context) {user = models.User{Id: id,Username: dbUser.Username,- Firstname: utils.IfNotNilOrDefault(user.Firstname, dbUser.Firstname),- Lastname: utils.IfNotNilOrDefault(user.Lastname, dbUser.Lastname),- Avatar: utils.IfNotNilOrDefault(user.Avatar, dbUser.Avatar),+ Firstname: utils.IfNotNilPointer(user.Firstname, dbUser.Firstname),+ Lastname: utils.IfNotNilPointer(user.Lastname, dbUser.Lastname),+ Avatar: utils.IfNotNilPointer(user.Avatar, dbUser.Avatar),Role: dbUser.Role,- Email: utils.IfNotNilOrDefault(user.Email, dbUser.Email),+ Email: utils.IfNotNilValue(&user.Email, dbUser.Email),CreatedTimestamp: dbUser.CreatedTimestamp,UpdatedTimestamp: time.Now().UnixMilli(),}diff --git a/backend/utils/utils.go b/backend/utils/utils.goindex da4ea5d3..3d75c267 100644--- a/backend/utils/utils.go+++ b/backend/utils/utils.go@@ -1,16 +1,14 @@package utils-func IfNotNilOrDefault[T comparable](newValue any, defaultValue T) T {- // Si newValue est un pointeur et non nil, on le dé-référence- if v, ok := newValue.(*T); ok && v != nil {- return *v+func IfNotNilPointer[T any](newValue, defaultValue *T) *T {+ if newValue != nil {+ return newValue}-- // Si newValue est une valeur directe non nulle (cas des strings par exemple), on le retourne- if v, ok := newValue.(T); ok {- return v+ return defaultValue+}+func IfNotNilValue[T any](newValue *T, defaultValue T) T {+ if newValue != nil {+ return *newValue}-- // Sinon, on retourne la valeur par défautreturn defaultValue}