MCPcopy Index your code
hub / github.com/TruthHun/DocHub / Reg

Method Reg

controllers/HomeControllers/UserController.go:316–365  ·  view source on GitHub ↗

会员注册[GET/POST]

()

Source from the content-addressed store, hash-verified

314
315//会员注册[GET/POST]
316func (this *UserController) Reg() {
317 if this.IsLogin > 0 {
318 this.Redirect("/user", 302)
319 return
320 }
321
322 if this.Ctx.Request.Method == "GET" {
323 this.Data["IsUser"] = true
324 this.Data["Seo"] = models.NewSeo().GetByPage("PC-Login", "会员注册", "会员注册", "会员注册", this.Sys.Site)
325 this.Data["PageId"] = "wenku-reg"
326 if this.Sys.IsCloseReg {
327 this.TplName = "regclose.html"
328 } else {
329 this.TplName = "reg.html"
330 }
331 return
332 }
333
334 if this.Sys.IsCloseReg {
335 this.ResponseJson(false, "注册失败,站点已关闭注册功能")
336 }
337
338 //先验证邮箱验证码是否正确
339 email := this.GetString("email")
340 code := this.GetString("code")
341 if this.Sys.CheckRegEmail {
342 sessEmail := fmt.Sprintf("%v", this.GetSession("RegMail"))
343 sessCode := fmt.Sprintf("%v", this.GetSession("RegCode"))
344 if sessEmail != email || sessCode != code {
345 this.ResponseJson(false, "邮箱验证码不正确,请重新输入或重新获取")
346 }
347 }
348
349 // 注册
350 err, uid := models.NewUser().Reg(
351 email,
352 this.GetString("username"),
353 this.GetString("password"),
354 this.GetString("repassword"),
355 this.GetString("intro"),
356 )
357 if err != nil {
358 this.ResponseJson(false, err.Error())
359 }
360
361 models.Regulate(models.GetTableSys(), "CntUser", 1, "Id=1") //站点用户数量增加
362 this.IsLogin = uid
363 this.SetCookieLogin(uid)
364 this.ResponseJson(true, "会员注册成功")
365}
366
367// 发送邮件
368func (this *UserController) SendMail() {

Callers

nothing calls this directly

Calls 3

GetByPageMethod · 0.80
SetCookieLoginMethod · 0.80
ResponseJsonMethod · 0.45

Tested by

no test coverage detected