user.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. class UserEndpointsMixin:
  2. # no auth needed
  3. def user_profile(self, user_id, room_id=None):
  4. """
  5. Can be called with just user_id, room_id only seems to affect the url field
  6. :param user_id:
  7. :param room_id:
  8. :return:
  9. """
  10. endpoint = "/api/user/profile"
  11. result = self._api_get(endpoint, params={"user_id": user_id, "room_id": room_id})
  12. return result
  13. # auth required for meaningful result
  14. def is_birthday_registered(self):
  15. """
  16. Whether the currently logged in user has registered their birthday
  17. Returns true without auth
  18. :return:
  19. """
  20. endpoint = "/api/user/is_birthday_registered"
  21. result = self._api_get(endpoint)
  22. return result.get('is_birthday_registered')
  23. # auth required
  24. def account_info(self):
  25. """
  26. Returns data about currently logged in user's account
  27. Requires auth, otherwise it 404s
  28. :return:
  29. """
  30. endpoint = "/api/account/"
  31. result = self._api_get(endpoint)
  32. return result
  33. # post methods, none of these are truly working
  34. def update_gift_use_flag(self, flag_type, flag):
  35. """
  36. No idea what this does.
  37. :param flag_type:
  38. :param flag:
  39. :return:
  40. """
  41. endpoint = "/api/user/update_gift_use_flg"
  42. result = self._api_post(endpoint, data=dict(
  43. type=flag_type, flg=flag,
  44. csrf_token=self._csrf_token))
  45. return result
  46. def register_birthday(self, year, month, day):
  47. """
  48. Registers currently logged in user's birthday
  49. Returns {"ok": true} if successful, or a System Error otherwise (e.g. if trying to set it again)
  50. :param year:
  51. :param month:
  52. :param day:
  53. :return:
  54. """
  55. endpoint = "/api/user/register_birthday"
  56. r = self._api_post(endpoint, data=dict(
  57. year=year, month=month, day=day,
  58. csrf_token=self._csrf_token))
  59. return r
  60. # authenticate
  61. def login(self, username, password):
  62. """
  63. Login to a showroom account.
  64. :param username:
  65. :param password:
  66. :return:
  67. """
  68. endpoint = "/user/login"
  69. # fetch home page
  70. r = self._api_get("", return_response=True)
  71. if not r:
  72. # TODO: error
  73. return
  74. # get csrf_token
  75. # csrf_token = get_csrf_token(r.text)
  76. captcha_word = ""
  77. result = self._api_post(endpoint, data=dict(
  78. account_id=username,
  79. password=password,
  80. captcha_word=captcha_word,
  81. csrf_token=self._csrf_token
  82. ))
  83. if result.get('ok'):
  84. self._auth = result
  85. return True
  86. else:
  87. return False