コード例 #1
0
func (this *MainController) ChangePwd() {
	fmt.Println("修改密码成功")
	userInfo := this.GetSession("userinfo")
	if userInfo == nil {
		this.Ctx.Redirect(302, beego.AppConfig.String("auth_gateway"))
	}
	oldPwd := this.GetString("oldpwd")
	newPwd := this.GetString("newpwd")
	repeatpassword := this.GetString("reppwd")
	if newPwd != repeatpassword {
		this.Rsp(false, "二次密码输入不一致")
	}
	user, err := m.CheckLogin(userInfo.(m.User).Uname, oldPwd)
	if err == nil {
		var u m.User
		u.Id = user.Id
		u.Pwd = newPwd
		id, err := m.UpdateUser(&u)
		if err == nil && id > 0 {
			this.Rsp(true, "密码修改成功")
			return
		} else {
			this.Rsp(false, err.Error())
			return
		}

	}
	this.Rsp(false, "密码错误")
}
コード例 #2
0
//就是代表更新
func (this *UserController) Edit() {

	isAction := this.GetString("isAction")

	Id, _ := this.GetInt64("Id")
	Uname := this.GetString("Uname")
	Pwd := this.GetString("Pwd")
	Nickname := this.GetString("Nickname")
	Email := this.GetString("Email")
	Phone := this.GetString("Phone")
	Status, _ := this.GetInt64("Status")
	Remark := this.GetString("Remark")
	// Logintime := this.GetString("Logintime")
	// Ctime := this.GetString("Ctime")

	user := new(m.User)
	user.Id = Id
	user.Uname = strings.TrimSpace(Uname)
	user.Pwd = strings.TrimSpace(Pwd)
	user.Nickname = strings.TrimSpace(Nickname)
	user.Email = Email
	user.Phone = Phone
	user.Status = Status
	user.Remark = Remark

	if "0" == isAction {
		_, err := m.UpdateUser(user)
		if err != nil {
			this.Rsp(false, "更新出现问题:"+err.Error())
		} else {
			this.Ctx.Redirect(302, "/cstore/user/list.html")
		}
	} else {
		this.Data["Resource"] = user
		this.TplNames = "user/edit.html"
	}

}