nps/web/controllers/auth.go

33 lines
659 B
Go
Raw Normal View History

package controllers
import (
"github.com/cnlh/nps/lib/crypt"
"github.com/cnlh/nps/vender/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
m["crypt_auth_key"] = string(b)
m["crypt_type"] = "aes cbc"
return
}
}