mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-02-03 18:02:17 +02:00
updated LastVerificationSentAt and LastResetSentAt fill sequence
This commit is contained in:
parent
c8ef3c4050
commit
53b20ec104
@ -13,6 +13,8 @@
|
||||
"@hourly": "0 * * * *"
|
||||
```
|
||||
|
||||
- Fill the `LastVerificationSentAt` and `LastResetSentAt` fields only after a successfull email send.
|
||||
|
||||
|
||||
## v0.17.5
|
||||
|
||||
|
@ -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...)
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
@ -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...)
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
@ -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...)
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user