コード例 #1
0
 def register(self, params):
     userData = Users().getOne({Users.email == params['email']})
     if (userData == None):
         #昵称首字母
         isChinese = re.compile(u"[\u4e00-\u9fa5]+")
         isEnglish = re.compile('[a-zA-Z]')
         nickNameFirstWord = params['nickName'][0]
         if isChinese.search(nickNameFirstWord):
             first_word = Pinyin().get_initial(nickNameFirstWord)
         elif isEnglish.search(nickNameFirstWord):
             first_word = nickNameFirstWord.upper()
         else:
             first_word = '#'
         data = {
             'email': params['email'],
             'password': Users.set_password(params['password']),
             'nick_name': params['nickName'],
             'head_img': params['headImg'],
             'first_word': first_word,
             'created_at': time.time(),
             'updated_at': time.time()
         }
         user = Users().add(data)
         if user == False:
             return Utils.formatError(Code.BAD_REQUEST, '注册失败')
         else:
             result = UsersAuthJWT.authenticate(params['email'],
                                                params['password'])
             return result
         return Utils.formatError(Code.BAD_REQUEST, '注册失败')
     return Utils.formatError(Code.BAD_REQUEST, '账号已注册')
コード例 #2
0
    def adminChat(message: dict) -> dict:
        admin_user_info = UsersAuthJWT().adminIdentify(
            message['Authorization'])
        if isinstance(admin_user_info, str):
            return Utils.formatError(CONST['CODE']['ERROR_AUTH_CHECK_TOKEN_FAIL']['value'], admin_user_info)
        # 整合数据信息
        filters = {
            Admin.id == admin_user_info['data']['id'],
        }
        admin_user_info = Admin().getOne(filters)
        default_img_data = Config().getOne(
            {Config.type == 'img', Config.code == 'default.img', Config.status == 1})
        if default_img_data == None:
            default_img = 'static/img/about/python.jpg'
        else:
            default_img = default_img_data['config']

        admin_user_info['nick_name'] = '系统管理-'+admin_user_info['nick_name']
        admin_user_info['head_img'] = default_img  # 这里后期改成配置的
        # 使用0作为系统id
        msg = message['data']['msg']
        room_uuid = message['data']['room_uuid']
        Type = message['data']['type']
        room_data = Room.get(room_uuid)
        if room_data == None:
            return Utils.formatError(CONST['CODE']['ROOM_NO_EXIST']['value'], "房间不存在")
        room_type = room_data.type
        created_at = int(time.time())
        save_action = message['data']['save_action']
        return ChatService.sendChatMessage(msg, room_uuid, Type, room_data, room_type, created_at, save_action, admin_user_info, 1)
コード例 #3
0
 def login(self, data):
     name = data['name']
     #生成一个md5对象
     m1 = hashlib.md5()
     #使用md5对象里的update方法md5转换
     m1.update(data['pwd'].encode("utf-8"))
     pwd = m1.hexdigest()
     #用户名/邮箱/手机登录
     filters = {
         Admin.name == name, Admin.pwd == pwd, Admin.delete_time == 0
     }
     admin = Admin().getOne(filters, 'add_time desc')
     if admin == None:
         filters = {
             Admin.email == name, Admin.pwd == pwd, Admin.delete_time == 0
         }
         admin = Admin().getOne(filters, 'add_time desc')
         if admin == None:
             filters = {
                 Admin.mobile == name, Admin.pwd == pwd,
                 Admin.delete_time == 0
             }
             admin = Admin().getOne(filters, 'add_time desc')
     if admin != None:
         #更新登录时间
         filters = {Admin.id == admin['id']}
         update_time = int(time.time())
         Admin().edit({Admin.update_time: update_time}, filters)
         token = UsersAuthJWT.encode_auth_token(admin['id'], update_time)
         return Utils.formatBody({'token': token, 'user': admin})
     return Utils.formatError(CONST['CODE']['ERROR']['value'])
コード例 #4
0
def login():
    oa_account = request.json.get('account')
    password = request.json.get('password')
    if not oa_account or not password:
        return BaseController().error('账号和密码不能为空')
    else:
        result = UsersAuthJWT.authenticate(oa_account, password)
        return result
