-
Notifications
You must be signed in to change notification settings - Fork 0
/
loginByDocker.go
37 lines (33 loc) · 910 Bytes
/
loginByDocker.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
package controllers
import (
"encoding/json"
"github.com/astaxie/beego"
"github.com/astaxie/beego/orm"
"library/common"
"models"
"net/url"
"time"
)
type LoginByDockerController struct {
BaseController
}
func (c *LoginByDockerController) Get() {
if beego.BConfig.RunMode != "docker" {
c.StopRun()
return
}
jumpUrl := c.GetString("jumpurl")
var user models.User
o := orm.NewOrm()
err := o.Raw("SELECT * FROM `user` WHERE username= ?", "admin").QueryRow(&user)
if err == nil && user.AuthKey == "" {
userAuth := common.Md5String(user.Username + common.GetString(time.Now().Unix()))
user.AuthKey = userAuth
models.UpdateUserById(&user)
}
resUserInfo := map[string]interface{}{"user": user, "login": true}
userInfoJson, err := json.Marshal(resUserInfo)
c.Ctx.SetCookie("gopub_userinfo", url.QueryEscape(string(userInfoJson)), 3600*24*2, "/")
c.Redirect(jumpUrl, 302)
c.StopRun()
}