Implement activate account page
Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -47,7 +47,6 @@ type (
|
||||
|
||||
CreateIdentityFromInvitationRequest struct {
|
||||
InvitationToken string
|
||||
Password string
|
||||
}
|
||||
|
||||
LoadOrCreateIdentityRequest struct {
|
||||
@@ -92,7 +91,6 @@ func (req CreateIdentityFromInvitationRequest) Validate() error {
|
||||
v := validator.New()
|
||||
|
||||
v.Check(req.InvitationToken, "invitationToken", validator.NotEmpty())
|
||||
v.Check(req.Password, "password", PasswordValidator())
|
||||
|
||||
return v.Error()
|
||||
}
|
||||
@@ -153,11 +151,6 @@ func (s *AuthService) ActivateAccount(
|
||||
now = time.Now()
|
||||
)
|
||||
|
||||
hashedPassword, err := s.hp.HashPassword([]byte(req.Password))
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("cannot hash password: %w", err)
|
||||
}
|
||||
|
||||
err = s.pg.WithTx(
|
||||
ctx,
|
||||
func(tx pg.Conn) error {
|
||||
@@ -197,7 +190,6 @@ func (s *AuthService) ActivateAccount(
|
||||
return fmt.Errorf("cannot load identity: %w", err)
|
||||
}
|
||||
|
||||
identity.HashedPassword = hashedPassword
|
||||
identity.EmailAddressVerified = true
|
||||
identity.UpdatedAt = now
|
||||
|
||||
|
||||
@@ -326,15 +326,15 @@ func (e ErrInvitationNotDeleted) Error() string {
|
||||
return fmt.Sprintf("cannot delete invitation %q in %q status", e.InvitationID, e.Status)
|
||||
}
|
||||
|
||||
type ErrPasswordRequired struct {
|
||||
type ErrPasswordAuthenticationRequired struct {
|
||||
Reason string
|
||||
}
|
||||
|
||||
func NewPasswordRequiredError(reason string) *ErrPasswordRequired {
|
||||
return &ErrPasswordRequired{Reason: reason}
|
||||
func NewPasswordAuthenticationRequiredError(reason string) *ErrPasswordAuthenticationRequired {
|
||||
return &ErrPasswordAuthenticationRequired{Reason: reason}
|
||||
}
|
||||
|
||||
func (e *ErrPasswordRequired) Error() string {
|
||||
func (e *ErrPasswordAuthenticationRequired) Error() string {
|
||||
return fmt.Sprintf("password authentication required: %s", e.Reason)
|
||||
}
|
||||
|
||||
|
||||
@@ -573,16 +573,23 @@ func (s SessionService) AssumeOrganizationSession(
|
||||
return fmt.Errorf("cannot load SAML configuration: %w", err)
|
||||
}
|
||||
|
||||
if err == nil && samlConfig.EnforcementPolicy == coredata.SAMLEnforcementPolicyRequired {
|
||||
if rootSession.AuthMethod != coredata.AuthMethodSAML {
|
||||
return NewSAMLAuthenticationRequiredError("policy_requirement")
|
||||
if err == nil {
|
||||
switch samlConfig.EnforcementPolicy {
|
||||
case coredata.SAMLEnforcementPolicyRequired:
|
||||
if rootSession.AuthMethod != coredata.AuthMethodSAML {
|
||||
return NewSAMLAuthenticationRequiredError("policy_requirement")
|
||||
}
|
||||
case coredata.SAMLEnforcementPolicyOptional:
|
||||
// SAML is optional: both PASSWORD and SAML root sessions are allowed.
|
||||
}
|
||||
} else {
|
||||
switch rootSession.AuthMethod {
|
||||
case coredata.AuthMethodPassword:
|
||||
case coredata.AuthMethodSAML:
|
||||
// No (or non-required) SAML configuration: require a password-authenticated or magic-link root session
|
||||
// (eg. when switching into a password-based org from a SAML login)
|
||||
return NewPasswordAuthenticationRequiredError("password_authentication_required")
|
||||
}
|
||||
} else if err == nil && samlConfig.EnforcementPolicy == coredata.SAMLEnforcementPolicyOptional {
|
||||
// SAML is optional: both PASSWORD and SAML root sessions are allowed.
|
||||
} else if rootSession.AuthMethod != coredata.AuthMethodPassword {
|
||||
// No (or non-required) SAML configuration: require a password-authenticated root session
|
||||
// (eg. when switching into a password-based org from a SAML login).
|
||||
return NewPasswordRequiredError("password_authentication_required")
|
||||
}
|
||||
|
||||
tenantID := scope.GetTenantID()
|
||||
|
||||
Reference in New Issue
Block a user