コード例 #5
0
def login():
    ''' 登录 '''
    email = request.json.get('email')
    password = request.json.get('password')
    if (not email or not password):
        return BaseController().error('用户名和密码不能为空')
    else:
        result = UsersAuthJWT.authenticate(email, password)
        return result
コード例 #6
0
def get():
    '''
    *获取用户信息 
    *jwt中修改error处理方法,统一响应头
    *_default_jwt_error_handler
    '''
    result = UsersAuthJWT().identify(request)
    if isinstance(result, str):
        return BaseController().error(result)
    if (result['data']):
        user = Users.get(result['data']['id'])
        returnUser = {
            'id': user.id,
            'name': user.name,
            'email': user.email,
            'login_time': user.updated_at
        }
        return BaseController().successData(returnUser)
    return BaseController().error('未找到用户')
コード例 #7
0
 def register(params):
     userData = Users().getOne({Users.email == params['email']})
     if (userData == None):
         #昵称首字母
         isChinese = re.compile(u"[\u4e00-\u9fa5]+")
         isEnglish = re.compile('[a-zA-Z]')
         nickNameFirstWord = params['nickName'][0]
         nowTime = time.time()
         if isChinese.search(nickNameFirstWord):
             first_word = Pinyin().get_initial(nickNameFirstWord)
         elif isEnglish.search(nickNameFirstWord):
             first_word = nickNameFirstWord.upper()
         else:
             first_word = '#'
         data = {
             'email': params['email'],
             'password': Users.set_password(params['password']),
             'nick_name': params['nickName'],
             'head_img': params['headImg'],
             'first_word': first_word,
             'created_at': nowTime,
             'updated_at': nowTime
         }
         user = Users().add(data)
         if user == False:
             return Utils.formatError(CONST['CODE']['BAD_REQUEST']['value'],
                                      '注册失败')
         else:
             result = UsersAuthJWT.authenticate(params['email'],
                                                params['password'])
             # 发送延时推广进群广告
             invite = Invite()
             invite.setAction("invite")
             invite.setId(result['data']['user']['id'])
             # 延时2分钟推送
             delayQueue.product(invite.__dict__, 120)
             return result
     return Utils.formatError(CONST['CODE']['BAD_REQUEST']['value'],
                              '账号已注册')
コード例 #8
0
 def adminCreateRoom(message):
     admin_user_info = UsersAuthJWT().adminIdentify(
         message['Authorization'])
     if isinstance(admin_user_info, str):
         return Utils.formatError(CONST['CODE']['ERROR_AUTH_CHECK_TOKEN_FAIL']['value'], admin_user_info)
     filters = {
         Admin.id == admin_user_info['data']['id'],
     }
     admin_user_info = Admin().getOne(filters)
     filters = {
         AddressBook.be_focused_user_id == message['user_id'],
         AddressBook.focused_user_id == admin_user_info['id'],
         AddressBook.type == 1
     }
     addressBookInfo = AddressBook().getOne(filters)
     if addressBookInfo == None:
         room_uuid = Utils.unique_id()
         # 建立通讯录关系
         status = AddressBook.adminAddRoomAndAddressBook(
             room_uuid, admin_user_info, message['user_id'])
         if status == False:
             return Utils.formatError(CONST['CODE']['BAD_REQUEST']['value'], msg='添加失败')
         # 添加后同步房间
         addressBookData = AddressBook.get(room_uuid)
         for item in addressBookData:
             roomList = AddressBook.getRoomList(
                 item.be_focused_user_id)['list']
             if item['type'] == CONST['ADDRESSBOOK']['ADMIN']['value']:
                 socketio.emit('room', Utils.formatBody(
                     roomList), namespace="/api", room='@broadcast.'+str(item.be_focused_user_id))
             else:
                 socketio.emit('room', Utils.formatBody(
                     roomList), namespace="/api", room='@broadcast.'+str(item.be_focused_user_id))
     else:
         room_uuid = addressBookInfo['room_uuid']
     return Utils.formatBody({'room_uuid': room_uuid})
コード例 #9
0
 def login(params):
     return UsersAuthJWT.authenticate(params['email'], params['password'])
コード例 #10
0
ファイル: UsersController.py プロジェクト: caoxianwei/chat-2
def login(params):
    result = UsersAuthJWT.authenticate(params['email'], params['password'])
    return BaseController().json(result)