Spaces:
Configuration error
Configuration error
File size: 1,112 Bytes
3f70c4e c991d6d 8b40e41 3f70c4e c991d6d 3f70c4e 6f9e96f 3f70c4e 73f8fa4 3f70c4e c991d6d 3f70c4e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | package services
import (
"errors"
"api.qobiltu.id/middleware"
"api.qobiltu.id/models"
"api.qobiltu.id/repositories"
)
type LoginConstructor struct {
Email string
Password string
}
type AuthenticationService struct {
Service[LoginConstructor, models.AuthenticatedUser]
}
func (s *AuthenticationService) Authenticate() {
accountData := repositories.GetAccountbyEmail(s.Constructor.Email)
if accountData.NoRecord {
s.Exception.DataNotFound = true
s.Exception.Message = "there is no account with given credentials!"
return
}
if middleware.VerifyPassword(accountData.Result.Password, s.Constructor.Password) != nil {
s.Exception.Unauthorized = true
s.Exception.Message = "incorrect password!"
return
}
token, err_tok := middleware.GenerateToken(&accountData.Result)
if err_tok != nil {
s.Error = errors.Join(s.Error, err_tok)
}
accountData.Result.Password = "SECRET"
s.Result = models.AuthenticatedUser{
Account: accountData.Result,
Token: token,
}
s.Error = accountData.RowsError
}
// LoginHandler handles user login
|