예제 #1
0
파일: user.go 프로젝트: qmdx/GoCMS
//修改密码
func (c *User) EditPwd(admin *models.Admin) revel.Result {
	if c.Request.Method == "GET" {
		title := "修改密码--GoCMS管理系统"

		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.Edit(UserID) {
				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/")
		}
	}
}
예제 #2
0
파일: admin.go 프로젝트: qmdx/GoCMS
//编辑管理员
func (c Admin) Edit(admin *models.Admin) revel.Result {
	if c.Request.Method == "GET" {
		title := "编辑管理员--GoCMS管理系统"

		role := new(models.Role)
		role_list := role.GetRoleList()

		var id string = c.Params.Get("id")

		if len(id) > 0 {
			Id, err := strconv.ParseInt(id, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}

			admin_info := admin.GetById(Id)

			c.Render(title, admin_info, role_list)
		} else {
			c.Render(title, role_list)
		}

		return c.RenderTemplate("Setting/Admin/Edit.html")
	} else {

		var id string = c.Params.Get("id")

		if len(id) > 0 {
			Id, err := strconv.ParseInt(id, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}

			var username string = c.Params.Get("username")
			if len(username) > 0 {
				admin.Username = username
			} else {
				c.Flash.Error("请输入用户名!")
				c.Flash.Out["url"] = "/Admin/Edit/" + id + "/"
				return c.Redirect("/Message/")
			}

			var password string = c.Params.Get("password")
			if len(password) > 0 {
				admin.Password = password
			}

			var pwdconfirm string = c.Params.Get("pwdconfirm")
			if len(pwdconfirm) > 0 {
				if password != pwdconfirm {
					c.Flash.Error("两次输入密码不一致!")
					c.Flash.Out["url"] = "/Admin/Edit/" + id + "/"
					return c.Redirect("/Message/")
				}
			}

			var email string = c.Params.Get("email")
			if len(email) > 0 {
				admin.Email = email
			} else {
				c.Flash.Error("请输入E-mail!")
				c.Flash.Out["url"] = "/Admin/Edit/" + id + "/"
				return c.Redirect("/Message/")
			}

			var realname string = c.Params.Get("realname")
			if len(realname) > 0 {
				admin.Realname = realname
			} else {
				c.Flash.Error("请输入真实姓名!")
				c.Flash.Out["url"] = "/Admin/Edit/" + id + "/"
				return c.Redirect("/Message/")
			}

			var lang string = c.Params.Get("lang")
			if len(lang) > 0 {
				admin.Lang = lang
			} else {
				c.Flash.Error("请选择语言!")
				c.Flash.Out["url"] = "/Admin/Edit/" + id + "/"
				return c.Redirect("/Message/")
			}

			var roleid string = c.Params.Get("roleid")
			if len(roleid) > 0 {

				Roleid, err := strconv.ParseInt(roleid, 10, 64)
				if err != nil {
					revel.WARN.Println(err)
				}

				admin.Roleid = Roleid
			} else {
				c.Flash.Error("请选择所属角色!")
				c.Flash.Out["url"] = "/Admin/Edit/" + id + "/"
				return c.Redirect("/Message/")
			}

			var status string = c.Params.Get("status")
			if len(status) > 0 {
				Status, err := strconv.ParseInt(status, 10, 64)
				if err != nil {
					revel.WARN.Println(err)
				}
				admin.Status = Status
			} else {
				c.Flash.Error("请选择是否启用!")
				c.Flash.Out["url"] = "/Admin/Edit/" + id + "/"
				return c.Redirect("/Message/")
			}

			if admin.Edit(Id) {
				c.Flash.Success("编辑管理员成功!")
				c.Flash.Out["url"] = "/Admin/"
				return c.Redirect("/Message/")
			} else {
				c.Flash.Error("编辑管理员失败!")
				c.Flash.Out["url"] = "/Admin/Edit/" + id + "/"
				return c.Redirect("/Message/")
			}
		} else {
			c.Flash.Error("编辑管理员失败!")
			c.Flash.Out["url"] = "/Admin/Edit/" + id + "/"
			return c.Redirect("/Message/")
		}

	}
}
예제 #3
0
파일: user.go 프로젝트: qmdx/GoCMS
//个人信息
func (c *User) EditInfo(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/EditInfo.html")
	} else {

		var realname string = c.Params.Get("realname")
		if len(realname) > 0 {
			admin.Realname = realname
		} else {
			c.Flash.Error("请输入真实姓名!")
			c.Flash.Out["url"] = "/EditInfo/"
			return c.Redirect("/Message/")
		}

		var email string = c.Params.Get("email")
		if len(email) > 0 {
			admin.Email = email
		} else {
			c.Flash.Error("请输入电子邮件!")
			c.Flash.Out["url"] = "/EditInfo/"
			return c.Redirect("/Message/")
		}

		var lang string = c.Params.Get("lang")
		if len(lang) > 0 {
			admin.Lang = lang
		} else {
			c.Flash.Error("请选择语言!")
			c.Flash.Out["url"] = "/EditInfo/"
			return c.Redirect("/Message/")
		}

		if UserID, ok := c.Session["UserID"]; ok {
			UserID, err := strconv.ParseInt(UserID, 10, 64)
			if err != nil {
				revel.WARN.Println(err)
			}

			if admin.Edit(UserID) {
				c.Flash.Success("修改成功!")
				c.Flash.Out["url"] = "/EditInfo/"
				return c.Redirect("/Message/")
			} else {
				c.Flash.Error("修改失败!")
				c.Flash.Out["url"] = "/EditInfo/"
				return c.Redirect("/Message/")
			}
		} else {
			c.Flash.Error("未登陆,请先登陆!")
			c.Flash.Out["url"] = "/"
			return c.Redirect("/Message/")
		}
	}
}