@@ -13,7 +13,9 @@ import (
13
13
user_model "code.gitea.io/gitea/models/user"
14
14
"code.gitea.io/gitea/modules/base"
15
15
"code.gitea.io/gitea/modules/context"
16
+ "code.gitea.io/gitea/modules/log"
16
17
"code.gitea.io/gitea/modules/setting"
18
+ "code.gitea.io/gitea/modules/util"
17
19
"code.gitea.io/gitea/modules/web"
18
20
auth_service "code.gitea.io/gitea/services/auth"
19
21
"code.gitea.io/gitea/services/auth/source/oauth2"
@@ -81,6 +83,32 @@ func LinkAccount(ctx *context.Context) {
81
83
ctx .HTML (http .StatusOK , tplLinkAccount )
82
84
}
83
85
86
+ func handleSignInError (ctx * context.Context , userName string , ptrForm any , tmpl base.TplName , invoker string , err error ) {
87
+ if errors .Is (err , util .ErrNotExist ) {
88
+ ctx .RenderWithErr (ctx .Tr ("form.username_password_incorrect" ), tmpl , ptrForm )
89
+ } else if errors .Is (err , util .ErrInvalidArgument ) {
90
+ ctx .Data ["user_exists" ] = true
91
+ ctx .RenderWithErr (ctx .Tr ("form.username_password_incorrect" ), tmpl , ptrForm )
92
+ } else if user_model .IsErrUserProhibitLogin (err ) {
93
+ ctx .Data ["user_exists" ] = true
94
+ log .Info ("Failed authentication attempt for %s from %s: %v" , userName , ctx .RemoteAddr (), err )
95
+ ctx .Data ["Title" ] = ctx .Tr ("auth.prohibit_login" )
96
+ ctx .HTML (http .StatusOK , "user/auth/prohibit_login" )
97
+ } else if user_model .IsErrUserInactive (err ) {
98
+ ctx .Data ["user_exists" ] = true
99
+ if setting .Service .RegisterEmailConfirm {
100
+ ctx .Data ["Title" ] = ctx .Tr ("auth.active_your_account" )
101
+ ctx .HTML (http .StatusOK , TplActivate )
102
+ } else {
103
+ log .Info ("Failed authentication attempt for %s from %s: %v" , userName , ctx .RemoteAddr (), err )
104
+ ctx .Data ["Title" ] = ctx .Tr ("auth.prohibit_login" )
105
+ ctx .HTML (http .StatusOK , "user/auth/prohibit_login" )
106
+ }
107
+ } else {
108
+ ctx .ServerError (invoker , err )
109
+ }
110
+ }
111
+
84
112
// LinkAccountPostSignIn handle the coupling of external account with another account using signIn
85
113
func LinkAccountPostSignIn (ctx * context.Context ) {
86
114
signInForm := web .GetForm (ctx ).(* forms.SignInForm )
@@ -116,12 +144,7 @@ func LinkAccountPostSignIn(ctx *context.Context) {
116
144
117
145
u , _ , err := auth_service .UserSignIn (signInForm .UserName , signInForm .Password )
118
146
if err != nil {
119
- if user_model .IsErrUserNotExist (err ) {
120
- ctx .Data ["user_exists" ] = true
121
- ctx .RenderWithErr (ctx .Tr ("form.username_password_incorrect" ), tplLinkAccount , & signInForm )
122
- } else {
123
- ctx .ServerError ("UserLinkAccount" , err )
124
- }
147
+ handleSignInError (ctx , signInForm .UserName , & signInForm , tplLinkAccount , "UserLinkAccount" , err )
125
148
return
126
149
}
127
150
0 commit comments