示例#1
0
文件: index.go 项目: hogenwang/comcms
//执行修改密码
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
文件: admin.go 项目: hogenwang/comcms
func AdminLogin(username, password, ip string) (*Admin, bool) {
	var entity = new(Admin)
	flag := false
	if len(username) < 4 || len(password) < 5 {
		return nil, flag
	}
	md5password := common.GetMd5String(password)
	entity = &Admin{UserName: username, PassWord: md5password}

	var err error
	has, err := x.Get(entity)
	//查询不到,返回
	if !has || err != nil {
		fmt.Println("没找到管理员:", entity)
		return nil, flag
	}
	fmt.Println("现在的:", entity)
	//写入记录
	entity.LastLoginIP = entity.ThisLoginIP
	entity.LastLoginTime = entity.ThisLoginTime
	entity.ThisLoginTime = time.Now()
	entity.ThisLoginIP = ip
	entity.LoginCount += 1
	fmt.Println("准备写入:", entity)
	_, err = x.Id(entity.Id).Update(entity)

	if err != nil {
		//写入失败记录
		fmt.Println("准备失败 :", err.Error())
		return nil, flag
	}
	flag = true
	return entity, flag
}
示例#3
0
文件: index.go 项目: hogenwang/comcms
//执行添加管理员
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)
}
示例#4
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)
}