forked from UlricQin/beego-blog
/
login_controller.go
48 lines (39 loc) · 1.08 KB
/
login_controller.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
package controllers
import (
"github.com/ulricqin/beego-blog/g"
)
type LoginController struct {
BaseController
}
func (this *LoginController) Login() {
this.TplNames = "login/login.html"
}
func (this *LoginController) DoLogin() {
name := this.GetString("name")
if name == "" {
this.Ctx.WriteString("name is blank")
return
}
password := this.GetString("password")
if password == "" {
this.Ctx.WriteString("password is blank")
return
}
if g.RootName != name {
this.Ctx.WriteString("name is incorrect" + g.RootName)
return
}
if g.RootPass != password {
this.Ctx.WriteString("password is incorrect")
return
}
this.Ctx.SetCookie("bb_name", name, 2592000, "/")
this.Ctx.ResponseWriter.Header().Add("Set-Cookie", "bb_password="+password+"; Max-Age=2592000; Path=/; httponly")
this.Ctx.WriteString("")
}
func (this *LoginController) Logout() {
this.Ctx.SetCookie("bb_name", g.RootName, 0, "/")
this.Ctx.ResponseWriter.Header().Add("Set-Cookie", "bb_password="+g.RootPass+"; Max-Age=0; Path=/; httponly")
// this.Ctx.WriteString("logout")
this.Redirect("/", 302)
}