diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 980eb51d5..8f5fb4d5a 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -373,7 +373,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Group("/user", func() { m.Get("/login", user.SignIn) m.Get("/login/cloud_brain", user.SignInCloudBrain) - + m.Post("/login/cloud_brain", bindIgnErr(auth.SignInForm{}), user.SignInCloudBrainPost) m.Post("/login", bindIgnErr(auth.SignInForm{}), user.SignInPost) m.Get("/login/phone", user.SignInPhone) diff --git a/routers/user/auth.go b/routers/user/auth.go index 43a6580fc..7cd6472ff 100755 --- a/routers/user/auth.go +++ b/routers/user/auth.go @@ -180,7 +180,7 @@ func SignInCloudBrain(ctx *context.Context) { return } - ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login" + ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login/cloud_brain" ctx.Data["PageIsSignIn"] = true ctx.Data["PageIsCloudBrainLogin"] = true ctx.Data["EnableCloudBrain"] = true @@ -267,8 +267,7 @@ func SignInPostAPI(ctx *context.Context) { handleSignInFullNotRedirect(ctx, u, true, false) } -// SignInPost response for sign in request -func SignInPost(ctx *context.Context, form auth.SignInForm) { +func SignInPostCommon(ctx *context.Context, form auth.SignInForm) { ctx.Data["Title"] = ctx.Tr("sign_in") orderedOAuth2Names, oauth2Providers, err := models.GetActiveOAuth2Providers() @@ -279,9 +278,9 @@ func SignInPost(ctx *context.Context, form auth.SignInForm) { ctx.Data["OrderedOAuth2Names"] = orderedOAuth2Names ctx.Data["OAuth2Providers"] = oauth2Providers ctx.Data["Title"] = ctx.Tr("sign_in") - ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login" + ctx.Data["PageIsSignIn"] = true - ctx.Data["PageIsLogin"] = true + ctx.Data["IsCourse"] = ctx.QueryBool("course") ctx.Data["EnableSSPI"] = models.IsSSPIEnabled() ctx.Data["EnableCloudBrain"] = true @@ -313,7 +312,9 @@ func SignInPost(ctx *context.Context, form auth.SignInForm) { ctx.HTML(200, "user/auth/prohibit_login") } } else { - ctx.ServerError("UserSignIn", err) + log.Warn("UserSignIn", err) + ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), tplSignIn, &form) + log.Info("Failed authentication attempt for %s from %s", form.UserName, ctx.RemoteAddr()) } return } @@ -351,6 +352,20 @@ func SignInPost(ctx *context.Context, form auth.SignInForm) { ctx.Redirect(setting.AppSubURL + "/user/two_factor") } + +func SignInCloudBrainPost(ctx *context.Context, form auth.SignInForm) { + ctx.Data["PageIsCloudBrainLogin"] = true + ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login/cloud_brain" + SignInPostCommon(ctx,form) +} + +// SignInPost response for sign in request +func SignInPost(ctx *context.Context, form auth.SignInForm) { + ctx.Data["PageIsLogin"] = true + ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login" + SignInPostCommon(ctx,form) +} + // TwoFactor shows the user a two-factor authentication page. func TwoFactor(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("twofa") @@ -1317,7 +1332,7 @@ func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterFo return } } - + if !form.Agree { ctx.RenderWithErr(ctx.Tr("sign_up_agree_tips"), tplSignUp, &form) return