//后台登陆 func (c *User) LoginPost() revel.Result { var username string = c.Params.Get("username") var password string = c.Params.Get("password") var verify string = c.Params.Get("verify") data := make(map[string]string) if len(username) <= 0 { data["status"] = "0" data["url"] = "/" data["info"] = "请填写用户名!" return c.RenderJson(data) } if len(password) <= 0 { data["status"] = "0" data["url"] = "/" data["info"] = "请填写密码!" return c.RenderJson(data) } if len(verify) <= 0 { data["status"] = "0" data["url"] = "/" data["info"] = "请填写验证码!" return c.RenderJson(data) } admin := new(models.Admin) admin = admin.GetByName(username) if admin.Id <= 0 { data["status"] = "0" data["url"] = "/" data["info"] = "用户名错误!" } else if username == admin.Username && lib.EncryptPassword(password) == admin.Password { c.Session["UserID"] = fmt.Sprintf("%d", admin.Id) data["status"] = "1" data["url"] = "/" data["info"] = "登陆成功!" } else { data["status"] = "0" data["url"] = "/" data["info"] = "密码错误!" } return c.RenderJson(data) }
//添加管理员 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 }
//编辑管理员 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 }