Esempio n. 1
0
//修改密码
func (this *Users) UpdatePassword(f *Field, pass *Password) error {
	defer db.Close()
	//用户密码是否正确
	u, err := this.ValidPassword(f.Updator, pass.OldPassword)
	if err != nil {
		return err
	}
	//更新数据
	_, err = db.Exec("update users set password=?,updated=?,updator=?,ip=? where id=?",
		utils.MD5(pass.NewPassword), f.Updated, f.Updator, f.Ip, u.Id)

	return err
}
Esempio n. 2
0
//验证用户密码是否合法
func (this *Users) ValidPassword(id int64, password string) (*Users, error) {
	defer db.Close()

	u := new(Users)

	err := db.WhereEqual("Id", id).Find(u)

	if err != nil {
		return nil, errors.New("accoundNotFound")
	} else {
		//校验密码
		if u.Password == utils.MD5(password) {
			return u, nil
		} else {
			return nil, errors.New("invalidPassword")
		}
	}
}
Esempio n. 3
0
//登录
func (this *Users) Login(loginName, password string, f *Field) (*Users, error) {
	defer db.Close()

	u := new(Users)
	condition := qbs.NewEqualCondition("Loginname", loginName).AndEqual("Deleted", utils.DelNormal)
	err := db.Condition(condition).Find(u)

	if err != nil {
		return nil, errors.New("accoundNotFound")
	} else {
		//是否被锁定
		if u.Status == utils.StatDisabled {
			return nil, errors.New("accountLocked")
		}
		//校验密码
		if u.Password == utils.MD5(password) {
			//db.Save(u)
			return u, nil
		} else {
			return nil, errors.New("invalidPassword")
		}
	}

}
Esempio n. 4
0
//设置签名,防止重复提交
func (this *base) token() string {
	s := utils.MD5(time.Now().String())
	this.SetSession("token", string(s))

	return s
}
Esempio n. 5
0
/*
新增账户
1、新增账户
2、增加账户基本信息
*/
func (this *Users) Add(m *Users) (int64, error) {
	defer db.Close()
	m.Password = utils.MD5(m.Password)
	return db.Save(m)
}