feat: integrate tenant SSO and remote toggle
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
660d5291ec
commit
ca5765b988
27 changed files with 529 additions and 159 deletions
|
|
@ -28,6 +28,7 @@ const CandidateThreshold = 60.0
|
|||
|
||||
type IAuthService interface {
|
||||
Login(context.Context, string, string) (string, model.User, error)
|
||||
EstablishExternalSession(context.Context, string, string) (string, model.User, error)
|
||||
}
|
||||
|
||||
type IJobService interface {
|
||||
|
|
@ -88,6 +89,36 @@ func (s *AuthService) Login(ctx context.Context, email, password string) (string
|
|||
return token, user, nil
|
||||
}
|
||||
|
||||
func (s *AuthService) EstablishExternalSession(ctx context.Context, email, displayName string) (string, model.User, error) {
|
||||
email = strings.ToLower(strings.TrimSpace(email))
|
||||
displayName = strings.TrimSpace(displayName)
|
||||
if email == "" {
|
||||
return "", model.User{}, ErrValidation
|
||||
}
|
||||
user, err := s.store.FindUserByEmail(ctx, email)
|
||||
if errors.Is(err, repository.ErrNotFound) {
|
||||
if displayName == "" {
|
||||
displayName = email
|
||||
}
|
||||
hash, hashErr := security.HashPassword(uuid.NewString())
|
||||
if hashErr != nil {
|
||||
return "", model.User{}, hashErr
|
||||
}
|
||||
user, err = s.store.CreateUser(ctx, model.User{
|
||||
Email: email, DisplayName: displayName, Role: "interviewer", PasswordHash: hash,
|
||||
})
|
||||
}
|
||||
if err != nil {
|
||||
return "", model.User{}, err
|
||||
}
|
||||
token, err := s.tokens.Issue(user.ID, user.Email, user.Role)
|
||||
if err != nil {
|
||||
return "", model.User{}, err
|
||||
}
|
||||
user.PasswordHash = ""
|
||||
return token, user, nil
|
||||
}
|
||||
|
||||
type JobService struct {
|
||||
store repository.IStore
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue