示例#1
0
 def get_logged_in_user(new_request):
     # get the auth token
     auth_token = new_request.headers.get('Authorization')
     if auth_token:
         resp = User.decode_auth_token(auth_token)
         if not isinstance(resp, str):
             user = User.query.filter_by(id=resp).first()
             response_object = {
                 'status': 'success',
                 'data': {
                     'user_id': user.id,
                     'email': user.email,
                     'admin': user.admin,
                     'registered_on': str(user.registered_on)
                 }
             }
             return response_object, 200
         response_object = {'status': 'fail', 'message': resp}
         return response_object, 401
     else:
         response_object = {
             'status': 'fail',
             'message': 'Provide a valid auth token.'
         }
         return response_object, 401
 def test_decode_auth_token(self):
     user = User(email='*****@*****.**',
                 password='******',
                 registered_on=datetime.datetime.utcnow())
     db.session.add(user)
     db.session.commit()
     auth_token = User.encode_auth_token(user.id)
     self.assertTrue(
         User.decode_auth_token(auth_token.decode('utf-8')) == user.id)
示例#3
0
    def test_decode_auth_token(self):
        user = User(email='*****@*****.**',
                    last_name='Arthur',
                    name='Oliver',
                    password='******',
                    registered_on=datetime.datetime.utcnow())

        db.session.add(user)
        db.session.commit()
        auth_token = user.encode_auth_token(user.id)
        self.assertTrue(isinstance(auth_token, bytes))
        self.assertTrue(
            User.decode_auth_token(auth_token.decode("utf-8")) == 1)
    def logout_user(data):
        if data:
            auth_token = data.split(" ")[1]
        else:
            auth_token = ''

        if auth_token:
            resp = User.decode_auth_token(auth_token)
            if not isinstance(resp, str):
                return save_token(token=auth_token)
            else:
                response_object = {'status': 'error', 'message': resp}
                return response_object, 401
        else:
            response_object = {
                'status': 'error',
                'message': 'Provide a valid auth token.'
            }
            return response_object, 403
 def logout_user(data):
     if data:
         auth_token = data.split(" ")[1]
     else:
         auth_token = ""
     if auth_token:
         resp = User.decode_auth_token(auth_token)
         if not isinstance(resp, str):
             # mark the token as blacklisted
             # return save_token(token=auth_token)
             pass
         else:
             response_object = {"status": "fail", "message": resp}
             return response_object, 401
     else:
         response_object = {
             "status": "fail",
             "message": "Provide a valid auth token.",
         }
         return response_object, 403
示例#6
0
 def logout_user(data):
     if data:
         auth_token = data.split(" ")[1]
     else:
         auth_token = ''
     if auth_token:
         resp = User.decode_auth_token(auth_token)
         if not isinstance(resp, str):
             # mark the token as blacklisted
             # return save_token(token=auth_token)
             pass
         else:
             response_object = {'status': 'fail', 'message': resp}
             return response_object, 401
     else:
         response_object = {
             'status': 'fail',
             'message': 'Provide a valid auth token.'
         }
         return response_object, 403
示例#7
0
 def logout_user(data):
     if data:
         auth_token = data.split(' ')[1]
     else:
         auth_token = ''
     if auth_token:
         resp = User.decode_auth_token(auth_token)
         if not isinstance(resp, str):
             return save_token(token=auth_token)
         else:
             res = {
                 'status': 'fail',
                 'message': resp
             }
             return res, 401
     else:
         res = {
             'status': 'fail',
             'message': 'Provide a valid auth token'
         }
         return res, 403