You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

55 lines
1.2 KiB

package controller
import (
"GoClouds/cloud/sysCloud"
"GoClouds/core/comm"
"GoClouds/service/userService"
gocloud "github.com/mgr9525/go-cloud"
ruisUtil "github.com/mgr9525/go-ruisutil"
"gopkg.in/macaron.v1"
"time"
)
type UserController struct{}
func (e *UserController) GetPath() string {
return "/user"
}
func (e *UserController) Routes() {
gocloud.Web.Any("/login", e.login)
}
func (e *UserController) Mid() []macaron.Handler {
return []macaron.Handler{gocloud.AccessAllowFun}
}
func (e *UserController) login(c *macaron.Context, ctj gocloud.ContJSON) {
name := ctj.GetString("name")
pass := ctj.GetString("pass")
if len(name) <= 0 {
c.PlainText(511, []byte("param err:name!"))
return
}
if len(pass) <= 0 {
c.PlainText(511, []byte("param err:pass!"))
return
}
usr := userService.FindName(name)
if usr == nil {
c.PlainText(512, []byte("未找到用户"))
return
}
if usr.Pass != ruisUtil.Md5String(pass) {
c.PlainText(513, []byte("密码错误"))
return
}
if !sysCloud.CheckPermission(usr.Xid, "login") {
c.PlainText(514, []byte("帐号禁止登录"))
return
}
usr.Logintm = time.Now()
comm.DbSys.Cols("logintm").Where("xid=?", usr.Xid).Update(usr)
c.PlainText(200, []byte(usr.Xid))
}