diff --git a/backend/controllers/login_verification.go b/backend/controllers/login_verification.go index cde9554d..d376bcfe 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 efd1c2c8..ffbc5dd1 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) + } +}