示例#1
0
文件: user.go 项目: wuwenbao/GoWebSSH
func (this *UserController) Add() {
	username := this.GetString("username")
	password := this.GetString("password")
	user := models.User{Username: username}
	exit := orm.NewOrm().QueryTable("user").Filter("username", username).Exist()
	if exit {
		this.ToJsonFail("已经存在!")
		return
	}
	user.Password = password
	_, err := orm.NewOrm().Insert(&user)
	if err != nil {
		beego.Error(err)
		this.ToJsonFail(err.Error())
		return
	}
	this.JsonSuccess()
}
示例#2
0
文件: user.go 项目: wuwenbao/GoWebSSH
func (this *UserController) ChangePwd() {
	newpassword1 := this.GetString("newpassword1", "")
	newpassword2 := this.GetString("newpassword2", "")
	password := this.GetString("password", "")
	if newpassword1 == "" {
		this.ToJsonFail("密码不能为空!!")
		return
	}
	if newpassword1 != newpassword2 {
		this.ToJsonFail("两次密码不一样!!")
		return
	}
	id := this.GetSession("uid").(int)
	m := models.User{Id: id}
	err := orm.NewOrm().Read(&m)
	if err != nil {
		beego.Error(err)
		this.ToJsonFail(err.Error())
		return
	}
	if password != m.Password {
		this.ToJsonFail("密码错误!!")
		return
	}
	m.Password = newpassword1
	_, err = orm.NewOrm().Update(&m, "Password")
	println(m.Password)
	if err != nil {
		beego.Error(err)
		this.ToJsonFail(err.Error())
		return
	}
	this.DelSession("username")
	this.DelSession("uid")
	this.JsonSuccess()
}