func (c User) SignupPost(user models.User) revel.Result { user.Validate(c.Validation) if c.Validation.HasErrors() { c.Validation.Keep() c.FlashParams() return c.Redirect(routes.User.Signup()) } salt := uuidName() user.Type = MEMBER_GROUP user.Avatar = models.DefaultAvatar user.ValidateCode = uuidName() user.Salt = salt user.HashedPassword = models.EncryptPassword(user.Password, salt) aff, _ := engine.Insert(&user) if aff == 0 { c.Flash.Error("注册用户失败") return c.Redirect(routes.User.Signup()) } subject := "激活账号 —— Revel中文社区" content := `<h2><a href="http://gorevel.cn/user/validate/` + user.ValidateCode + `">激活账号</a></h2>` go sendMail(subject, content, []string{user.Email}) c.Flash.Success(fmt.Sprintf("%s 注册成功,请到您的邮箱 %s 激活账号!", user.Name, user.Email)) engine.Insert(&models.Permissions{ UserId: user.Id, Perm: MEMBER_GROUP, }) return c.Redirect(routes.User.Signin()) }
func (c User) EditPost(avatar string) revel.Result { if c.Validation.HasErrors() { c.Validation.Keep() c.FlashParams() return c.Redirect(routes.User.Edit()) } var user models.User has, _ := engine.Id(c.user().Id).Get(&user) if !has { return c.NotFound("用户不存在") } file, header, err := c.Request.FormFile("image") if err == nil { defer file.Close() if ok := checkImageExt(c.Validation, &file, header, IMAGE_EXTS); ok { fileName := uuidFileName(header.Filename) err, ret := qiniuUploadImage(&file, fileName) if err != nil { c.Flash.Error("上传头像到七牛出错,请检查七牛配置。") return c.Redirect(routes.User.Edit()) } else { if user.IsCustomAvatar() { qiniuDeleteImage(user.Avatar) } user.Avatar = ret.Key } } } else if avatar != "" { if user.IsCustomAvatar() { qiniuDeleteImage(user.Avatar) } user.Avatar = avatar } aff, _ := engine.Id(c.user().Id).Cols("avatar").Update(&user) if aff > 0 { c.Flash.Success("保存成功") } else { c.Flash.Error("保存失败") } return c.Redirect(routes.User.Edit()) }