示例#1
0
def displayLogin():
    username = input('Username: '******'Password: '******'msg'])
    _uAuth.storeTokens(t_type='access', token=r.body['access_token'])
    return _pageLogged.menu()
示例#2
0
 def post(self):
     try:
         args = request.args
         parser.add_argument('message', help='Chat message', required=True)
         reqData = parser.parse_args()
         userId = get_jwt_claims()
         userAllowed = _mSharedChat.allowedRead(userId['identity'])
         if _functions.resultError(userAllowed):
             return userAllowed.flaskResp()
         sChat = _mChat.findById(args['chatId'])
         if _functions.resultError(sChat):
             return sChat.flaskResp()
         new_message = {
             'message': reqData['message'],
             'from': userId['identity'],
             'read': False,
         }
         uChat = _mSharedMessage.new(sChat.id, new_message)
         if _functions.resultError(uChat):
             return uChat.flaskResp()
         return _functions.setModuleSuccess(payload=uChat.messages,
                                            key='mongo',
                                            status=200).flaskResp()
     except Exception as e:
         return _functions.setModuleError(payload=e,
                                          error='Error posting new message',
                                          status=500).flaskResp()
示例#3
0
def alive():
    try:
        return _functions.setModuleSuccess(payload='Hi, how are you',
                                           status=200)
    except Exception as e:
        return _functions.setModuleError(payload=e,
                                         error="Error checking alive",
                                         status=500)
示例#4
0
 def delete(self):
     try:
         jti = get_raw_jwt()['jti']
         _tmpDb.RevokeInstance.set(jti, 'true', ACCESS_EXPIRES * 1.2)
         return _functions.setModuleSuccess(payload='Access token revoked',
                                            status=200).flaskResp()
     except Exception as e:
         return _functions.setModuleError(
             payload=e, error='Error access token revoked ...',
             status=500).flaskResp()
示例#5
0
 def get(self):
     try:
         userId = get_jwt_identity()
         sUser = _mUser.findById(userId)
         if sUser is None:
             return _responses.userNotFound().flaskResp()
         if _functions.resultError(sUser):
             return sUser.flaskResp()
         return _functions.setModuleSuccess(payload=_mUser.selectInfo(['email', 'dni', 'name', 'surname', 'age'], sUser), key='master', status=200).flaskResp()
     except Exception as e:
         return _functions.setModuleError(payload=e, error='Error accessing user information ...').flaskResp()
示例#6
0
 def post(self):
     try:
         current_user = get_jwt_identity()
         access_token = _utilAuth.createAccessToken(current_user)
         access_jti = get_jti(encoded_token=access_token)
         _tmpDb.RevokeInstance.set(access_jti, 'false',
                                   ACCESS_EXPIRES * 1.2)
         return _functions.setModuleSuccess(payload={
             'access_token': access_token
         },
                                            key='master',
                                            status=201).flaskResp()
     except Exception as e:
         return _functions.setModuleError(
             payload=e, error='Error refreshing token ...').flaskResp()
示例#7
0
 def get(self):
     try:
         user = get_jwt_claims()
         sUser = _mUser.findOne('_id', user['identity'])
         if _functions.resultError(sUser):
             return sChat.flaskResp()
         userChats = _mUser.myChats(user['identity'])
         if _functions.resultError(sUser._id):
             return userChats.flaskResp()
         return _functions.setModuleSuccess(payload=list(userChats),
                                            key='mongo',
                                            status=200).flaskResp()
     except Exception as e:
         return _functions.setModuleError(
             payload=e,
             error='Error listing chats, try it later ...',
             status=500).flaskResp()
示例#8
0
 def get(self):
     try:
         args = request.args
         userId = get_jwt_claims()
         userAllowed = _mSharedChat.allowedRead(userId['identity'])
         if _functions.resultError(userAllowed):
             return userAllowed.flaskResp()
         sChat = _mChat.findById(args['chatId'])
         if _functions.resultError(sChat):
             return sChat.flaskResp()
         return _functions.setModuleSuccess(payload=sChat.messages,
                                            key='mongo',
                                            status=200).flaskResp()
     except Exception as e:
         return _functions.setModuleError(payload=e,
                                          error='Error posting new message',
                                          status=500).flaskResp()
