@@ -41,21 +41,15 @@ func (source *Source) Authenticate(ctx context.Context, user *user_model.User, u
41
41
}
42
42
43
43
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 )
58
51
}
52
+
59
53
return nil , err
60
54
}
61
55
0 commit comments