clortho/apis/apis_utils_test.go
Maxime Duchene-Savard d295c13e78 auth api work
2025-03-30 23:43:03 -04:00

29 lines
583 B
Go

package apis
import (
"clortho/db"
"clortho/users"
"github.com/gin-gonic/gin"
)
func MockAuthMiddleware(user db.User) gin.HandlerFunc {
return func(c *gin.Context) {
session := users.NewSession(user)
c.Set("session", session)
}
}
func InitUser(username string, password string) (*db.User, error) {
user := users.GetUser(username)
if user == nil {
user, _ = users.CreateUser(username)
}
passHash, _ := users.HashPassword(password)
user.PasswordHash = &passHash
res := db.Connection.Save(&user)
if res.Error != nil {
return nil, res.Error
}
return user, nil
}