-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.go
41 lines (37 loc) · 836 Bytes
/
auth.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
package controllers
import (
"encoding/hex"
"github.com/cnlh/nps/lib/crypt"
"github.com/cnlh/nps/vender/github.com/astaxie/beego"
"time"
)
type AuthController struct {
beego.Controller
}
func (s *AuthController) GetAuthKey() {
m := make(map[string]interface{})
defer func() {
s.Data["json"] = m
s.ServeJSON()
}()
if cryptKey := beego.AppConfig.String("auth_crypt_key"); len(cryptKey) != 16 {
m["status"] = 0
return
} else {
b, err := crypt.AesEncrypt([]byte(beego.AppConfig.String("auth_key")), []byte(cryptKey))
if err != nil {
m["status"] = 0
return
}
m["status"] = 1
m["crypt_auth_key"] = hex.EncodeToString(b)
m["crypt_type"] = "aes cbc"
return
}
}
func (s *AuthController) GetTime() {
m := make(map[string]interface{})
m["time"] = time.Now().Unix()
s.Data["json"] = m
s.ServeJSON()
}