func LinkAccountPostRegister(ctx *context.Context) {
	form := web.GetForm(ctx).(*forms.RegisterForm)
	// TODO Make insecure passwords optional for local accounts also,
	//      once email-based Second-Factor Auth is available
	ctx.Data["DisablePassword"] = !setting.Service.RequireExternalRegistrationPassword || setting.Service.AllowOnlyExternalRegistration
	ctx.Data["Title"] = ctx.Tr("link_account")
	ctx.Data["LinkAccountMode"] = true
	ctx.Data["LinkAccountModeRegister"] = true
	ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha && setting.Service.RequireExternalRegistrationCaptcha
	ctx.Data["RecaptchaURL"] = setting.Service.RecaptchaURL
	ctx.Data["Captcha"] = context.GetImageCaptcha()
	ctx.Data["CaptchaType"] = setting.Service.CaptchaType
	ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
	ctx.Data["HcaptchaSitekey"] = setting.Service.HcaptchaSitekey
	ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration
	ctx.Data["ShowRegistrationButton"] = false

	// use this to set the right link into the signIn and signUp templates in the link_account template
	ctx.Data["SignInLink"] = setting.AppSubURL + "/user/link_account_signin"
	ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/link_account_signup"

	gothUserInterface := ctx.Session.Get("linkAccountGothUser")
	if gothUserInterface == nil {
		ctx.ServerError("UserSignUp", errors.New("not in LinkAccount session"))
		return
	}
	gothUser, ok := gothUserInterface.(goth.User)
	if !ok {
		ctx.ServerError("UserSignUp", fmt.Errorf("session linkAccountGothUser type is %t but not goth.User", gothUserInterface))
		return
	}

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

	if setting.Service.DisableRegistration || setting.Service.AllowOnlyInternalRegistration {
		ctx.Error(http.StatusForbidden)
		return
	}

	if setting.Service.EnableCaptcha && setting.Service.RequireExternalRegistrationCaptcha {
		var valid bool
		var err error
		switch setting.Service.CaptchaType {
		case setting.ImageCaptcha:
			valid = context.GetImageCaptcha().VerifyReq(ctx.Req)
		case setting.ReCaptcha:
			valid, err = recaptcha.Verify(ctx, form.GRecaptchaResponse)
		case setting.HCaptcha:
			valid, err = hcaptcha.Verify(ctx, form.HcaptchaResponse)
		default:
			ctx.ServerError("Unknown Captcha Type", fmt.Errorf("Unknown Captcha Type: %s", setting.Service.CaptchaType))
			return
		}
		if err != nil {
			log.Debug("%s", err.Error())
		}

		if !valid {
			ctx.Data["Err_Captcha"] = true
			ctx.RenderWithErr(ctx.Tr("form.captcha_incorrect"), tplLinkAccount, &form)
			return
		}
	}

	if !form.IsEmailDomainAllowed() {
		ctx.RenderWithErr(ctx.Tr("auth.email_domain_blacklisted"), tplLinkAccount, &form)
		return
	}

	if setting.Service.AllowOnlyExternalRegistration || !setting.Service.RequireExternalRegistrationPassword {
		// In models.User an empty password is classed as not set, so we set form.Password to empty.
		// Eventually the database should be changed to indicate "Second Factor"-enabled accounts
		// (accounts that do not introduce the security vulnerabilities of a password).
		// If a user decides to circumvent second-factor security, and purposefully create a password,
		// they can still do so using the "Recover Account" option.
		form.Password = ""
	} else {
		if (len(strings.TrimSpace(form.Password)) > 0 || len(strings.TrimSpace(form.Retype)) > 0) && form.Password != form.Retype {
			ctx.Data["Err_Password"] = true
			ctx.RenderWithErr(ctx.Tr("form.password_not_match"), tplLinkAccount, &form)
			return
		}
		if len(strings.TrimSpace(form.Password)) > 0 && len(form.Password) < setting.MinPasswordLength {
			ctx.Data["Err_Password"] = true
			ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplLinkAccount, &form)
			return
		}
	}

	loginSource, err := models.GetActiveOAuth2LoginSourceByName(gothUser.Provider)
	if err != nil {
		ctx.ServerError("CreateUser", err)
	}

	u := &models.User{
		Name:        form.UserName,
		Email:       form.Email,
		Passwd:      form.Password,
		IsActive:    !(setting.Service.RegisterEmailConfirm || setting.Service.RegisterManualConfirm),
		LoginType:   models.LoginOAuth2,
		LoginSource: loginSource.ID,
		LoginName:   gothUser.UserID,
	}

	if !createAndHandleCreatedUser(ctx, tplLinkAccount, form, u, &gothUser, false) {
		// error already handled
		return
	}

	ctx.Redirect(setting.AppSubURL + "/user/login")
}
// LinkAccountPostRegister handle the creation of a new account for an external account using signUp
LinkAccountPostRegister handle the creation of a new account for an external account using signUp
// LinkAccountPostRegister handle the creation of a new account for an external account using signUp
func LinkAccountPostRegister(ctx *context.Context) {
	form := web.GetForm(ctx).(*forms.RegisterForm)
	ctx.Data["DisablePassword"] = !setting.Service.RequireExternalRegistrationPassword || setting.Service.AllowOnlyExternalRegistration
	ctx.Data["Title"] = ctx.Tr("link_account")
	ctx.Data["LinkAccountMode"] = true
	ctx.Data["LinkAccountModeRegister"] = true
	ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha && setting.Service.RequireExternalRegistrationCaptcha
	ctx.Data["RecaptchaURL"] = setting.Service.RecaptchaURL
	ctx.Data["Captcha"] = context.GetImageCaptcha()
	ctx.Data["CaptchaType"] = setting.Service.CaptchaType
	ctx.Data["RecaptchaSitekey"] = setting.Service.RecaptchaSitekey
	ctx.Data["HcaptchaSitekey"] = setting.Service.HcaptchaSitekey
	ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration
	ctx.Data["ShowRegistrationButton"] = false
	ctx.Data["SignInLink"] = setting.AppSubURL + "/user/link_account_signin"
	ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/link_account_signup"
	gothUserInterface := ctx.Session.Get("linkAccountGothUser")
	if gothUserInterface == nil {
		ctx.ServerError("UserSignUp", errors.New("not in LinkAccount session"))
		return
	}
	gothUser, ok := gothUserInterface.(goth.User)
	if !ok {
		ctx.ServerError("UserSignUp", fmt.Errorf("session linkAccountGothUser type is %t but not goth.User", gothUserInterface))
		return
	}
	if ctx.HasError() {
		ctx.HTML(http.StatusOK, tplLinkAccount)
		return
	}
	if setting.Service.DisableRegistration || setting.Service.AllowOnlyInternalRegistration {
		ctx.Error(http.StatusForbidden)
		return
	}
	if setting.Service.EnableCaptcha && setting.Service.RequireExternalRegistrationCaptcha {
		var valid bool
		var err error
		switch setting.Service.CaptchaType {
		case setting.ImageCaptcha:
			valid = context.GetImageCaptcha().VerifyReq(ctx.Req)
		case setting.ReCaptcha:
			valid, err = recaptcha.Verify(ctx, form.GRecaptchaResponse)
		case setting.HCaptcha:
			valid, err = hcaptcha.Verify(ctx, form.HcaptchaResponse)
		default:
			ctx.ServerError("Unknown Captcha Type", fmt.Errorf("Unknown Captcha Type: %s", setting.Service.CaptchaType))
			return
		}
		if err != nil {
			log.Debug("%s", err.Error())
		}
		if !valid {
			ctx.Data["Err_Captcha"] = true
			ctx.RenderWithErr(ctx.Tr("form.captcha_incorrect"), tplLinkAccount, &form)
			return
		}
	}
	if !form.IsEmailDomainAllowed() {
		ctx.RenderWithErr(ctx.Tr("auth.email_domain_blacklisted"), tplLinkAccount, &form)
		return
	}
	if setting.Service.AllowOnlyExternalRegistration || !setting.Service.RequireExternalRegistrationPassword {
		form.Password = ""
	} else {
		if (len(strings.TrimSpace(form.Password)) > 0 || len(strings.TrimSpace(form.Retype)) > 0) && form.Password != form.Retype {
			ctx.Data["Err_Password"] = true
			ctx.RenderWithErr(ctx.Tr("form.password_not_match"), tplLinkAccount, &form)
			return
		}
		if len(strings.TrimSpace(form.Password)) > 0 && len(form.Password) < setting.MinPasswordLength {
			ctx.Data["Err_Password"] = true
			ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplLinkAccount, &form)
			return
		}
	}
	loginSource, err := models.GetActiveOAuth2LoginSourceByName(gothUser.Provider)
	if err != nil {
		ctx.ServerError("CreateUser", err)
	}
	u := &models.User{
		Name:        form.UserName,
		Email:       form.Email,
		Passwd:      form.Password,
		IsActive:    !(setting.Service.RegisterEmailConfirm || setting.Service.RegisterManualConfirm),
		LoginType:   models.LoginOAuth2,
		LoginSource: loginSource.ID,
		LoginName:   gothUser.UserID,
	}
	if !createAndHandleCreatedUser(ctx, tplLinkAccount, form, u, &gothUser, false) {
		return
	}
	ctx.Redirect(setting.AppSubURL + "/user/login")
}
func LinkAccountPostRegister ( ctx * context . Context ) { form := web . GetForm ( ctx ) . ( * forms . RegisterForm ) ctx . Data [ " " ] = ! setting . Service . RequireExternalRegistrationPassword || setting . Service . AllowOnlyExternalRegistration ctx . Data [ " " ] = ctx . Tr ( " " ) ctx . Data [ " " ] = true ctx . Data [ " " ] = true ctx . Data [ " " ] = setting . Service . EnableCaptcha && setting . Service . RequireExternalRegistrationCaptcha ctx . Data [ " " ] = setting . Service . RecaptchaURL ctx . Data [ " " ] = context . GetImageCaptcha ( ) ctx . Data [ " " ] = setting . Service . CaptchaType ctx . Data [ " " ] = setting . Service . RecaptchaSitekey ctx . Data [ " " ] = setting . Service . HcaptchaSitekey ctx . Data [ " " ] = setting . Service . DisableRegistration ctx . Data [ " " ] = false ctx . Data [ " " ] = setting . AppSubURL + " " ctx . Data [ " " ] = setting . AppSubURL + " " gothUserInterface := ctx . Session . Get ( " " ) if gothUserInterface == nil { ctx . ServerError ( " " , errors . New ( " " ) ) return } gothUser , ok := gothUserInterface . ( goth . User ) if ! ok { ctx . ServerError ( " " , fmt . Errorf ( " " , gothUserInterface ) ) return } if ctx . HasError ( ) { ctx . HTML ( http . StatusOK , tplLinkAccount ) return } if setting . Service . DisableRegistration || setting . Service . AllowOnlyInternalRegistration { ctx . Error ( http . StatusForbidden ) return } if setting . Service . EnableCaptcha && setting . Service . RequireExternalRegistrationCaptcha { var valid bool var err error switch setting . Service . CaptchaType { case setting . ImageCaptcha : valid = context . GetImageCaptcha ( ) . VerifyReq ( ctx . Req ) case setting . ReCaptcha : valid , err = recaptcha . Verify ( ctx , form . GRecaptchaResponse ) case setting . HCaptcha : valid , err = hcaptcha . Verify ( ctx , form . HcaptchaResponse ) default : ctx . ServerError ( " " , fmt . Errorf ( " " , setting . Service . CaptchaType ) ) return } if err != nil { log . Debug ( " " , err . Error ( ) ) } if ! valid { ctx . Data [ " " ] = true ctx . RenderWithErr ( ctx . Tr ( " " ) , tplLinkAccount , & form ) return } } if ! form . IsEmailDomainAllowed ( ) { ctx . RenderWithErr ( ctx . Tr ( " " ) , tplLinkAccount , & form ) return } if setting . Service . AllowOnlyExternalRegistration || ! setting . Service . RequireExternalRegistrationPassword { form . Password = " " } else { if ( len ( strings . TrimSpace ( form . Password ) ) > 0 || len ( strings . TrimSpace ( form . Retype ) ) > 0 ) && form . Password != form . Retype { ctx . Data [ " " ] = true ctx . RenderWithErr ( ctx . Tr ( " " ) , tplLinkAccount , & form ) return } if len ( strings . TrimSpace ( form . Password ) ) > 0 && len ( form . Password ) < setting . MinPasswordLength { ctx . Data [ " " ] = true ctx . RenderWithErr ( ctx . Tr ( " " , setting . MinPasswordLength ) , tplLinkAccount , & form ) return } } loginSource , err := models . GetActiveOAuth2LoginSourceByName ( gothUser . Provider ) if err != nil { ctx . ServerError ( " " , err ) } u := & models . User { Name : form . UserName , Email : form . Email , Passwd : form . Password , IsActive : ! ( setting . Service . RegisterEmailConfirm || setting . Service . RegisterManualConfirm ) , LoginType : models . LoginOAuth2 , LoginSource : loginSource . ID , LoginName : gothUser . UserID , } if ! createAndHandleCreatedUser ( ctx , tplLinkAccount , form , u , & gothUser , false ) { return } ctx . Redirect ( setting . AppSubURL + " " ) }
LinkAccountPostRegister handle the creation of a new account for an external account using signUp
LinkAccountPostRegister handle the creation of a new account for an external account using signUp
// TODO Make insecure passwords optional for local accounts also, //      once email-based Second-Factor Auth is available // use this to set the right link into the signIn and signUp templates in the link_account template // In models.User an empty password is classed as not set, so we set form.Password to empty. // Eventually the database should be changed to indicate "Second Factor"-enabled accounts // (accounts that do not introduce the security vulnerabilities of a password). // If a user decides to circumvent second-factor security, and purposefully create a password, // they can still do so using the "Recover Account" option. // error already handled