35 lines
702 B
Go
35 lines
702 B
Go
package authsvc
|
|
|
|
import (
|
|
"errors"
|
|
|
|
authdomain "legalgo-BE-go/internal/domain/auth"
|
|
"legalgo-BE-go/internal/utilities/utils"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
func (sv *AuthSvc) LoginAsStaff(spec authdomain.LoginReq) (string, error) {
|
|
staff, err := sv.staffRepo.GetStaffByEmail(spec.Email)
|
|
if err != nil {
|
|
return "", errors.New(err.Error())
|
|
}
|
|
|
|
matchPassword := ComparePassword(staff.Password, spec.Password)
|
|
if !matchPassword {
|
|
return "", errors.New("wrong password")
|
|
}
|
|
|
|
authToken := authdomain.AuthToken{
|
|
Email: staff.Email,
|
|
SessionID: uuid.NewString(),
|
|
}
|
|
|
|
token, err := utils.GenerateToken(authToken)
|
|
if err != nil {
|
|
return "", errors.New(err.Error())
|
|
}
|
|
|
|
return token, nil
|
|
}
|