MCPcopy Index your code
hub / github.com/TruthHun/BookStack / Bind

Method Bind

controllers/AcountController.go:311–405  ·  view source on GitHub ↗

用户注册.[移除用户注册,直接叫用户绑定] 注意:如果用户输入的账号密码跟现有的账号密码相一致,则表示绑定账号,否则表示注册新账号。

()

Source from the content-addressed store, hash-verified

309//用户注册.[移除用户注册,直接叫用户绑定]
310//注意:如果用户输入的账号密码跟现有的账号密码相一致,则表示绑定账号,否则表示注册新账号。
311func (this *AccountController) Bind() {
312 var err error
313 account := this.GetString("account")
314 nickname := strings.TrimSpace(this.GetString("nickname"))
315 password1 := this.GetString("password1")
316 password2 := this.GetString("password2")
317 email := this.GetString("email")
318 oauthType := this.GetString("oauth")
319 oauthId := this.GetString("id")
320 avatar := this.GetString("avatar") //用户头像
321 isbind, _ := this.GetInt("isbind", 0)
322
323 ibind := func(oauthType string, oauthId, memberId interface{}) (err error) {
324 //注册成功,绑定用户
325 switch oauthType {
326 case "gitee":
327 err = models.ModelGitee.Bind(oauthId, memberId)
328 case "github":
329 err = models.ModelGithub.Bind(oauthId, memberId)
330 case "qq":
331 err = models.ModelQQ.Bind(oauthId, memberId)
332 }
333 return
334 }
335
336 if oauthType != "email" {
337 if auth, ok := this.GetSession("auth").(string); !ok || fmt.Sprintf("%v-%v", oauthType, oauthId) != auth {
338 this.JsonResult(6005, "绑定信息有误,授权类型不符")
339 }
340 } else { //邮箱登录,如果开启了验证码,则对验证码进行校验
341 if v, ok := this.Option["ENABLED_CAPTCHA"]; ok && strings.EqualFold(v, "true") {
342 if !cpt.VerifyReq(this.Ctx.Request) {
343 this.JsonResult(1, "验证码不正确")
344 }
345 }
346 }
347
348 member := models.NewMember()
349
350 if isbind == 1 {
351 if member, err = models.NewMember().Login(account, password1); err != nil || member.MemberId == 0 {
352 beego.Error("绑定用户失败", err, member)
353 this.JsonResult(1, "绑定用户失败,用户名或密码不正确")
354 }
355 } else {
356 if password1 != password2 {
357 this.JsonResult(6003, "登录密码与确认密码不一致")
358 }
359
360 if ok, err := regexp.MatchString(conf.RegexpAccount, account); account == "" || !ok || err != nil {
361 this.JsonResult(6001, "用户名只能由英文字母数字组成,且在3-50个字符")
362 }
363 if l := strings.Count(password1, ""); password1 == "" || l > 50 || l < 6 {
364 this.JsonResult(6002, "密码必须在6-50个字符之间")
365 }
366
367 if ok, err := regexp.MatchString(conf.RegexpEmail, email); !ok || err != nil || email == "" {
368 this.JsonResult(6004, "邮箱格式不正确")

Callers 1

LoginBindWechatMethod · 0.45

Calls 7

AddMethod · 0.95
NewMemberFunction · 0.92
GetDefaultAvatarFunction · 0.92
JsonResultMethod · 0.80
loginByMemberIdMethod · 0.80
LoginMethod · 0.45
CountMethod · 0.45

Tested by

no test coverage detected