@@ -13,7 +13,9 @@ import (
1313 user_model "code.gitea.io/gitea/models/user"
1414 "code.gitea.io/gitea/modules/base"
1515 "code.gitea.io/gitea/modules/context"
16+ "code.gitea.io/gitea/modules/log"
1617 "code.gitea.io/gitea/modules/setting"
18+ "code.gitea.io/gitea/modules/util"
1719 "code.gitea.io/gitea/modules/web"
1820 auth_service "code.gitea.io/gitea/services/auth"
1921 "code.gitea.io/gitea/services/auth/source/oauth2"
@@ -81,6 +83,32 @@ func LinkAccount(ctx *context.Context) {
8183 ctx .HTML (http .StatusOK , tplLinkAccount )
8284}
8385
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+
84112// LinkAccountPostSignIn handle the coupling of external account with another account using signIn
85113func LinkAccountPostSignIn (ctx * context.Context ) {
86114 signInForm := web .GetForm (ctx ).(* forms.SignInForm )
@@ -116,12 +144,7 @@ func LinkAccountPostSignIn(ctx *context.Context) {
116144
117145 u , _ , err := auth_service .UserSignIn (signInForm .UserName , signInForm .Password )
118146 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 )
125148 return
126149 }
127150
0 commit comments