passport.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package http
  2. import (
  3. "go-common/app/service/main/passport-game/model"
  4. "go-common/app/service/main/passport-game/service"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. func oauth(c *bm.Context) {
  10. var (
  11. err error
  12. params = c.Request.Form
  13. accessKey = params.Get("access_key")
  14. from = params.Get("from")
  15. )
  16. if accessKey == "" {
  17. c.JSON(nil, ecode.RequestErr)
  18. return
  19. }
  20. app, ok := c.Get("app")
  21. if !ok {
  22. c.JSON(nil, ecode.AppKeyInvalid)
  23. return
  24. }
  25. var token *model.Token
  26. if token, err = srv.Oauth(c, app.(*model.App), accessKey, from); err != nil {
  27. log.Error("service.Oauth(%s) error(%v)", accessKey, err)
  28. res := map[string]interface{}{}
  29. if err == service.ErrDispatcherError {
  30. res["message"] = err.Error()
  31. }
  32. c.JSONMap(res, err)
  33. return
  34. }
  35. c.JSON(token, nil)
  36. }
  37. func getKeyOrigin(c *bm.Context) {
  38. var err error
  39. var t *model.RSAKey
  40. if t, err = srv.RSAKeyOrigin(c); err != nil {
  41. log.Error("service.RSAKeyOrigin() error(%v)", err)
  42. c.JSON(nil, err)
  43. return
  44. }
  45. c.JSON(t, nil)
  46. }
  47. func getKey(c *bm.Context) {
  48. c.JSON(srv.RSAKey(c), nil)
  49. }
  50. func getKeyProxy(c *bm.Context) {
  51. if srv.Proxy(c) {
  52. getKeyOrigin(c)
  53. return
  54. }
  55. getKey(c)
  56. }
  57. func renewToken(c *bm.Context) {
  58. var (
  59. err error
  60. params = c.Request.Form
  61. accessKey = params.Get("access_key")
  62. from = params.Get("from")
  63. )
  64. var r *model.RenewToken
  65. if r, err = srv.RenewToken(c, accessKey, from); err != nil {
  66. log.Error("service.RenewToken() error(%v)", err)
  67. res := map[string]interface{}{}
  68. if err == service.ErrDispatcherError {
  69. res["message"] = err.Error()
  70. }
  71. c.JSONMap(res, err)
  72. return
  73. }
  74. c.JSON(r, nil)
  75. }