From a4dba70d0b53182f999eb786192f49cf13263639 Mon Sep 17 00:00:00 2001 From: smail Date: Fri, 11 Sep 2026 14:34:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=9C=AA=E7=BB=91?= =?UTF-8?q?=E5=AE=9A=E5=A4=96=E9=83=A8=E9=82=AE=E7=AE=B1=E7=9A=84=E6=96=B0?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=99=BB=E5=BD=95=E8=A2=AB=E4=BA=8C=E6=AC=A1?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E9=98=BB=E6=96=AD=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/controllers/login_verification.go | 4 ++++ .../login_verification_policy_test.go | 20 ++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/backend/controllers/login_verification.go b/backend/controllers/login_verification.go index cde9554..d376bcf 100644 --- a/backend/controllers/login_verification.go +++ b/backend/controllers/login_verification.go @@ -12,6 +12,7 @@ import ( "git.pcux.cn/xuans/Smail/dto/response" "git.pcux.cn/xuans/Smail/models" "git.pcux.cn/xuans/Smail/services/access" + "git.pcux.cn/xuans/Smail/services/externalemail" "git.pcux.cn/xuans/Smail/services/verification" "git.pcux.cn/xuans/Smail/session" "git.pcux.cn/xuans/Smail/utils/array" @@ -91,6 +92,9 @@ func beginLoginVerification(user *models.User, remoteIP string) (map[string]any, } binding, err := runtime.external.FindVerifiedPrimaryByUser(user.ID) if err != nil { + if errors.Is(err, externalemail.ErrBindingNotFound) { + return nil, nil + } return nil, errLoginVerificationUnavailable } email, err := runtime.external.Decrypt(*binding) diff --git a/backend/controllers/login_verification_policy_test.go b/backend/controllers/login_verification_policy_test.go index efd1c2c..ffbc5dd 100644 --- a/backend/controllers/login_verification_policy_test.go +++ b/backend/controllers/login_verification_policy_test.go @@ -1,6 +1,10 @@ package controllers -import "testing" +import ( + "testing" + + "git.pcux.cn/xuans/Smail/models" +) func TestLoginVerificationPolicyEnabled(t *testing.T) { tests := []struct { @@ -24,3 +28,17 @@ func TestLoginVerificationPolicyEnabled(t *testing.T) { }) } } + +func TestBeginLoginVerification_NoExternalEmail(t *testing.T) { + user := &models.User{ + ID: 99999, + Account: "test_no_email", + } + res, err := beginLoginVerification(user, "127.0.0.1") + if err != nil { + t.Fatalf("expected nil error for user without external email, got: %v", err) + } + if res != nil { + t.Fatalf("expected nil challenge result for user without external email, got: %v", res) + } +}