Пример #1
0
func (c App) DoRegister(user *model.User) revel.Result {
	user.Flag = false
	user.Vip = 0
	user.Logo = fmt.Sprintf("default%d.jpg", rand.Intn(9))
	//todo check
	dao, err := model.NewDao()
	defer dao.Close()
	if err != nil {
		c.Flash.Error("用户保存失败,请稍后重试!")
		return c.Redirect("/register")
	}
	hasUser := dao.GetUserByName(user.Name)
	if hasUser != nil && hasUser.Name != "" {
		c.Flash.Error("用户名已存在,请登录或找回密码!")
		return c.Redirect("/register")
	}
	hasUser = dao.GetUserByEmail(user.Email)
	if hasUser != nil && hasUser.Name != "" {
		c.Flash.Error("邮箱/手机 已存在,请登录或找回密码!")
		return c.Redirect("/register")
	}
	err = dao.InserUser(user)
	if err != nil {
		c.Flash.Error("用户保存失败,请稍后重试!")
		return c.Redirect("/register")
	}
	c.Session["user"] = user.Name
	return c.Redirect("/")
}
Пример #2
0
func (c Mobile) Regist() revel.Result {
	user := new(model.User)
	username := c.Request.PostFormValue("name")
	if username == "" {
		user.Email = "请输入用户名"
		return c.RenderJson(user)
	}
	email := c.Request.PostFormValue("email")
	if email == "" {
		user.Email = "请输入邮箱/手机"
		return c.RenderJson(user)
	}
	pass := c.Request.PostFormValue("pass")
	if pass == "" {
		user.Email = "请输入密码"
		return c.RenderJson(user)
	}
	user.Name = username
	user.Email = email
	user.Pass = pass
	dao, err := model.NewDao()
	defer dao.Close()
	if err != nil {
		user.Name = ""
		user.Email = "数据保存失败了,请稍后再试!"
		return c.RenderJson(user)
	}
	hasUser := dao.GetUserByName(user.Name)
	if hasUser != nil && hasUser.Name != "" {
		user.Name = ""
		user.Email = "用户名已存在,请重新输入,或登录或找回密码!"
		return c.RenderJson(user)
	}
	hasUser = dao.GetUserByEmail(user.Email)
	if hasUser != nil && hasUser.Name != "" {
		user.Name = ""
		user.Email = "邮箱/手机 已存在,请重新输入,或登录或找回密码!"
		return c.RenderJson(user)
	}
	user.Flag = true
	user.Vip = 0
	user.Logo = fmt.Sprintf("default%d.jpg", rand.Intn(9))
	revel.ERROR.Printf("user: %v", user)
	err = dao.InserUser(user)
	if err != nil {
		user.Name = ""
		user.Email = "数据保存失败了,请稍后再试!"
		return c.RenderJson(user)
	}
	return c.RenderJson(user)
}