|
|
@ -2,11 +2,17 @@ package controller |
|
|
|
|
|
|
|
import ( |
|
|
|
"GoClouds/cloud/sysCloud" |
|
|
|
"GoClouds/core/bean" |
|
|
|
"GoClouds/core/comm" |
|
|
|
"GoClouds/models" |
|
|
|
"GoClouds/service/userService" |
|
|
|
"encoding/json" |
|
|
|
"fmt" |
|
|
|
"github.com/go-macaron/cache" |
|
|
|
gocloud "github.com/mgr9525/go-cloud" |
|
|
|
ruisUtil "github.com/mgr9525/go-ruisutil" |
|
|
|
"gopkg.in/macaron.v1" |
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
) |
|
|
|
|
|
|
@ -16,12 +22,37 @@ func (e *UserController) GetPath() string { |
|
|
|
return "/user" |
|
|
|
} |
|
|
|
func (e *UserController) Routes() { |
|
|
|
gocloud.Web.Any("/info", e.info) |
|
|
|
gocloud.Web.Any("/login", e.login) |
|
|
|
} |
|
|
|
func (e *UserController) Mid() []macaron.Handler { |
|
|
|
return []macaron.Handler{gocloud.AccessAllowFun} |
|
|
|
} |
|
|
|
|
|
|
|
func (UserController) info(c *macaron.Context, ch cache.Cache, ctj gocloud.ContJSON) { |
|
|
|
id := ctj.GetString("id") |
|
|
|
if len(id) <= 0 { |
|
|
|
c.PlainText(500, []byte("param err")) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
e := &models.SysUser{} |
|
|
|
key := fmt.Sprintf("uinfo:%s", id) |
|
|
|
if ch.Get(key) != nil { |
|
|
|
bts := ch.Get(key).([]byte) |
|
|
|
err := json.Unmarshal(bts, e) |
|
|
|
if err == nil { |
|
|
|
c.JSON(200, e) |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
e = userService.FindXid(id) |
|
|
|
bts, err := json.Marshal(e) |
|
|
|
if err == nil { |
|
|
|
ch.Put(key, bts, 3600*5) |
|
|
|
} |
|
|
|
c.JSON(200, e) |
|
|
|
} |
|
|
|
func (e *UserController) login(c *macaron.Context, ctj gocloud.ContJSON) { |
|
|
|
name := ctj.GetString("name") |
|
|
|
pass := ctj.GetString("pass") |
|
|
@ -34,13 +65,20 @@ func (e *UserController) login(c *macaron.Context, ctj gocloud.ContJSON) { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
ret := &bean.SysLogin{} |
|
|
|
usr := userService.FindName(name) |
|
|
|
if usr == nil { |
|
|
|
c.PlainText(512, []byte("未找到用户")) |
|
|
|
ret.Errs = "未找到用户" |
|
|
|
c.JSON(200, ret) |
|
|
|
return |
|
|
|
} |
|
|
|
if usr.Pass != ruisUtil.Md5String(pass) { |
|
|
|
c.PlainText(513, []byte("密码错误")) |
|
|
|
if len(usr.Xid) <= 0 { |
|
|
|
usr.Xid = fmt.Sprintf("%d", usr.Id) |
|
|
|
comm.DbSys.Cols("xid").Where("id=?", usr.Id).Update(usr) |
|
|
|
} |
|
|
|
if usr.Pass != strings.ToUpper(ruisUtil.Md5String(pass)) { |
|
|
|
ret.Errs = "密码错误" |
|
|
|
c.JSON(200, ret) |
|
|
|
return |
|
|
|
} |
|
|
|
if !sysCloud.CheckPermission(usr.Xid, "login") { |
|
|
@ -51,5 +89,9 @@ func (e *UserController) login(c *macaron.Context, ctj gocloud.ContJSON) { |
|
|
|
usr.Logintm = time.Now() |
|
|
|
comm.DbSys.Cols("logintm").Where("xid=?", usr.Xid).Update(usr) |
|
|
|
|
|
|
|
c.PlainText(200, []byte(usr.Xid)) |
|
|
|
ret.Stat = 1 |
|
|
|
ret.Uid = usr.Id |
|
|
|
ret.Xid = usr.Xid |
|
|
|
ret.Name = usr.Name |
|
|
|
c.JSON(200, ret) |
|
|
|
} |