Пример #1
0
Файл: users.go Проект: z2665/t12
// @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()
		}

	}
}
Пример #2
0
Файл: users.go Проект: z2665/t12
// @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()
	}
}