Skip to content

Commit 1d34d43

Browse files
committed
process with all textproto.Error and add comment
1 parent 280861f commit 1d34d43

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

services/auth/source/smtp/source_authenticate.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,15 @@ func (source *Source) Authenticate(ctx context.Context, user *user_model.User, u
4141
}
4242

4343
if err := Authenticate(auth, source); err != nil {
44-
// Check standard error format first,
45-
// then fallback to worse case.
46-
tperr, ok := err.(*textproto.Error)
47-
if (ok && tperr.Code == 535) ||
48-
strings.Contains(err.Error(), "Username and Password not accepted") {
49-
return nil, user_model.ErrUserNotExist{Name: userName}
50-
}
51-
if (ok && tperr.Code == 534) ||
52-
strings.Contains(err.Error(), "Application-specific password required") {
53-
return nil, user_model.ErrUserNotExist{Name: userName}
54-
}
55-
if (ok && tperr.Code == 526) ||
56-
strings.Contains(err.Error(), "Authentication failure") {
57-
return nil, user_model.ErrUserNotExist{Name: userName}
44+
// when authentication via smtp fails, wrap the error as ErrInvalidArgument
45+
// with the original textproto.Erro as the cause
46+
// so it will show username or password to the user
47+
// while log the original error so that admin can check the actual reason
48+
// see: routers/web/auth/auth.go SiginPost
49+
if tperr, ok := err.(*textproto.Error); ok {
50+
return nil, errors.Join(util.ErrInvalidArgument, tperr)
5851
}
52+
5953
return nil, err
6054
}
6155

0 commit comments

Comments
 (0)