-
Notifications
You must be signed in to change notification settings - Fork 0
/
session.go
executable file
·58 lines (50 loc) · 1.2 KB
/
session.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* Copyright 2014 @ S1N1 Team.
* name :
* author : jarryliu
* date : 2014-02-05 21:53
* description :
* history :
*/
package session
import (
"github.com/atnet/gof"
"github.com/atnet/gof/web"
"go2o/src/core"
"go2o/src/core/infrastructure/domain"
"net/http"
)
var _lsession *loginSession
func GetLSession() *loginSession {
if _lsession == nil {
_lsession = &loginSession{core.GlobalApp}
}
return _lsession
}
//商户业务逻辑
type loginSession struct {
gof.App
}
func (this *loginSession) AdministratorLogin(w http.ResponseWriter, usr string, pwd string) bool {
loginTokenResult := domain.Md5PartnerPwd(usr, pwd)
loginResult := loginTokenResult == ctx.App.Config().GetString("master_token")
if loginResult {
//存入cookie
expires := time.Now()
expires = expires.Add(3600 * 72 * 1e9) //72H
cookie := http.Cookie{Name: "mtkey",
Value: loginTokenResult,
Expires: expires}
http.SetCookie(w, &cookie)
web.Seria2json(w, true, "", nil)
return true
}
return false
}
func (this *loginSession) IsAdministrator(r *http.Request) bool {
cookie, _ := r.Cookie("mtkey")
if cookie == nil || cookie.Value != ctx.App.Config().GetString("master_token") {
return false
}
return true
}