Skip to content

Commit

Permalink
Merge pull request #9 from nayla-finance/blocked-msg
Browse files Browse the repository at this point in the history
Blocked msg for user and otp should not sent to bloked user
  • Loading branch information
aalkhodiry authored Nov 14, 2024
2 parents 9eeb640 + ecda954 commit 94d72a9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
12 changes: 11 additions & 1 deletion schema/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,23 @@ func NewInvalidCredentialsError() error {
func NewIdentityInactiveError() error {
return errors.WithStack(&ValidationError{
ValidationError: &jsonschema.ValidationError{
Message: `this account is blocked please contact system administrator to regain access`,
Message: `Your account has been locked due to multiple failed login attempts. Please reset your password to unlock your account.`,
InstancePtr: "#/",
},
Messages: new(text.Messages).Add(text.NewErrorValidationIdentityInactive()),
})
}

func NewErrorValidationRecoveryNoStrategyFoundForBlockedAccount() error {
return errors.WithStack(&ValidationError{
ValidationError: &jsonschema.ValidationError{
Message: `this account is blocked please contact system administrator to regain access`,
InstancePtr: "#/",
},
Messages: new(text.Messages).Add(text.NewErrorValidationRecoveryNoStrategyFoundForBlockedAccount()),
})
}

func NewAccountNotFoundError() error {
return errors.WithStack(&ValidationError{
ValidationError: &jsonschema.ValidationError{
Expand Down
8 changes: 6 additions & 2 deletions selfservice/strategy/code/code_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/ory/herodot"
"github.com/ory/kratos/courier/template/email"
"github.com/ory/kratos/courier/template/sms"
"github.com/ory/kratos/schema"

"github.com/ory/x/sqlcon"
"github.com/ory/x/stringsx"
Expand Down Expand Up @@ -205,7 +206,7 @@ func (s *Sender) SendRecoveryCode(ctx context.Context, f *recovery.Flow, via ide

var address *identity.RecoveryAddress
var err error

if via == identity.VerifiableAddressTypeEmail {
address, err = s.deps.IdentityPool().FindRecoveryAddressByValue(ctx, identity.RecoveryAddressTypeEmail, to)
} else {
Expand Down Expand Up @@ -245,7 +246,10 @@ func (s *Sender) SendRecoveryCode(ctx context.Context, f *recovery.Flow, via ide
if err != nil {
return err
}


if i.IsBlocked() {
return errors.WithStack(schema.NewErrorValidationRecoveryNoStrategyFoundForBlockedAccount())
}
rawCode := GenerateCode()

var code *RecoveryCode
Expand Down
5 changes: 4 additions & 1 deletion selfservice/strategy/password/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ func (s *Strategy) Login(w http.ResponseWriter, r *http.Request, f *login.Flow,
return nil, s.handleLoginError(r, f, p, errors.WithStack(schema.NewInvalidCredentialsError()))
}

if !i.IsActive() {
if i.IsInactive() {
return nil, s.handleLoginError(r, f, p, errors.WithStack(schema.NewIdentityInactiveError()))
}
if i.IsBlocked() {
return nil, s.handleLoginError(r, f, p, errors.WithStack(schema.NewErrorValidationRecoveryNoStrategyFoundForBlockedAccount()))
}

var o identity.CredentialsPassword
d := json.NewDecoder(bytes.NewBuffer(c.Config))
Expand Down

0 comments on commit 94d72a9

Please sign in to comment.