Пример #1
0
func (c *UserController) commonCreateUser() {

	var user entities.User
	user.Name = c.GetString("name")
	user.Mail = c.GetString("mail")
	user.Nick = user.Name
	user.Password = c.GetString("password")
	captcha := c.GetString("captcha")
	var err error
	isCaptchaValid := c.isMailCaptchaValid(captcha)
	if !isCaptchaValid {
		err = errors.New("验证码错误")
	} else {
		err = services.SaveUser(&user)
	}

	if err != nil {
		c.StringError(err.Error())
		c.Data["name"] = user.Name
		c.Data["mail"] = user.Mail
		c.Register()
	}

	c.SetCurrSession("user", user)

	c.Ctx.Redirect(302, "/")
}
Пример #2
0
func (c *UserController) PostTest() {
	var user = entities.User{}
	user.Name = "张利达"
	user.Age = 27
	user.Sex = 1
	c.SuccessResponse("data", user)
}
Пример #3
0
func TestSaveUser(t *testing.T) {

	user := new(entities.User)
	user.Name = "name"
	user.Mail = "*****@*****.**"
	user.Password = "******"

	err := services.SaveUser(user)

	fmt.Println(err)
}
Пример #4
0
func (c *UserController) oauthCreateUser() {

	var user entities.User
	user.Name = c.GetString("name")
	user.Mail = c.GetString("mail")
	user.Password = c.GetString("password")
	user.Nick = user.Name

	openUser := c.CurrentOpenUser()
	beego.Debug("openuser:"******"user", user)
		c.Ctx.Redirect(302, "/")
		var err error
		var result int64
		if unBindUser {
			result, err = services.BindUserIdToOpenUser(openUser.OpenId, entities.OPEN_USER_TYPE_QQ, user.Id)
		}
		//防止单个openuser 绑定多个user
		if nil == err && result > 0 {
			openUser.UserId = user.Id
			c.SetSession("openUser", openUser)
		}
		return
	}

	c.StringError(err.Error())
	c.Data["name"] = user.Name
	c.Data["mail"] = user.Mail
	c.OauthRegister()
}