forked from golang/hotime
54 lines
1.0 KiB
Go
54 lines
1.0 KiB
Go
package app
|
|
|
|
import (
|
|
. "../../../hotime"
|
|
. "../../../hotime/common"
|
|
)
|
|
|
|
var adminCtr = Ctr{
|
|
"token": func(this *Context) {
|
|
this.Display(0, this.SessionId)
|
|
},
|
|
"test": func(this *Context) {
|
|
this.Session("id", this.SessionId)
|
|
},
|
|
//自带的登录
|
|
"login": func(this *Context) {
|
|
|
|
name := this.Req.FormValue("name")
|
|
pwd := this.Req.FormValue("password")
|
|
if len(name) < 2 ||
|
|
len(pwd) < 3 {
|
|
this.Display(3, "数据校验不通过")
|
|
}
|
|
where := Map{"password": Md5(pwd)}
|
|
if len(name) == 11 {
|
|
where["phone"] = name
|
|
} else {
|
|
where["name"] = name
|
|
}
|
|
|
|
admin := this.Db.Get("admin", "*", Map{"AND": where})
|
|
if admin == nil {
|
|
this.Display(4, "账户密码错误")
|
|
return
|
|
}
|
|
|
|
this.Session("id", admin.GetCeilInt("id"))
|
|
admin["password"] = nil
|
|
this.Display(0, admin)
|
|
|
|
},
|
|
"info": func(this *Context) {
|
|
admin := this.Db.Get("admin", "*", Map{"id": this.Session("id").ToInt()})
|
|
|
|
if admin == nil {
|
|
this.Display(2, "登录失效,请重新登录")
|
|
return
|
|
}
|
|
admin["password"] = nil
|
|
|
|
this.Display(0, admin)
|
|
},
|
|
}
|