Skip to content

Commit

Permalink
updated LastVerificationSentAt and LastResetSentAt fill sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
ganigeorgiev committed Aug 17, 2023
1 parent c8ef3c4 commit 53b20ec
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"@hourly": "0 * * * *"
```

- Fill the `LastVerificationSentAt` and `LastResetSentAt` fields only after a successfull email send.


## v0.17.5

Expand Down
6 changes: 3 additions & 3 deletions forms/admin_password_reset_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ func (form *AdminPasswordResetRequest) Submit(interceptors ...InterceptorFunc[*m
return errors.New("You have already requested a password reset.")
}

// update last sent timestamp
admin.LastResetSentAt = types.NowDateTime()

return runInterceptors(admin, func(m *models.Admin) error {
if err := mails.SendAdminPasswordReset(form.app, m); err != nil {
return err
}

// update last sent timestamp
m.LastResetSentAt = types.NowDateTime()

return form.dao.SaveAdmin(m)
}, interceptors...)
}
4 changes: 2 additions & 2 deletions forms/admin_password_reset_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func TestAdminPasswordResetRequestInterceptors(t *testing.T) {
t.Fatalf("Expected interceptor2 to be called")
}

if interceptorLastResetSentAt.String() == admin.LastResetSentAt.String() {
t.Fatalf("Expected the form model to be filled before calling the interceptors")
if interceptorLastResetSentAt.String() != admin.LastResetSentAt.String() {
t.Fatalf("Expected the form model to NOT be filled before calling the interceptors")
}
}
6 changes: 3 additions & 3 deletions forms/record_password_reset_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ func (form *RecordPasswordResetRequest) Submit(interceptors ...InterceptorFunc[*
return errors.New("You've already requested a password reset.")
}

// update last sent timestamp
authRecord.Set(schema.FieldNameLastResetSentAt, types.NowDateTime())

return runInterceptors(authRecord, func(m *models.Record) error {
if err := mails.SendRecordPasswordReset(form.app, m); err != nil {
return err
}

// update last sent timestamp
m.Set(schema.FieldNameLastResetSentAt, types.NowDateTime())

return form.dao.SaveRecord(m)
}, interceptors...)
}
4 changes: 2 additions & 2 deletions forms/record_password_reset_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func TestRecordPasswordResetRequestInterceptors(t *testing.T) {
t.Fatalf("Expected interceptor2 to be called")
}

if interceptorLastResetSentAt.String() == authRecord.LastResetSentAt().String() {
t.Fatalf("Expected the form model to be filled before calling the interceptors")
if interceptorLastResetSentAt.String() != authRecord.LastResetSentAt().String() {
t.Fatalf("Expected the form model to NOT be filled before calling the interceptors")
}
}
6 changes: 3 additions & 3 deletions forms/record_verification_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ func (form *RecordVerificationRequest) Submit(interceptors ...InterceptorFunc[*m
if (now.Sub(lastVerificationSentAt)).Seconds() < form.resendThreshold {
return errors.New("A verification email was already sent.")
}

// update last sent timestamp
record.SetLastVerificationSentAt(types.NowDateTime())
}

return runInterceptors(record, func(m *models.Record) error {
Expand All @@ -96,6 +93,9 @@ func (form *RecordVerificationRequest) Submit(interceptors ...InterceptorFunc[*m
return err
}

// update last sent timestamp
m.SetLastVerificationSentAt(types.NowDateTime())

return form.dao.SaveRecord(m)
}, interceptors...)
}
4 changes: 2 additions & 2 deletions forms/record_verification_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func TestRecordVerificationRequestInterceptors(t *testing.T) {
t.Fatalf("Expected interceptor2 to be called")
}

if interceptorLastVerificationSentAt.String() == authRecord.LastVerificationSentAt().String() {
t.Fatalf("Expected the form model to be filled before calling the interceptors")
if interceptorLastVerificationSentAt.String() != authRecord.LastVerificationSentAt().String() {
t.Fatalf("Expected the form model to NOT be filled before calling the interceptors")
}
}

0 comments on commit 53b20ec

Please sign in to comment.