auth.go 652 B

1234567891011121314151617181920212223242526272829303132
  1. package controllers
  2. import (
  3. "github.com/cnlh/nps/lib/crypt"
  4. "github.com/cnlh/nps/vender/github.com/astaxie/beego"
  5. )
  6. type AuthController struct {
  7. beego.Controller
  8. }
  9. func (s *AuthController) GetAuthKey() {
  10. m := make(map[string]interface{})
  11. defer func() {
  12. s.Data["json"] = m
  13. s.ServeJSON()
  14. }()
  15. if cryptKey := beego.AppConfig.String("cryptKey"); len(cryptKey) != 16 {
  16. m["status"] = 0
  17. return
  18. } else {
  19. b, err := crypt.AesEncrypt([]byte(beego.AppConfig.String("authKey")), []byte(cryptKey))
  20. if err != nil {
  21. m["status"] = 0
  22. return
  23. }
  24. m["status"] = 1
  25. m["crypt_auth_key"] = string(b)
  26. m["crypt_type"] = "aes cbc"
  27. return
  28. }
  29. }