示例#9
0
 def post(self):
     try:
         reqData = parser.parse_args()
         vPassword = _validators.checkPassword(reqData['password'])
         if _functions.resultError(vPassword):
             return vPassword.flaskResp()
         hashPassword = _auth.hashPassword(reqData['password'])
         if _functions.resultError(hashPassword):
             return hashPassword
         newRoundsMan = _models.User(
             username=reqData['username'],
             password=hashPassword,
         )
         newRoundsMan.save()
         return _functions.setModuleSuccess(
             payload='User created successfully', status=200).flaskResp()
     except Exception as e:
         return _functions.setModuleError(
             payload=e,
             error='Error crating new user, try it later...',
             status=500).flaskResp()
示例#10
0
    def post(self):
        try:
            parser.add_argument('username',
                                help='User with whom to start the chat',
                                required=False)
            parser.add_argument('chat', help='Chat id', required=False)
            reqData = parser.parse_args()
            alloweds = []

            sUser = _mUser.findOne('username', reqData['username'])
            if _functions.resultError(sUser):
                return sUser.flaskResp()

            alloweds.append(sUser._id)
            creator = get_jwt_claims()
            alloweds.append(creator['identity'])

            newChat = _models.Chat(creator=creator['identity'],
                                   alloweds=alloweds)
            newChat.save()

            uUser = _mUser.findOneAndUpdate('_id', creator['identity'],
                                            'chats', newChat.id)
            if _functions.resultError(uUser):
                return uUser.flaskResp()

            uToUser = _mUser.findOneAndUpdate('_id', sUser._id, 'chats',
                                              newChat.id)
            if _functions.resultError(uToUser):
                return uUser.flaskResp()

            return _functions.setModuleSuccess(
                payload='Chat initialized correctly', status=200).flaskResp()
        except Exception as e:
            return _functions.setModuleError(
                payload=e,
                error='Error creating new chat, try it later ...',
                status=500).flaskResp()
示例#11
0
    def post(self):
        try:
            reqData = parser.parse_args()
            user = _moduleUser.findOne('username', reqData['username'])
            if user is None:
                return _functions.setModuleError(
                    payload='User not found on DB',
                    error='User not found, try it later...',
                    status=404).flaskResp()
            unHashPassword = _auth.unHashPassword(reqData['password'],
                                                  user['password'])
            if _functions.resultError(unHashPassword):
                return unHashPassword.flaskResp()
            tokens = _auth.encodeJwt(user)
            if _functions.resultError(tokens):
                return tokens.flaskResp()
            access_jti = get_jti(encoded_token=tokens.token)
            refresh_jti = get_jti(encoded_token=tokens.rToken)

            _tmpDb.RevokeInstance.set(
                access_jti, 'false', _tmpDb.TokensExpires.access_expires * 1.2)
            _tmpDb.RevokeInstance.set(
                refresh_jti, 'false',
                _tmpDb.TokensExpires.refresh_expires * 1.2)

            return _functions.setModuleSuccess(payload={
                'msg': 'Login success',
                'access_token': tokens.token,
                'refresh_token': tokens.rToken
            },
                                               key='master',
                                               status=201).flaskResp()
        except Exception as e:
            return _functions.setModuleError(
                payload=e,
                error='Error login user, try it later...',
                status=500).flaskResp()
示例#12
0
def displayInnit():
    username = input('Type the user with whom to start the chat: ')
    r = _serviceChat.innit(username)
    if _functions.resultError(r):
        return r
    _functions.setModuleSuccess(payload=r.body['msg'])
示例#13
0
def displayList():
    r = _serviceChat.list()
    if _functions.resultError(r):
        return r
    _functions.setModuleSuccess(payload=r.body)
    return _pageLogged.menu()