|
|
|
@ -6,7 +6,6 @@ import (
|
|
|
|
|
"github.com/ouqiang/gocron/models"
|
|
|
|
|
"github.com/go-macaron/session"
|
|
|
|
|
"github.com/ouqiang/gocron/modules/logger"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// @author qiang.ou<qingqianludao@gmail.com>
|
|
|
|
@ -30,20 +29,20 @@ func ValidateLogin(ctx *macaron.Context, sess session.Store) string {
|
|
|
|
|
return json.CommonFailure("用户名或密码错误")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sess.Set("username", username)
|
|
|
|
|
sess.Set("username", userModel.Name)
|
|
|
|
|
sess.Set("uid", userModel.Id)
|
|
|
|
|
|
|
|
|
|
return json.Success("登录成功", nil)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Logout(ctx *macaron.Context, sess session.Store) {
|
|
|
|
|
if IsLogin(sess) {
|
|
|
|
|
err := sess.Delete("username")
|
|
|
|
|
err := sess.Destory(ctx)
|
|
|
|
|
if err != nil {
|
|
|
|
|
logger.Error("用户退出登录失败", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctx.SetSecureCookie("MacaronSession", "", 0, "/", "", nil, nil, time.Now().AddDate(-1, 0, 0))
|
|
|
|
|
Login(ctx)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -56,9 +55,18 @@ func Username(sess session.Store) string {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Uid(sess session.Store) int {
|
|
|
|
|
uid,ok := sess.Get("uid").(int)
|
|
|
|
|
if ok {
|
|
|
|
|
return uid
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func IsLogin(sess session.Store) bool {
|
|
|
|
|
username,ok := sess.Get("username").(string)
|
|
|
|
|
if ok && username != "" {
|
|
|
|
|
uid, ok := sess.Get("uid").(int)
|
|
|
|
|
if ok && uid > 0 {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|