func SignInPost(ctx *context.Context) {
	ctx.Data["Title"] = ctx.Tr("sign_in")

	orderedOAuth2Names, oauth2Providers, err := models.GetActiveOAuth2Providers()
	if err != nil {
		ctx.ServerError("UserSignIn", err)
		return
	}
	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["EnableSSPI"] = models.IsSSPIEnabled()

	if ctx.HasError() {
		ctx.HTML(http.StatusOK, tplSignIn)
		return
	}

	form := web.GetForm(ctx).(*forms.SignInForm)
	u, err := models.UserSignIn(form.UserName, form.Password)
	if err != nil {
		if models.IsErrUserNotExist(err) {
			ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), tplSignIn, &form)
			log.Info("Failed authentication attempt for %s from %s: %v", form.UserName, ctx.RemoteAddr(), err)
		} else if models.IsErrEmailAlreadyUsed(err) {
			ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplSignIn, &form)
			log.Info("Failed authentication attempt for %s from %s: %v", form.UserName, ctx.RemoteAddr(), err)
		} else if models.IsErrUserProhibitLogin(err) {
			log.Info("Failed authentication attempt for %s from %s: %v", form.UserName, ctx.RemoteAddr(), err)
			ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
			ctx.HTML(http.StatusOK, "user/auth/prohibit_login")
		} else if models.IsErrUserInactive(err) {
			if setting.Service.RegisterEmailConfirm {
				ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
				ctx.HTML(http.StatusOK, TplActivate)
			} else {
				log.Info("Failed authentication attempt for %s from %s: %v", form.UserName, ctx.RemoteAddr(), err)
				ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
				ctx.HTML(http.StatusOK, "user/auth/prohibit_login")
			}
		} else {
			ctx.ServerError("UserSignIn", err)
		}
		return
	}
	// If this user is enrolled in 2FA, we can't sign the user in just yet.
	// Instead, redirect them to the 2FA authentication page.
	_, err = models.GetTwoFactorByUID(u.ID)
	if err != nil {
		if models.IsErrTwoFactorNotEnrolled(err) {
			handleSignIn(ctx, u, form.Remember)
		} else {
			ctx.ServerError("UserSignIn", err)
		}
		return
	}

	// User needs to use 2FA, save data and redirect to 2FA page.
	if err := ctx.Session.Set("twofaUid", u.ID); err != nil {
		ctx.ServerError("UserSignIn: Unable to set twofaUid in session", err)
		return
	}
	if err := ctx.Session.Set("twofaRemember", form.Remember); err != nil {
		ctx.ServerError("UserSignIn: Unable to set twofaRemember in session", err)
		return
	}
	if err := ctx.Session.Release(); err != nil {
		ctx.ServerError("UserSignIn: Unable to save session", err)
		return
	}

	regs, err := models.GetU2FRegistrationsByUID(u.ID)
	if err == nil && len(regs) > 0 {
		ctx.Redirect(setting.AppSubURL + "/user/u2f")
		return
	}

	ctx.Redirect(setting.AppSubURL + "/user/two_factor")
}
// SignInPost response for sign in request
SignInPost response for sign in request
// SignInPost response for sign in request
func SignInPost(ctx *context.Context) {
	ctx.Data["Title"] = ctx.Tr("sign_in")
	orderedOAuth2Names, oauth2Providers, err := models.GetActiveOAuth2Providers()
	if err != nil {
		ctx.ServerError("UserSignIn", err)
		return
	}
	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["EnableSSPI"] = models.IsSSPIEnabled()
	if ctx.HasError() {
		ctx.HTML(http.StatusOK, tplSignIn)
		return
	}
	form := web.GetForm(ctx).(*forms.SignInForm)
	u, err := models.UserSignIn(form.UserName, form.Password)
	if err != nil {
		if models.IsErrUserNotExist(err) {
			ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), tplSignIn, &form)
			log.Info("Failed authentication attempt for %s from %s: %v", form.UserName, ctx.RemoteAddr(), err)
		} else if models.IsErrEmailAlreadyUsed(err) {
			ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplSignIn, &form)
			log.Info("Failed authentication attempt for %s from %s: %v", form.UserName, ctx.RemoteAddr(), err)
		} else if models.IsErrUserProhibitLogin(err) {
			log.Info("Failed authentication attempt for %s from %s: %v", form.UserName, ctx.RemoteAddr(), err)
			ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
			ctx.HTML(http.StatusOK, "user/auth/prohibit_login")
		} else if models.IsErrUserInactive(err) {
			if setting.Service.RegisterEmailConfirm {
				ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
				ctx.HTML(http.StatusOK, TplActivate)
			} else {
				log.Info("Failed authentication attempt for %s from %s: %v", form.UserName, ctx.RemoteAddr(), err)
				ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
				ctx.HTML(http.StatusOK, "user/auth/prohibit_login")
			}
		} else {
			ctx.ServerError("UserSignIn", err)
		}
		return
	}
	_, err = models.GetTwoFactorByUID(u.ID)
	if err != nil {
		if models.IsErrTwoFactorNotEnrolled(err) {
			handleSignIn(ctx, u, form.Remember)
		} else {
			ctx.ServerError("UserSignIn", err)
		}
		return
	}
	if err := ctx.Session.Set("twofaUid", u.ID); err != nil {
		ctx.ServerError("UserSignIn: Unable to set twofaUid in session", err)
		return
	}
	if err := ctx.Session.Set("twofaRemember", form.Remember); err != nil {
		ctx.ServerError("UserSignIn: Unable to set twofaRemember in session", err)
		return
	}
	if err := ctx.Session.Release(); err != nil {
		ctx.ServerError("UserSignIn: Unable to save session", err)
		return
	}
	regs, err := models.GetU2FRegistrationsByUID(u.ID)
	if err == nil && len(regs) > 0 {
		ctx.Redirect(setting.AppSubURL + "/user/u2f")
		return
	}
	ctx.Redirect(setting.AppSubURL + "/user/two_factor")
}
func SignInPost ( ctx * context . Context ) { ctx . Data [ " " ] = ctx . Tr ( " " ) orderedOAuth2Names , oauth2Providers , err := models . GetActiveOAuth2Providers ( ) if err != nil { ctx . ServerError ( " " , err ) return } ctx . Data [ " " ] = orderedOAuth2Names ctx . Data [ " " ] = oauth2Providers ctx . Data [ " " ] = ctx . Tr ( " " ) ctx . Data [ " " ] = setting . AppSubURL + " " ctx . Data [ " " ] = true ctx . Data [ " " ] = true ctx . Data [ " " ] = models . IsSSPIEnabled ( ) if ctx . HasError ( ) { ctx . HTML ( http . StatusOK , tplSignIn ) return } form := web . GetForm ( ctx ) . ( * forms . SignInForm ) u , err := models . UserSignIn ( form . UserName , form . Password ) if err != nil { if models . IsErrUserNotExist ( err ) { ctx . RenderWithErr ( ctx . Tr ( " " ) , tplSignIn , & form ) log . Info ( " " , form . UserName , ctx . RemoteAddr ( ) , err ) } else if models . IsErrEmailAlreadyUsed ( err ) { ctx . RenderWithErr ( ctx . Tr ( " " ) , tplSignIn , & form ) log . Info ( " " , form . UserName , ctx . RemoteAddr ( ) , err ) } else if models . IsErrUserProhibitLogin ( err ) { log . Info ( " " , form . UserName , ctx . RemoteAddr ( ) , err ) ctx . Data [ " " ] = ctx . Tr ( " " ) ctx . HTML ( http . StatusOK , " " ) } else if models . IsErrUserInactive ( err ) { if setting . Service . RegisterEmailConfirm { ctx . Data [ " " ] = ctx . Tr ( " " ) ctx . HTML ( http . StatusOK , TplActivate ) } else { log . Info ( " " , form . UserName , ctx . RemoteAddr ( ) , err ) ctx . Data [ " " ] = ctx . Tr ( " " ) ctx . HTML ( http . StatusOK , " " ) } } else { ctx . ServerError ( " " , err ) } return } _ , err = models . GetTwoFactorByUID ( u . ID ) if err != nil { if models . IsErrTwoFactorNotEnrolled ( err ) { handleSignIn ( ctx , u , form . Remember ) } else { ctx . ServerError ( " " , err ) } return } if err := ctx . Session . Set ( " " , u . ID ) ; err != nil { ctx . ServerError ( " " , err ) return } if err := ctx . Session . Set ( " " , form . Remember ) ; err != nil { ctx . ServerError ( " " , err ) return } if err := ctx . Session . Release ( ) ; err != nil { ctx . ServerError ( " " , err ) return } regs , err := models . GetU2FRegistrationsByUID ( u . ID ) if err == nil && len ( regs ) > 0 { ctx . Redirect ( setting . AppSubURL + " " ) return } ctx . Redirect ( setting . AppSubURL + " " ) }
SignInPost response for sign in request
SignInPost response for sign in request
// If this user is enrolled in 2FA, we can't sign the user in just yet. // Instead, redirect them to the 2FA authentication page. // User needs to use 2FA, save data and redirect to 2FA page.