validator.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * 直播间男女端共用Manager
  3. */
  4. 'use strict';
  5. const F = require('../common/function');
  6. const C = require('../config');
  7. const _ = require('underscore');
  8. _.str = require('underscore.string');
  9. _.v = require('validator');
  10. const co = require('co');
  11. module.exports = function (app, commonManager) {
  12. var mgr_map = commonManager.mgr_map;
  13. /**
  14. * 判断用户是否在房间,true,则在房间,false,则不在
  15. * @param room_id
  16. * @param uid
  17. * @returns {boolean}
  18. */
  19. this.isRoomUser = function* (room_id, uid) {
  20. let roomid_map_uid_key = _.str.sprintf(C.redisPre.roomid_map_uid_key, room_id);
  21. let rank = yield mgr_map.redis.zrank(roomid_map_uid_key, uid);
  22. return !F.isNull(rank);
  23. };
  24. /**
  25. * 判断该socket是否在房间中
  26. * @param room_id
  27. * @param socket_id
  28. * @returns {boolean}
  29. */
  30. this.isRoomSocket = function* (room_id, socket_id) {
  31. let score = yield mgr_map.redis.getRoomSocketId(room_id, socket_id);
  32. return !F.isNull(score);
  33. };
  34. /**
  35. * 判断用户是否房主
  36. * @param room_id
  37. * @param uid
  38. * @returns {boolean}
  39. */
  40. this.isRoomCreator = function* (room_id, uid) {
  41. let room_info = yield mgr_map.room.getRoomInfo(room_id);
  42. if (F.isNull(room_info)) {
  43. F.throwErrCode(100203);
  44. }
  45. return room_info.uid == uid;
  46. };
  47. /**
  48. * 判断用户是否管理员
  49. * @param room_id
  50. * @param uid
  51. * @returns {boolean}
  52. */
  53. this.isRoomManager = function* (room_id, uid) {
  54. let room_manager = yield mgr_map.redis.getRoomManager(room_id, uid);
  55. return !F.isNull(room_manager);
  56. };
  57. /**
  58. *
  59. * @param room_id
  60. * @param uid
  61. * @returns {boolean}
  62. */
  63. this.isRoomBlacklist = function* (room_id, uid) {
  64. return yield mgr_map.redis.isBlacklist(room_id, uid);
  65. };
  66. this.isInPublicRoom = function* (room_id, socket_id) {
  67. let socket_room_id = yield mgr_map.redis.getPublicRoomIdBySocketId(socket_id);
  68. return room_id == socket_room_id;
  69. };
  70. /**
  71. * 校验实名认证
  72. */
  73. this.checkRealName = function* (uid, type) {
  74. let get_res = yield mgr_map.curl.httpGet(C.java_host, C.java_port, '/user/realname/v1/getUserRealNameStatus', {
  75. 'uid': uid,
  76. 'type': type
  77. }, null, 'utf8', 'http');
  78. if (!get_res.result) {
  79. F.throwErrCode(100101);
  80. }
  81. return JSON.parse(get_res.data);
  82. };
  83. };