Skip to content

Commit

Permalink
修复
Browse files Browse the repository at this point in the history
  • Loading branch information
lisijie committed May 26, 2015
1 parent 7f0db89 commit 8c077a2
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
5 changes: 5 additions & 0 deletions controllers/admin/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ type AccountController struct {

//登录
func (this *AccountController) Login() {

if this.userid > 0 {
this.Redirect("/admin", 302)
}

if this.GetString("dosubmit") == "yes" {
account := strings.TrimSpace(this.GetString("account"))
password := strings.TrimSpace(this.GetString("password"))
Expand Down
33 changes: 16 additions & 17 deletions controllers/admin/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,23 @@ func (this *baseController) Prepare() {

//登录状态验证
func (this *baseController) auth() {
if this.controllerName == "account" && (this.actionName == "login" || this.actionName == "logout") {

} else {
arr := strings.Split(this.Ctx.GetCookie("auth"), "|")
if len(arr) == 2 {
idstr, password := arr[0], arr[1]
userid, _ := strconv.Atoi(idstr)
if userid > 0 {
var user models.User
user.Id = userid
if user.Read() == nil && password == util.Md5([]byte(this.getClientIp()+"|"+user.Password)) {
this.userid = user.Id
this.username = user.UserName
}
arr := strings.Split(this.Ctx.GetCookie("auth"), "|")
if len(arr) == 2 {
idstr, password := arr[0], arr[1]
userid, _ := strconv.Atoi(idstr)
if userid > 0 {
var user models.User
user.Id = userid
if user.Read() == nil && password == util.Md5([]byte(this.getClientIp()+"|"+user.Password)) {
this.userid = user.Id
this.username = user.UserName
}
}
if this.userid == 0 {
this.Redirect("/admin/login", 302)
}
}

if this.userid == 0 && (this.controllerName != "account" ||
(this.controllerName == "account" && this.actionName != "logout" && this.actionName != "login")) {
this.Redirect("/admin/login", 302)
}
}

Expand Down Expand Up @@ -93,6 +91,7 @@ func (this *baseController) isPost() bool {
//获取用户IP地址
func (this *baseController) getClientIp() string {
s := strings.Split(this.Ctx.Request.RemoteAddr, ":")

return s[0]
}

Expand Down
2 changes: 2 additions & 0 deletions controllers/admin/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package admin

import (
"github.com/lisijie/goblog/models"
"github.com/lisijie/goblog/models/option"
)

type SystemController struct {
Expand Down Expand Up @@ -36,6 +37,7 @@ func (this *SystemController) Setting() {
opt.Update("Value")
}
}
option.FlushOptions()
this.Redirect("/admin/system/setting", 302)
}

Expand Down
6 changes: 6 additions & 0 deletions models/option/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ func GetOptions() map[string]string {
return v.(map[string]string)
}

func FlushOptions() {
rs, _ := util.Factory.Get("cache")
cache := rs.(*util.LruCache)
cache.Delete("options")
}

func Get(key string) string {
options := GetOptions()
if v, ok := options[key]; ok {
Expand Down
2 changes: 1 addition & 1 deletion views/admin/account/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<div class="main">
<div class="loginform">

<form method="post">
<form method="post" target="_top">
<input type="hidden" name="dosubmit" value="yes" />
<fieldset>
<legend>后台登录</legend>
Expand Down

0 comments on commit 8c077a2

Please sign in to comment.