Exemplo n.º 1
0
func (this *UserController) Reg() {

	beego.Info("register controller")
	result := make(map[string]interface{})
	result["succ"] = "succ"

	email := this.GetString("email")
	pwd := this.GetString("pwd")

	beego.Info(email)
	beego.Info(pwd)

	u := new(models.User)
	u.Email = email
	u.Pwd = helper.MD5(pwd)
	u.Reged = time.Now()
	u.Uname = email

	id, err := models.SaveUser(u)
	if err != nil {
		beego.Error(err)
		result["succ"] = "err"
	} else {
		result["id"] = u.Pwd
		result["email"] = email
	}
	this.SetSession("online_user", "u_"+strconv.FormatInt(id, 10))
	this.SetSession("online_user_email", email)

	this.Data["json"] = result
	this.ServeJson()
}