Add captcha support to OpenID based signup

This commit is contained in:
Sandro Santilli 2017-03-17 17:40:39 +01:00 committed by Kim "BKC" Carlbäcker
parent f00a4c8078
commit 97ee88975a
2 changed files with 15 additions and 4 deletions

View file

@ -15,6 +15,8 @@ import (
"code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"github.com/go-macaron/captcha"
) )
const ( const (
@ -310,6 +312,7 @@ func RegisterOpenID(ctx *context.Context) {
ctx.Data["PageIsSignIn"] = true ctx.Data["PageIsSignIn"] = true
ctx.Data["PageIsOpenIDRegister"] = true ctx.Data["PageIsOpenIDRegister"] = true
ctx.Data["EnableOpenIDSignUp"] = setting.EnableOpenIDSignUp ctx.Data["EnableOpenIDSignUp"] = setting.EnableOpenIDSignUp
ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
ctx.Data["OpenID"] = oid ctx.Data["OpenID"] = oid
userName, _ := ctx.Session.Get("openid_determined_username").(string) userName, _ := ctx.Session.Get("openid_determined_username").(string)
if userName != "" { if userName != "" {
@ -323,7 +326,7 @@ func RegisterOpenID(ctx *context.Context) {
} }
// RegisterOpenIDPost handles submission of a form to create a new user authenticated via an OpenID URI // RegisterOpenIDPost handles submission of a form to create a new user authenticated via an OpenID URI
func RegisterOpenIDPost(ctx *context.Context, form auth.SignUpOpenIDForm) { func RegisterOpenIDPost(ctx *context.Context, cpt *captcha.Captcha, form auth.SignUpOpenIDForm) {
if ! setting.EnableOpenIDSignUp { if ! setting.EnableOpenIDSignUp {
ctx.Error(403) ctx.Error(403)
return return
@ -338,16 +341,14 @@ func RegisterOpenIDPost(ctx *context.Context, form auth.SignUpOpenIDForm) {
ctx.Data["PageIsSignIn"] = true ctx.Data["PageIsSignIn"] = true
ctx.Data["PageIsOpenIDRegister"] = true ctx.Data["PageIsOpenIDRegister"] = true
ctx.Data["EnableOpenIDSignUp"] = setting.EnableOpenIDSignUp ctx.Data["EnableOpenIDSignUp"] = setting.EnableOpenIDSignUp
ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha
ctx.Data["OpenID"] = oid ctx.Data["OpenID"] = oid
/*
// TODO: handle captcha ?
if setting.Service.EnableCaptcha && !cpt.VerifyReq(ctx.Req) { if setting.Service.EnableCaptcha && !cpt.VerifyReq(ctx.Req) {
ctx.Data["Err_Captcha"] = true ctx.Data["Err_Captcha"] = true
ctx.RenderWithErr(ctx.Tr("form.captcha_incorrect"), tplSignUpOID, &form) ctx.RenderWithErr(ctx.Tr("form.captcha_incorrect"), tplSignUpOID, &form)
return return
} }
*/
len := setting.MinPasswordLength len := setting.MinPasswordLength
if len < 256 { len = 256 } if len < 256 { len = 256 }

View file

@ -20,6 +20,16 @@
<label for="email">{{.i18n.Tr "email"}}</label> <label for="email">{{.i18n.Tr "email"}}</label>
<input id="email" name="email" type="email" value="{{.email}}" required> <input id="email" name="email" type="email" value="{{.email}}" required>
</div> </div>
{{if .EnableCaptcha}}
<div class="inline field">
<label></label>
{{.Captcha.CreateHtml}}
</div>
<div class="required inline field {{if .Err_Captcha}}error{{end}}">
<label for="captcha">{{.i18n.Tr "captcha"}}</label>
<input id="captcha" name="captcha" value="{{.captcha}}" autocomplete="off">
</div>
{{end}}
<div class="inline field"> <div class="inline field">
<label for="openid">OpenID URI</label> <label for="openid">OpenID URI</label>
<input id="openid" value="{{ .OpenID }}" readonly> <input id="openid" value="{{ .OpenID }}" readonly>