add endpoints for kontor-api

This commit is contained in:
Thomas Peetz
2026-01-09 17:04:46 +01:00
parent 98eb72bd22
commit e5d4b748dc
12 changed files with 95 additions and 30 deletions
+17 -5
View File
@@ -18,9 +18,21 @@ type jwtCustomClaims struct {
jwt.RegisteredClaims
}
type LoginRequest struct {
Email string `json:"email"`
Password string `json:"password"`
}
func Login(c echo.Context) error {
user := c.FormValue("user")
pass := c.FormValue("pass")
// user := c.FormValue("email")
// pass := c.FormValue("password")
loginRequest := new(LoginRequest)
if err := c.Bind(loginRequest); err != nil {
return err
}
email := loginRequest.Email
password := loginRequest.Password
var profile schema.Profile
var err error
@@ -28,12 +40,12 @@ func Login(c echo.Context) error {
ctx := context.Background()
db, _ = schema.GetDatabase()
err = db.NewSelect().Model(&profile).Where("email = ?", user).Scan(ctx)
err = db.NewSelect().Model(&profile).Where("email = ?", email).Scan(ctx)
if err != nil {
return c.String(http.StatusInternalServerError, err.Error())
}
if !utils.ComparePassword(profile.Password, pass) {
if !utils.ComparePassword(profile.Password, password) {
return echo.ErrUnauthorized
}
@@ -55,7 +67,7 @@ func Login(c echo.Context) error {
return err
}
return c.JSON(http.StatusOK, echo.Map{"token": t})
return c.JSON(http.StatusOK, echo.Map{"access_token": t, "token_type": "bearer"})
}
func restricted(c echo.Context) error {