Пример #1
0
func signInHandler(ctx *app.Context) {
	modal := ctx.FormValue("modal") != ""
	d := data(ctx)
	if !modal && !d.allowDirectSignIn() && d.hasEnabledSocialSignin() {
		// Redirect to the only available social sign-in
		ctx.MustRedirectReverse(false, d.enabledSocialAccountTypes()[0].HandlerName)
		return
	}
	from := ctx.FormValue(app.SignInFromParameterName)
	signIn := SignIn{From: from}
	form := form.New(ctx, &signIn)
	if d.allowDirectSignIn() && form.Submitted() && form.IsValid() {
		ctx.MustSignIn(asGondolaUser(reflect.ValueOf(signIn.User)))
		ctx.RedirectBack()
		return
	}
	user, _ := newEmptyUser(ctx)
	data := map[string]interface{}{
		"SocialAccountTypes": d.enabledSocialAccountTypes(),
		"From":               from,
		"SignInForm":         form,
		"SignUpForm":         SignUpForm(ctx, user),
		"AllowDirectSignIn":  d.allowDirectSignIn(),
		"AllowRegistration":  d.allowRegistration(),
	}
	tmpl := SignInTemplateName
	if modal && SignInModalTemplateName != "" {
		tmpl = SignInModalTemplateName
	}
	ctx.MustExecute(tmpl, data)
}
Пример #2
0
func jsSignUpHandler(ctx *app.Context) {
	d := data(ctx)
	if !d.allowRegistration() {
		ctx.NotFound("")
		return
	}
	user, _ := newEmptyUser(ctx)
	form := SignUpForm(ctx, user)
	if form.Submitted() && form.IsValid() {
		saveNewUser(ctx, user)
		writeJSONEncoded(ctx, user)
		return
	}
	FormErrors(ctx, form)
}
Пример #3
0
func jsSignInHandler(ctx *app.Context) {
	d := data(ctx)
	if !d.allowDirectSignIn() {
		ctx.NotFound("")
		return
	}
	signIn := SignIn{}
	form := form.New(ctx, &signIn)
	if form.Submitted() && form.IsValid() {
		user := reflect.ValueOf(signIn.User)
		ctx.MustSignIn(asGondolaUser(user))
		writeJSONEncoded(ctx, user)
		return
	}
	FormErrors(ctx, form)
}
Пример #4
0
func signUpHandler(ctx *app.Context) {
	d := data(ctx)
	if !d.allowDirectSignIn() {
		ctx.NotFound("")
		return
	}
	from := ctx.FormValue(app.SignInFromParameterName)
	user, _ := newEmptyUser(ctx)
	form := SignUpForm(ctx, user)
	if form.Submitted() && form.IsValid() {
		saveNewUser(ctx, user)
		ctx.RedirectBack()
		return
	}
	data := map[string]interface{}{
		"From":       from,
		"SignUpForm": form,
	}
	ctx.MustExecute(SignUpTemplateName, data)
}