fix: keep forwarding verification links idempotent
This commit is contained in:
@@ -1748,6 +1748,9 @@ func TestInboundForwardingSettingsAndDelivery(t *testing.T) {
|
||||
if code := admin.do("GET", "/api/verify-email?token="+url.QueryEscape(token), nil, nil); code != http.StatusOK {
|
||||
t.Fatalf("verify email code=%d", code)
|
||||
}
|
||||
if code := admin.do("GET", "/api/verify-email?token="+url.QueryEscape(token), nil, nil); code != http.StatusOK {
|
||||
t.Fatalf("reopen verified email link code=%d", code)
|
||||
}
|
||||
if code := admin.do("GET", "/api/me/forwarding", nil, &settings); code != http.StatusOK {
|
||||
t.Fatalf("reload forwarding settings code=%d", code)
|
||||
}
|
||||
@@ -1782,6 +1785,9 @@ func TestInboundForwardingSettingsAndDelivery(t *testing.T) {
|
||||
if code := admin.do("GET", "/api/verify-email?token="+url.QueryEscape(token), nil, nil); code != http.StatusOK {
|
||||
t.Fatalf("verify account target code=%d", code)
|
||||
}
|
||||
if code := admin.do("GET", "/api/verify-email?token="+url.QueryEscape(token), nil, nil); code != http.StatusOK {
|
||||
t.Fatalf("reopen account verification link code=%d", code)
|
||||
}
|
||||
if code := admin.do("POST", "/api/me/forwarding/account", map[string]string{"targetEmail": "account-forward@example.test"}, &settings); code != http.StatusOK || settings.AccountTargetEmail != "account-forward@example.test" {
|
||||
t.Fatalf("save account forwarding code=%d settings=%+v", code, settings)
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ func (a *App) handleVerifyForwardingEmail(w http.ResponseWriter, r *http.Request
|
||||
}
|
||||
now := a.now().UTC().Format(time.RFC3339Nano)
|
||||
_, err = a.db.ExecContext(r.Context(), `UPDATE forwarding_verified_emails
|
||||
SET verified=1,verified_at=?,verification_token_hash='',delivery_status='verified',delivery_error='',updated_at=?
|
||||
SET verified=1,verified_at=?,delivery_status='verified',delivery_error='',updated_at=?
|
||||
WHERE id=?`, now, now, id)
|
||||
if err != nil {
|
||||
a.renderForwardingVerificationPage(w, http.StatusInternalServerError, false, email, "验证失败,请稍后重试")
|
||||
|
||||
Reference in New Issue
Block a user