/
login.go
executable file
·67 lines (57 loc) · 1.39 KB
/
login.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
59
60
61
62
63
64
65
66
67
package controllers
import (
"github.com/astaxie/beego"
"github.com/astaxie/beego/context"
)
type LoginController struct {
beego.Controller
}
func (c *LoginController) Get() {
isExit := c.Input().Get("exit") == "True"
beego.Debug("login get =", isExit)
if isExit {
c.Ctx.SetCookie("uname", "", -1, "/")
c.Ctx.SetCookie("passwd", "", -1, "/")
uname := c.Ctx.GetCookie("uname")
passwd := c.Ctx.GetCookie("passwd")
beego.Debug("blog[debug] exit", uname, passwd)
c.Redirect("/", 301)
return
}
c.TplNames = "login.html"
}
func (c *LoginController) Post() {
uname := c.Input().Get("uname")
passwd := c.Input().Get("passwd")
autoLogin := c.Input().Get("autoLogin") == "on"
if beego.AppConfig.String("uname") == uname &&
beego.AppConfig.String("passwd") == passwd {
maxAge := 0
if autoLogin {
maxAge = 1<<31 - 1
}
c.Ctx.SetCookie("uname", uname, maxAge, "/")
c.Ctx.SetCookie("passwd", passwd, maxAge, "/")
c.Data["LoginErr"] = false
}
c.Redirect("/", 301)
return
}
func checkAccount(ctx *context.Context) bool {
uname := ctx.GetCookie("uname")
/*if err != nil {
return false
}*/
//uname := ok.Value
passwd := ctx.GetCookie("passwd")
/*if err != nil {
return false
}*/
//passwd := ok.Value
beego.Debug("blog[debug]", uname, passwd)
if beego.AppConfig.String("uname") == uname &&
beego.AppConfig.String("passwd") == passwd {
return true
}
return false
}