28 lines
620 B
Go
28 lines
620 B
Go
package authsvc
|
|
|
|
import (
|
|
"errors"
|
|
|
|
authdomain "github.com/ardeman/project-legalgo-go/internal/domain/auth"
|
|
"github.com/ardeman/project-legalgo-go/internal/utilities/utils"
|
|
)
|
|
|
|
func (a *AuthSvc) LoginAsUser(spec authdomain.LoginReq) (string, error) {
|
|
user, err := a.userRepo.GetUserByEmail(spec.Email)
|
|
if err != nil {
|
|
return "", errors.New(err.Error())
|
|
}
|
|
|
|
matchPassword := ComparePassword(user.Password, spec.Password)
|
|
if !matchPassword {
|
|
return "", errors.New("wrong password")
|
|
}
|
|
|
|
token, err := utils.GenerateToken(user.Email)
|
|
if err != nil {
|
|
return "", errors.New(err.Error())
|
|
}
|
|
|
|
return token, nil
|
|
}
|