Compare commits

...

8 Commits

Author SHA1 Message Date
Darren Hoo ecb885b558
Merge f6586943cb into 852547d0dc 2024-04-26 15:24:38 +02:00
techknowlogick f6586943cb
Merge branch 'main' into main 2024-04-09 21:40:13 -04:00
hyg 7eaf283b0c remove extra line 2023-09-19 10:13:14 +08:00
hyg 4d9f4ed5cd reword the comment 2023-09-16 10:32:57 +08:00
hyg 55afd39390 reword the comment 2023-09-16 10:31:49 +08:00
hyg 1d34d436c2 process with all textproto.Error and add comment 2023-09-16 10:19:14 +08:00
hyg 280861f31e add support for aliyun mail when authentication failed 2023-09-16 09:49:15 +08:00
hyg 814ca03be8 Show error instead of 500 HTTP error if authenticate fails via external SMTP
Close #27043
2023-09-16 09:09:06 +08:00
1 changed files with 7 additions and 10 deletions

View File

@ -42,16 +42,13 @@ func (source *Source) Authenticate(ctx context.Context, user *user_model.User, u
}
if err := Authenticate(auth, source); err != nil {
// Check standard error format first,
// then fallback to worse case.
tperr, ok := err.(*textproto.Error)
if (ok && tperr.Code == 535) ||
strings.Contains(err.Error(), "Username and Password not accepted") {
return nil, user_model.ErrUserNotExist{Name: userName}
}
if (ok && tperr.Code == 534) ||
strings.Contains(err.Error(), "Application-specific password required") {
return nil, user_model.ErrUserNotExist{Name: userName}
// when authentication via smtp fails, wraps ErrInvalidArgument
// with the original textproto.Error as the cause,
// so it will show username_password_incorrect to the user
// while log the original error so that admin can check.
// see: routers/web/auth/auth.go SiginPost
if tperr, ok := err.(*textproto.Error); ok {
return nil, errors.Join(util.ErrInvalidArgument, tperr)
}
return nil, err
}