Пример #1
0
//执行修改密码
func (c *AdminController) DoModPwd() {
	CheckAdminLogin(&c.Controller, 1)
	username, _ := c.GetSession("adminname").(string)
	uname := c.GetString("UserName")
	oldpwd := c.GetString("oldPwd")
	newpwd := c.GetString("newPwd")
	newpwd2 := c.GetString("newPwd2")
	tip := &models.TipJSON{}
	tip.Status = models.TipError
	if len(uname) < 4 {
		tip.Message = "用户名不能小于5个字符!"
		EchoTip(&c.Controller, tip)
	}
	if len(oldpwd) < 5 {
		tip.Message = "旧密码不能小于5个字符"
		EchoTip(&c.Controller, tip)
	}
	if len(newpwd) < 5 {
		tip.Message = "新密码不能小于5个字符!"
		EchoTip(&c.Controller, tip)
	}
	if newpwd != newpwd2 {
		tip.Message = "两次输入密码不一致,请重新输入!"
		EchoTip(&c.Controller, tip)
	}
	if username == uname && oldpwd == newpwd {
		tip.Message = "新旧密码一致,无法修改!"
		EchoTip(&c.Controller, tip)
	}

	//获取管理员

	admin := models.GetAdmin(username)
	if admin != nil {
		newpwdMd5 := common.GetMd5String(oldpwd)
		if admin.PassWord != newpwdMd5 {
			tip.Message = "旧密码错误,请重新输入!"
			EchoTip(&c.Controller, tip)
		}
		admin.UserName = uname
		admin.PassWord = common.GetMd5String(newpwd)
		models.EditAdmin(admin)
		tip.Status = models.TipSuccess
		tip.Message = "修改密码成功"
		if username != uname {
			tip.ReturnUrl = "/admin/logout"
		} else {
			tip.ReturnUrl = "/admin/"
		}
		EchoTip(&c.Controller, tip)

	} else {
		tip.Message = "登录授权过期!"
		EchoTip(&c.Controller, tip)
	}
}
Пример #2
0
//执行添加管理员
func (c *AdminController) DoAdd() {
	CheckAdminLogin(&c.Controller, 1)
	tip := &models.TipJSON{}
	tip.Status = models.TipError
	entity := &models.Admin{}
	username := c.GetString("UserName")
	password := c.GetString("PassWord")
	nickname := c.GetString("NickName")
	if len(username) < 4 {
		tip.Message = "用户名不能小于5个字符!"
		EchoTip(&c.Controller, tip)
	}
	if len(password) < 5 {
		tip.Message = "密码不能小于5个字符!"
		EchoTip(&c.Controller, tip)
	}
	a := models.GetAdmin(username)
	if a != nil {
		tip.Message = "该用户名已经存在,请修改!"
		EchoTip(&c.Controller, tip)
	}
	entity.UserName = username
	entity.PassWord = common.GetMd5String(password)
	entity.NickName = nickname
	entity.RoleId = 1 //否则无法登录
	if id, err := models.AddAdmin(entity); id > 0 && err == nil {
		//添加成功
		tip.Status = models.TipSuccess
		tip.Id = id
		tip.ReturnUrl = "/admin/admin/list"
		tip.Message = "添加管理员成功"
	} else {
		tip.Id = id
		tip.Message = "添加管理员失败:" + err.Error()
	}
	EchoTip(&c.Controller, tip)
}
Пример #3
0
//执行修改管理员
func (c *AdminController) DoEdit() {
	CheckAdminLogin(&c.Controller, 1)
	myid := c.Ctx.Input.Param(":id")
	editid, err := strconv.ParseInt(myid, 10, 64)
	tip := &models.TipJSON{}
	tip.Status = models.TipError

	if err != nil {
		tip.Message = "错误提交!"
		EchoTip(&c.Controller, tip)

	}

	id, err := c.GetInt64("Id")
	if err != nil {
		tip.Message = "错误参数传递!"
		EchoTip(&c.Controller, tip)

	}
	if editid != id {
		tip.Message = "错误参数传递!"
		EchoTip(&c.Controller, tip)
	}
	entity := models.GetAdminById(id)
	if entity == nil {
		tip.Message = "系统找不到本记录!"
		EchoTip(&c.Controller, tip)
	}
	username := c.GetString("UserName")
	password := c.GetString("PassWord")
	nickname := c.GetString("NickName")
	if len(username) < 4 {
		tip.Message = "用户名不能小于5个字符!"
		EchoTip(&c.Controller, tip)
	}
	if password != "" && len(password) < 5 {
		tip.Message = "密码不能小于5个字符!"
		EchoTip(&c.Controller, tip)
	}
	//如果用户名修改了。需要判断
	if entity.UserName != username {
		checkadmin := models.GetAdmin(username)
		if checkadmin != nil {
			tip.Message = "修改的用户名已经存在,请修改其他的用户名!"
			EchoTip(&c.Controller, tip)
		} else {
			entity.UserName = username
		}
	}
	if password != "" {
		entity.PassWord = common.GetMd5String(password)
	}
	entity.NickName = nickname
	if id, err := models.EditAdmin(entity); id > 0 && err == nil {
		//添加成功
		tip.Status = models.TipSuccess
		tip.Id = id
		tip.ReturnUrl = "/admin/admin/list"
		tip.Message = "编辑管理员信息成功"
	} else {
		tip.Id = id
		tip.Message = "编辑管理员失败:" + err.Error()
	}
	EchoTip(&c.Controller, tip)
}