nps/web/controllers/auth.go

43 lines
803 B
Go
Raw Normal View History

package controllers
import (
2019-03-19 09:26:17 -07:00
"encoding/hex"
2019-03-23 07:19:59 -07:00
"time"
2019-08-09 20:15:25 -07:00
2020-01-08 05:57:14 -08:00
"ehang.io/nps/lib/crypt"
2019-08-09 20:15:25 -07:00
"github.com/astaxie/beego"
)
type AuthController struct {
beego.Controller
}
func (s *AuthController) GetAuthKey() {
m := make(map[string]interface{})
defer func() {
s.Data["json"] = m
s.ServeJSON()
}()
2019-03-04 17:23:18 -08:00
if cryptKey := beego.AppConfig.String("auth_crypt_key"); len(cryptKey) != 16 {
m["status"] = 0
return
} else {
2019-03-04 17:23:18 -08:00
b, err := crypt.AesEncrypt([]byte(beego.AppConfig.String("auth_key")), []byte(cryptKey))
if err != nil {
m["status"] = 0
return
}
m["status"] = 1
2019-03-19 09:26:17 -07:00
m["crypt_auth_key"] = hex.EncodeToString(b)
m["crypt_type"] = "aes cbc"
return
}
}
2019-03-23 07:19:59 -07:00
func (s *AuthController) GetTime() {
m := make(map[string]interface{})
m["time"] = time.Now().Unix()
s.Data["json"] = m
s.ServeJSON()
}