package auth import ( "cls/internal/application/crypto" "cls/internal/domain/auth" "cls/pkg/logger" ) type AuthService struct { auth auth.AuthRepository phoneEncryption *crypto.PhoneEncryptionService passwordHash *crypto.PasswordHashService log logger.Logger jwtSecretKey string } func NewAuthService(auth auth.AuthRepository, phoneEncryption *crypto.PhoneEncryptionService, passwordHash *crypto.PasswordHashService, log logger.New) *AuthService { return &AuthService{auth, phoneEncryption, passwordHash, log("cls:service:auth"), ""} } func (a *AuthService) SetJWTSecretKey(secretKey string) { a.jwtSecretKey = secretKey } func (a *AuthService) GetJWTSecretKey() string { return a.jwtSecretKey } func (a *AuthService) LoginByCaptcha(phone string) (string, error) { ePhone, err := a.phoneEncryption.Encrypt(phone) if err != nil { a.log.Error(err.Error()) return "", err } token, err := a.auth.LoginByCaptcha(ePhone) if err != nil { return "", err } return token, nil } func (a *AuthService) LoginByPassword(phone, password string) (string, error) { ePhone, err := a.phoneEncryption.Encrypt(phone) if err != nil { a.log.Error(err.Error()) return "", err } ePassword, err := a.passwordHash.Hash(password) if err != nil { a.log.Error(err.Error()) return "", err } token, err := a.auth.LoginByPassword(ePhone, ePassword) if err != nil { return "", err } return token, nil }