Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
george518 committed Sep 13, 2018
1 parent edbf7df commit b248de0
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
6 changes: 4 additions & 2 deletions controllers/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (

"github.com/george518/PPGo_ApiAdmin/utils"

"strconv"

"github.com/george518/PPGo_ApiAdmin/models"
cache "github.com/patrickmn/go-cache"
)
Expand Down Expand Up @@ -104,7 +106,7 @@ func (self *AuthController) AjaxSave() {
self.ajaxMsg(err.Error(), MSG_ERR)
}
}
utils.Che.Set("menu"+utils.Int2String(self.user.Id), nil, cache.DefaultExpiration)
utils.Che.Set("menu"+strconv.Itoa(self.user.Id), nil, cache.DefaultExpiration)
self.ajaxMsg("", MSG_OK)
}

Expand All @@ -117,6 +119,6 @@ func (self *AuthController) AjaxDel() {
if err := auth.Update(); err != nil {
self.ajaxMsg(err.Error(), MSG_ERR)
}
utils.Che.Set("menu"+utils.Int2String(self.user.Id), nil, cache.DefaultExpiration)
utils.Che.Set("menu"+strconv.Itoa(self.user.Id), nil, cache.DefaultExpiration)
self.ajaxMsg("", MSG_OK)
}
15 changes: 9 additions & 6 deletions controllers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (
"fmt"
"strconv"
"strings"
"yin/apiadmin/utils"

"github.com/george518/PPGo_ApiAdmin/libs"
"github.com/george518/PPGo_ApiAdmin/utils"

"github.com/astaxie/beego"
"github.com/george518/PPGo_ApiAdmin/models"
Expand Down Expand Up @@ -66,15 +68,16 @@ func (self *BaseController) auth() {
userId, _ := strconv.Atoi(idstr)
if userId > 0 {
var err error
cheUser, found := utils.Che.Get("uid" + utils.Int2String(userId))

cheUser, found := utils.Che.Get("uid" + strconv.Itoa(userId))
user := &models.Admin{}
if found && cheUser != nil { //从缓存取用户
user = cheUser.(*models.Admin)
} else {
user, err = models.AdminGetById(userId)
utils.Che.Set("uid"+utils.Int2String(user.Id), user, cache.DefaultExpiration)
utils.Che.Set("uid"+strconv.Itoa(userId), user, cache.DefaultExpiration)
}
if err == nil && password == utils.Md5([]byte(self.getClientIp()+"|"+user.Password+user.Salt)) {
if err == nil && password == libs.Md5([]byte(self.getClientIp()+"|"+user.Password+user.Salt)) {
self.userId = user.Id

self.loginName = user.LoginName
Expand All @@ -101,7 +104,7 @@ func (self *BaseController) auth() {
}

func (self *BaseController) AdminAuth() {
cheMen, found := utils.Che.Get("menu" + utils.Int2String(self.user.Id))
cheMen, found := utils.Che.Get("menu" + strconv.Itoa(self.user.Id))
if found && cheMen != nil { //从缓存取菜单
menu := cheMen.(*CheMenu)
//fmt.Println("调用显示菜单")
Expand Down Expand Up @@ -157,7 +160,7 @@ func (self *BaseController) AdminAuth() {
cheM.AllowUrl = self.allowUrl
cheM.List1 = self.Data["SideMenu1"].([]map[string]interface{})
cheM.List2 = self.Data["SideMenu2"].([]map[string]interface{})
utils.Che.Set("menu"+utils.Int2String(self.user.Id), cheM, cache.DefaultExpiration)
utils.Che.Set("menu"+strconv.Itoa(self.user.Id), cheM, cache.DefaultExpiration)
}

}
Expand Down
4 changes: 2 additions & 2 deletions controllers/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
"github.com/astaxie/beego"
"github.com/george518/PPGo_ApiAdmin/libs"
"github.com/george518/PPGo_ApiAdmin/models"
"github.com/george518/PPGo_ApiAdmin/utils"
cache "github.com/patrickmn/go-cache"
"gitub.com/george518/PPGo_ApiAdmin/utils"
)

type LoginController struct {
Expand Down Expand Up @@ -48,7 +48,7 @@ func (self *LoginController) LoginIn() {
user.LastIp = self.getClientIp()
user.LastLogin = time.Now().Unix()
user.Update()
utils.Che.Set("uid"+utils.Int2String(user.Id), user, cache.DefaultExpiration)
utils.Che.Set("uid"+strconv.Itoa(user.Id), user, cache.DefaultExpiration)
authkey := libs.Md5([]byte(self.getClientIp() + "|" + user.Password + user.Salt))
self.Ctx.SetCookie("auth", strconv.Itoa(user.Id)+"|"+authkey, 7*86400)

Expand Down
7 changes: 5 additions & 2 deletions controllers/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ package controllers
import (
"strings"
"time"
"yin/apiadmin/utils"

"github.com/george518/PPGo_ApiAdmin/utils"

"strconv"

"github.com/george518/PPGo_ApiAdmin/libs"
"github.com/george518/PPGo_ApiAdmin/models"
Expand All @@ -32,7 +35,7 @@ func (self *UserController) Edit() {
row["phone"] = Admin.Phone
row["email"] = Admin.Email
self.Data["admin"] = row
utils.Che.Set("uid"+utils.Int2String(self.user.Id), nil, cache.DefaultExpiration)
utils.Che.Set("uid"+strconv.Itoa(self.user.Id), nil, cache.DefaultExpiration)
self.display()
}

Expand Down
8 changes: 8 additions & 0 deletions views/login/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
<link rel="stylesheet" href="/static/layui/css/layui.css?t=1504439386550" media="all">
<link rel="stylesheet" href="/static/css/login.css?t=1504439386550" media="all">
</head>

<!--登录超时跳出框架显示登录页 start-->
<script>
if(self.location !== top.location){
top.location = self.location;
}
</script>
<!--登录超时跳出框架显示登录页 end-->
<body>
<div class="layui-carousel video_mask bg-img" id="login_carousel" >

Expand Down

0 comments on commit b248de0

Please sign in to comment.