Пример #1
0
//添加管理员
func (a *Admin) Save() bool {

	admin := new(Admin)
	admin.Username = a.Username
	admin.Password = lib.EncryptPassword(a.Password)
	admin.Roleid = a.Roleid
	admin.Lastloginip = lib.GetClientIP()
	admin.Email = a.Email
	admin.Realname = a.Realname
	admin.Lang = a.Lang
	admin.Lastlogintime = time.Now().Format("2006-01-02 15:04:04")

	has, err := Engine.Insert(admin)
	if err != nil {
		revel.WARN.Println(has)
		revel.WARN.Printf("错误: %v", err)
		return false
	}
	return true
}
Пример #2
0
//编辑管理员
func (a *Admin) Edit(Id int64) bool {

	admin := new(Admin)

	if len(a.Username) > 0 {
		admin.Username = a.Username
	}

	if len(a.Password) > 0 {
		a.Password = lib.EncryptPassword(a.Password)
	}

	if a.Roleid > 0 {
		admin.Roleid = a.Roleid
	}

	if len(a.Email) > 0 {
		admin.Email = a.Email
	}

	if len(a.Realname) > 0 {
		admin.Realname = a.Realname
	}

	if len(a.Lang) > 0 {
		admin.Lang = a.Lang
	}

	admin.Lastloginip = lib.GetClientIP()
	admin.Lastlogintime = time.Now().Format("2006-01-02 15:04:04")

	has, err := Engine.Id(Id).Update(admin)
	if err != nil {
		revel.WARN.Println(has)
		revel.WARN.Printf("错误: %v", err)
		return false
	}
	return true
}