예제 #1
0
파일: index.go 프로젝트: hogenwang/comcms
//执行删除管理员
func (c *AdminController) DoDel() {
	id, _ := strconv.ParseInt(c.GetString("id"), 10, 64)
	tip := &models.TipJSON{}
	tip.Status = models.TipError
	if id <= 0 {
		tip.Message = "错误参数传递!"
		EchoTip(&c.Controller, tip)
	}
	myid, _ := c.GetSession("adminid").(int)
	if id == int64(myid) {
		tip.Message = "您不能删除自己!"
		EchoTip(&c.Controller, tip)
	}
	entity := models.GetAdminById(id)
	if entity == nil {
		tip.Message = "系统找不到本记录!"
		EchoTip(&c.Controller, tip)
	} else {
		if err := models.DelAdmin(entity); err != nil {
			tip.Message = "删除出错:" + err.Error()
			EchoTip(&c.Controller, tip)
		} else {
			tip.Status = models.TipSuccess
			tip.Message = "删除成功!"
			tip.ReturnUrl = "/admin/admin/list"
			EchoTip(&c.Controller, tip)
		}
	}
}
예제 #2
0
파일: index.go 프로젝트: hogenwang/comcms
//显示修改管理员
func (c *AdminController) Edit() {
	CheckAdminLogin(&c.Controller, 0)

	myid := c.Ctx.Input.Param(":id")
	id, err := strconv.ParseInt(myid, 10, 64)
	if err != nil {
		EchoErrorPage(&c.Controller, "错误参数传递!", "/admin/admin/list")
	}
	entity := models.GetAdminById(id)
	if entity == nil {
		EchoErrorPage(&c.Controller, "系统找不到本记录!", "/admin/category")
	}
	c.Data["Title"] = "编辑/查看管理员详情"
	c.Data["Action"] = "edit"
	c.Data["Entity"] = entity
	c.TplNames = "admin/admin_add.tpl"
}
예제 #3
0
파일: index.go 프로젝트: hogenwang/comcms
//执行修改管理员
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)
}