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

Method SendMail

controllers/HomeControllers/UserController.go:368–421  ·  view source on GitHub ↗

发送邮件

()

Source from the content-addressed store, hash-verified

366
367// 发送邮件
368func (this *UserController) SendMail() {
369 beego.Info(this.Ctx.GetCookie("_xsrf"))
370
371 //发送邮件的类型:注册(reg)和找回密码(findpwd)
372 t := this.GetString("type")
373 if t != "reg" && t != "findpwd" {
374 this.ResponseJson(false, "邮件发送类型不正确")
375 }
376
377 valid := validation.Validation{}
378 email := this.GetString("email")
379 res := valid.Email(email, "mail")
380 if res.Error != nil || !res.Ok {
381 this.ResponseJson(false, "邮箱格式不正确")
382 }
383
384 //检测邮箱是否已被注册
385 ModelUser := models.NewUser()
386 user := ModelUser.GetUserField(orm.NewCondition().And("email", email))
387
388 //注册邮件
389 if t == "reg" {
390 if user.Id > 0 {
391 this.ResponseJson(false, "该邮箱已经被注册会员")
392 }
393
394 code := helper.RandStr(6, 0)
395 err := models.NewEmail().SendMail(email, fmt.Sprintf("%v会员注册验证码", this.Sys.Site), strings.Replace(this.Sys.TplEmailReg, "{code}", code, -1))
396 if err != nil {
397 helper.Logger.Error("邮件发送失败:%v", err.Error())
398 this.ResponseJson(false, "邮件发送失败,请联系管理员检查邮箱配置是否正确")
399 }
400
401 this.SetSession("RegMail", email)
402 this.SetSession("RegCode", code)
403 this.ResponseJson(true, "邮件发送成功,请打开邮箱查看验证码")
404 }
405
406 // 找回密码
407 if user.Id == 0 {
408 this.ResponseJson(false, "邮箱不存在")
409 }
410
411 code := helper.RandStr(6, 0)
412 err := models.NewEmail().SendMail(email, fmt.Sprintf("%v找回密码验证码", this.Sys.Site), strings.Replace(this.Sys.TplEmailFindPwd, "{code}", code, -1))
413 if err != nil {
414 helper.Logger.Error("邮件发送失败:%v", err.Error())
415 this.ResponseJson(false, "邮件发送失败,请联系管理员检查邮箱配置是否正确")
416 }
417
418 this.SetSession("FindPwdMail", email)
419 this.SetSession("FindPwdCode", code)
420 this.ResponseJson(true, "邮件发送成功,请打开邮箱查看验证码")
421}
422
423//会员签到,增加金币
424func (this *UserController) Sign() {

Callers 2

GetMethod · 0.45
TestForSendingEmailMethod · 0.45

Calls 2

GetUserFieldMethod · 0.95
ResponseJsonMethod · 0.45

Tested by

no test coverage detected