updated LastVerificationSentAt and LastResetSentAt fill sequence
This commit is contained in:
parent
c8ef3c4050
commit
53b20ec104
|
@ -13,6 +13,8 @@
|
||||||
"@hourly": "0 * * * *"
|
"@hourly": "0 * * * *"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- Fill the `LastVerificationSentAt` and `LastResetSentAt` fields only after a successfull email send.
|
||||||
|
|
||||||
|
|
||||||
## v0.17.5
|
## v0.17.5
|
||||||
|
|
||||||
|
|
|
@ -75,14 +75,14 @@ func (form *AdminPasswordResetRequest) Submit(interceptors ...InterceptorFunc[*m
|
||||||
return errors.New("You have already requested a password reset.")
|
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 {
|
return runInterceptors(admin, func(m *models.Admin) error {
|
||||||
if err := mails.SendAdminPasswordReset(form.app, m); err != nil {
|
if err := mails.SendAdminPasswordReset(form.app, m); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update last sent timestamp
|
||||||
|
m.LastResetSentAt = types.NowDateTime()
|
||||||
|
|
||||||
return form.dao.SaveAdmin(m)
|
return form.dao.SaveAdmin(m)
|
||||||
}, interceptors...)
|
}, interceptors...)
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,7 +117,7 @@ func TestAdminPasswordResetRequestInterceptors(t *testing.T) {
|
||||||
t.Fatalf("Expected interceptor2 to be called")
|
t.Fatalf("Expected interceptor2 to be called")
|
||||||
}
|
}
|
||||||
|
|
||||||
if interceptorLastResetSentAt.String() == admin.LastResetSentAt.String() {
|
if interceptorLastResetSentAt.String() != admin.LastResetSentAt.String() {
|
||||||
t.Fatalf("Expected the form model to be filled before calling the interceptors")
|
t.Fatalf("Expected the form model to NOT be filled before calling the interceptors")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,14 +78,14 @@ func (form *RecordPasswordResetRequest) Submit(interceptors ...InterceptorFunc[*
|
||||||
return errors.New("You've already requested a password reset.")
|
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 {
|
return runInterceptors(authRecord, func(m *models.Record) error {
|
||||||
if err := mails.SendRecordPasswordReset(form.app, m); err != nil {
|
if err := mails.SendRecordPasswordReset(form.app, m); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update last sent timestamp
|
||||||
|
m.Set(schema.FieldNameLastResetSentAt, types.NowDateTime())
|
||||||
|
|
||||||
return form.dao.SaveRecord(m)
|
return form.dao.SaveRecord(m)
|
||||||
}, interceptors...)
|
}, interceptors...)
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,7 +164,7 @@ func TestRecordPasswordResetRequestInterceptors(t *testing.T) {
|
||||||
t.Fatalf("Expected interceptor2 to be called")
|
t.Fatalf("Expected interceptor2 to be called")
|
||||||
}
|
}
|
||||||
|
|
||||||
if interceptorLastResetSentAt.String() == authRecord.LastResetSentAt().String() {
|
if interceptorLastResetSentAt.String() != authRecord.LastResetSentAt().String() {
|
||||||
t.Fatalf("Expected the form model to be filled before calling the interceptors")
|
t.Fatalf("Expected the form model to NOT be filled before calling the interceptors")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,9 +82,6 @@ func (form *RecordVerificationRequest) Submit(interceptors ...InterceptorFunc[*m
|
||||||
if (now.Sub(lastVerificationSentAt)).Seconds() < form.resendThreshold {
|
if (now.Sub(lastVerificationSentAt)).Seconds() < form.resendThreshold {
|
||||||
return errors.New("A verification email was already sent.")
|
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 {
|
return runInterceptors(record, func(m *models.Record) error {
|
||||||
|
@ -96,6 +93,9 @@ func (form *RecordVerificationRequest) Submit(interceptors ...InterceptorFunc[*m
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update last sent timestamp
|
||||||
|
m.SetLastVerificationSentAt(types.NowDateTime())
|
||||||
|
|
||||||
return form.dao.SaveRecord(m)
|
return form.dao.SaveRecord(m)
|
||||||
}, interceptors...)
|
}, interceptors...)
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,7 +182,7 @@ func TestRecordVerificationRequestInterceptors(t *testing.T) {
|
||||||
t.Fatalf("Expected interceptor2 to be called")
|
t.Fatalf("Expected interceptor2 to be called")
|
||||||
}
|
}
|
||||||
|
|
||||||
if interceptorLastVerificationSentAt.String() == authRecord.LastVerificationSentAt().String() {
|
if interceptorLastVerificationSentAt.String() != authRecord.LastVerificationSentAt().String() {
|
||||||
t.Fatalf("Expected the form model to be filled before calling the interceptors")
|
t.Fatalf("Expected the form model to NOT be filled before calling the interceptors")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue