Beispiel #1
0
// @router /api/users/signup [post]
func (u *UserController) Adduser() {
	var user models.User
	user.UserName = u.GetString("username")
	user.PassWord = u.GetString("password")
	user.TrueName = u.GetString("truename")
	user.StuNum = u.GetString("stunum")
	user.School = u.GetString("school")
	user.SchoolEx = u.GetString("schoolex")
	user.Email = u.GetString("email")
	user.UserPic = "defult.png"
	beego.Notice(user)
	err := models.CheckUserIsRight(user)
	if err != nil {
		u.Data["json"] = models.ErrorContext{Err: err.Error()}
		u.ServeJson()
	} else {
		err = models.AddUser(user)
		if err != nil {
			u.Data["json"] = models.ErrorContext{Err: err.Error()}
			u.ServeJson()
		} else {
			u.Data["json"] = models.ErrorContext{Data: "注册成功"}
			u.ServeJson()
		}

	}
}
Beispiel #2
0
// @router /api/users/login [post]
func (u *UserController) UserLogin() {
	var user models.User
	user.UserName = u.GetString("username")
	user.PassWord = u.GetString("password")
	beego.Notice(user)
	err := models.CheckUserWhenLogin(user)
	if err != nil {
		u.Data["json"] = models.ErrorContext{Err: err.Error()}
		u.ServeJson()
	} else {
		u.SetSession("longined", user.UserName)
		u.Data["json"] = models.ErrorContext{Data: "登陆成功"}
		u.ServeJson()
	}
}
Beispiel #3
0
// @router /api/users/forgetresult [post]
func (u *UserController) ForgotPassWordFianl() {
	var us models.User
	var vcode models.Pair
	var err error
	var forgotreq forgotReq
	tempdata := u.GetString("data")
	json.Unmarshal([]byte(tempdata), &forgotreq)
	vcode.Vcode = forgotreq.Vcode
	beego.Notice(vcode.Vcode)
	us.UserName, err = models.CheckVcode(vcode)
	if err != nil {
		u.Data["json"] = models.ErrorContext{Err: err.Error()}
	} else {
		us.PassWord = forgotreq.Pass
		err := models.UserRestPassWord(us)
		if err != nil {
			u.Data["json"] = models.ErrorContext{Err: "发生了未知的错误!"}
		} else {
			u.Data["json"] = models.ErrorContext{Data: "重置成功!"}
		}
	}
	u.ServeJson()
}