add endpoints for kontor-api
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user