本文整理汇总了Golang中gnd/la/app.Context.FormValue方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.FormValue方法的具体用法?Golang Context.FormValue怎么用?Golang Context.FormValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gnd/la/app.Context
的用法示例。
在下文中一共展示了Context.FormValue方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: signInHandler
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: redirectToFrom
func redirectToFrom(ctx *app.Context) {
from := ctx.FormValue(app.SignInFromParameterName)
if from == "" {
from = "/"
}
ctx.Redirect(from, false)
}
示例3: windowCallbackHandler
func windowCallbackHandler(ctx *app.Context, user reflect.Value, callback string) {
inWindow := ctx.FormValue("window") != ""
if user.IsValid() {
ctx.MustSignIn(asGondolaUser(user))
}
if inWindow {
var payload []byte
if user.IsValid() {
var err error
payload, err = JSONEncode(ctx, user.Interface())
if err != nil {
panic(err)
}
}
ctx.MustExecute("js-callback.html", map[string]interface{}{
"Callback": callback,
"Payload": payload,
})
} else {
if user.IsValid() {
redirectToFrom(ctx)
} else {
ctx.MustRedirectReverse(false, app.SignInHandlerName)
}
}
}
示例4: responseIsValid
func (r *reCaptcha) responseIsValid(ctx *app.Context) (bool, string) {
challenge := ctx.FormValue("recaptcha_challenge_field")
response := ctx.FormValue("recaptcha_response_field")
values := url.Values{
"privatekey": {r.privateKey},
"remoteip": {ctx.RemoteAddress()},
"challenge": {challenge},
"response": {response},
}
resp, err := http.PostForm("http://www.google.com/recaptcha/api/verify", values)
if err == nil {
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
if err == nil {
lines := strings.Split(string(b), "\n")
if len(lines) > 0 {
if lines[0] == "true" {
return true, ""
}
if len(lines) > 1 {
return false, lines[1]
}
}
}
}
return false, ""
}
示例5: jsSignInFacebookHandler
func jsSignInFacebookHandler(ctx *app.Context) {
req := ctx.FormValue("req")
fbApp := data(ctx).opts.FacebookApp.Clone(ctx)
resp, err := fbApp.ParseSignedRequest(req)
if err != nil {
panic(err)
}
// Let it crash if the data does not have the
// specified format, this will make it easier
// to find it if it happens.
code := resp["code"].(string)
token, err := fbApp.Exchange("", code)
user, err := userFromFacebookToken(ctx, token)
if err != nil {
panic(err)
}
ctx.MustSignIn(asGondolaUser(user))
writeJSONEncoded(ctx, user)
}
示例6: ResetHandler
func ResetHandler(ctx *app.Context) {
d := data(ctx)
if !d.allowDirectSignIn() {
ctx.NotFound("")
return
}
payload := ctx.FormValue("p")
var valid bool
var expired bool
var f *form.Form
var user reflect.Value
var err error
var done bool
if payload != "" {
user, err = decodeResetPayload(ctx, payload)
if err == nil && user.IsValid() {
valid = true
} else {
if err == errResetExpired {
expired = true
}
}
}
if valid {
passwordForm := &PasswordForm{User: user}
f = form.New(ctx, passwordForm)
if f.Submitted() && f.IsValid() {
ctx.Orm().MustSave(user.Interface())
ctx.MustSignIn(asGondolaUser(user))
done = true
}
}
data := map[string]interface{}{
"Valid": valid,
"Expired": expired,
"Done": done,
"User": user,
"PasswordForm": f,
"Payload": payload,
}
ctx.MustExecute(ResetTemplateName, data)
}
示例7: signUpHandler
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)
}