user.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package http
  2. import (
  3. "go-common/library/ecode"
  4. bm "go-common/library/net/http/blademaster"
  5. )
  6. const (
  7. _sessUnKey = "username"
  8. )
  9. func queryUserInfo(c *bm.Context) {
  10. var (
  11. username string
  12. err error
  13. )
  14. if username, err = getUsername(c); err != nil {
  15. return
  16. }
  17. c.JSON(srv.QueryUserInfo(c, username))
  18. }
  19. func syncWechatContact(c *bm.Context) {
  20. c.JSON(nil, srv.HttpSyncWechatContacts(c))
  21. }
  22. func updateVisibleBugly(c *bm.Context) {
  23. var (
  24. v = new(struct {
  25. UpdateUsername string `form:"username"`
  26. VisibleBugly bool `form:"visible_bugly"`
  27. })
  28. err error
  29. username string
  30. )
  31. if err = c.Bind(v); err != nil {
  32. return
  33. }
  34. if username, err = getUsername(c); err != nil {
  35. return
  36. }
  37. c.JSON(nil, srv.UpdateUserVisibleBugly(c, username, v.UpdateUsername, v.VisibleBugly))
  38. }
  39. func accessToBugly(c *bm.Context) {
  40. var (
  41. username string
  42. err error
  43. )
  44. if username, err = getUsername(c); err != nil {
  45. return
  46. }
  47. if !srv.AccessToBugly(c, username) {
  48. c.JSON(nil, ecode.AccessDenied)
  49. c.Abort()
  50. return
  51. }
  52. }
  53. func getUsername(c *bm.Context) (username string, err error) {
  54. user, exist := c.Get(_sessUnKey)
  55. if !exist {
  56. err = ecode.AccessKeyErr
  57. c.JSON(nil, err)
  58. return
  59. }
  60. username = user.(string)
  61. return
  62. }