//修改密码 func (c *User) EditPwd(admin *models.Admin) revel.Result { if c.Request.Method == "GET" { title := "修改密码--GoCMS管理系统" if UserID, ok := c.Session["UserID"]; ok { UserID, err := strconv.ParseInt(UserID, 10, 64) if err != nil { revel.WARN.Println(err) } admin_info := admin.GetById(UserID) c.Render(title, admin_info) } else { c.Render(title) } return c.RenderTemplate("User/EditPwd.html") } else { if UserID, ok := c.Session["UserID"]; ok { UserID, err := strconv.ParseInt(UserID, 10, 64) if err != nil { revel.WARN.Println(err) } admin_info := admin.GetById(UserID) var old_password string = c.Params.Get("old_password") if len(old_password) > 0 { if admin_info.Password != utils.Md5(old_password) { c.Flash.Error("旧密码不正确!") c.Flash.Out["url"] = "/EditPwd/" return c.Redirect("/Message/") } } else { return c.Redirect("/User/EditPwd/") } var new_password string = c.Params.Get("new_password") if len(new_password) > 0 { } else { c.Flash.Error("新密码不能为空!") c.Flash.Out["url"] = "/EditPwd/" return c.Redirect("/Message/") } var new_pwdconfirm string = c.Params.Get("new_pwdconfirm") if len(new_pwdconfirm) > 0 { if new_pwdconfirm != new_password { c.Flash.Error("两次输入密码入不一致!") c.Flash.Out["url"] = "/EditPwd/" return c.Redirect("/Message/") } else { admin.Password = new_pwdconfirm } } else { c.Flash.Error("请输入重复新密码!") c.Flash.Out["url"] = "/EditPwd/" return c.Redirect("/Message/") } if admin.EditPwd(UserID) { //****************************************** //管理员日志 logs := new(models.Logs) desc := "个人设置|^|修改密码" logs.Save(admin_info, c.Controller, desc) //***************************************** c.Flash.Success("修改成功!") c.Flash.Out["url"] = "/EditPwd/" return c.Redirect("/Message/") } else { c.Flash.Error("修改失败!") c.Flash.Out["url"] = "/EditPwd/" return c.Redirect("/Message/") } } else { c.Flash.Error("未登陆,请先登陆!") c.Flash.Out["url"] = "/" return c.Redirect("/Message/") } } }