def test_getting_logged_in_user(self):
        """Test for retriving logged in user"""
        with self.client:
            # user registration
            user_response = register_user(self)
            # log in user
            login_response = login_user(self)
            data = json.loads(login_response.data.decode())
            self.assertTrue(data['Authorization'])

            # response request header
            # user logged in retrive
            print('---------------><----------------')
            print(request.headers.get('Authorization'))
            data, status = Auth.get_logged_in_user()
            print('data {}',data)
            print(status)
            user_details = Auth.get_logged_in_user(data)
            # user_data = json.loads(user_details)
            if user_details:
                print('////// ---- //////')
                print(type(user_details))
                print(user_details)
                print('////// ---- //////')
            else:
                print('////// ---- //////')
                print('something wrong')
                print('////// ---- //////')
Esempio n. 2
0
def edit_a_card_list(_id, data):
    card_list = get_a_card_list_by_id(_id)
    logged_user_id = Auth.get_logged_in_user_id(request)
    user = user_has_card_list(_id, logged_user_id)
    if not user:
        return {'status': 'fail', 'message': 'UNAUTHORIZED'}, 401
    print('user')
    print(user)

    if not card_list:
        response_object = {
            'status': 'fail',
            'message': 'Card not exists.',
        }
        return response_object, 400
    else:
        card_list_by_title = get_a_card_list_by_title(data['title'])
        if card_list_by_title:
            response_object = {
                'status': 'fail',
                'message': 'Card already exists.',
            }
            return response_object, 400
        else:
            card_list.title = data['title']

            _save_changes(card_list)
        return card_list.json(), 200
Esempio n. 3
0
    def decorated(*args, **kwargs):
        data, status = Auth.get_logged_in_user(request)

        if status != 200:
            return data, status

        return f(*args, **kwargs)
Esempio n. 4
0
    def wrapper_login_required(*args, **kwargs):
        data, status = Auth.get_logged_in_user(request)
        token = data.get('data')

        if not token:
            return data, status
        return func(*args, **kwargs)
Esempio n. 5
0
    def post(self):
        """Creates a new User """
        data = request.json
        is_admin = True if request.headers.get(
            'admin_secret_key') == 'maibhiadmin' else False

        return Auth.signup_user(data=data, is_admin=is_admin)
Esempio n. 6
0
    def post(self):
        # get the post data
        post_data = request.json
        try:
            feedback = Auth.login_user(data=post_data)
        except Exception as e:
            return 'an error occurred', 500

        if not isinstance(feedback, dict):
            user_data = get_a_user_by_email(post_data.get('email', None))
            response_data = {
                'email': user_data.email,
            }
            response_object = {
                'status': 'success',
                'message': 'Successfully logged in.',
                'body': response_data,
                'Authorization': feedback.decode()
            }
            return response_object, 200
        else:
            response_object = {
                'status': 'fail',
                'message': feedback.get('error', None),
            }
            return response_object, 401
Esempio n. 7
0
def delete_card_list(card_list):
    logged_user_id = Auth.get_logged_in_user_id(request)
    user = user_has_card_list(card_list.id, logged_user_id)
    if not user:
        return {'status': 'fail', 'message': 'UNAUTHORIZED'}, 401
    db.session.delete(card_list)
    db.session.commit()
    return {'status': 'success', 'message': 'Card list successfully deleted. '}, 200
Esempio n. 8
0
    def decorated(*args, **kwargs):

        data, status = Auth.get_logged_in_user(request)
        token = data.get('data')

        if not token:
            return data, status

        return f(*args, **kwargs)
Esempio n. 9
0
    def decorated(*args, **kwargs):
        feedback = Auth.get_logged_in_user(request)
        if not isinstance(feedback, User):
            return {
                'status': 'fail',
                'message': feedback.get('error', None)
            }, 401

        return f(*args, **kwargs)
Esempio n. 10
0
    def decorated(*args, **kwargs):
        data, status = Auth.get_logged_in_user(request)
        token = data.get('data')
        if not token:
            return data, status

        if not token.get('admin'):
            resp = {'status': 'fail', 'message': 'Admin token required'}
            return resp, 401

        return f(*args, **kwargs)
Esempio n. 11
0
def save_new_card(data):
    logged_user_id = Auth.get_logged_in_user_id(request)
    card_list = get_a_card_list_by_id(data['card_list_id'])
    if not card_list:
        return {'status': 'fail', 'message': 'card list does not exists'}, 400
    new_card = CardModel(title=data['title'],
                         description=data['description'],
                         user_id=logged_user_id,
                         card_list_id=data['card_list_id'])
    try:
        _save_changes(new_card)
        return new_card.json(), 201
    except:
        error_object = {'status': 'fail', 'message': 'Interval server error'}
        return error_object, 500
Esempio n. 12
0
    def decorated(*args, **kwargs):
        data, status = Auth.get_logged_in_user(request)
        token = data.get('data')
        print(token)
        if not token:
            return data, status

        admin = token.get('role')
        print(admin)
        if admin.lower() != 'admin':
            response_object = {
                'status': 'fail',
                'message': 'admin token required'
            }
            return response_object, 401
        return func(*args, **kwargs)
Esempio n. 13
0
    def decorated(*args, **kwargs):

        feedback = Auth.get_logged_in_user(request)

        if feedback.get('error', None):
            return {
                'status': 'fail',
                'message': feedback.get('error', None)
            }, 401

        verified = feedback.get('if_verified')
        if not verified:
            response_object = {
                'status': 'fail',
                'message': 'user not verified'
            }
            return response_object, 401

        return f(*args, **kwargs)
Esempio n. 14
0
def save_new_comment(data):
    logged_user_id = Auth.get_logged_in_user_id(request)
    card = get_a_card(data['card_id'])
    if not card:
        return {'status': 'fail', 'message': 'card  does not exists'}, 400
    new_comment = CommentModel(
        text=data['text'],
        parent_comment_id=data['parent_comment_id'],
        user_id=logged_user_id,
        card_id=data['card_id'],
        created_date=datetime.datetime.utcnow()
    )
    try:
        _save_changes(new_comment)
        return new_comment.json(), 201
    except:
        error_object = {
            'status': 'fail',
            'message': 'Interval server error'

        }
        return error_object, 500
Esempio n. 15
0
 def post(self):
     """Ingresar al sistema"""
     data = request.json
     return Auth.login_usuario(data)
Esempio n. 16
0
 def post(self):
     """Verificar token valido"""
     auth_header = request.headers.get('Authorization')
     return Auth.obtener_usuario_logeado(data=auth_header)
Esempio n. 17
0
 def get(self):
     # get auth token
     auth_header = request.headers.get('Authorization')
     return Auth.logout_user(auth_token=auth_header)
Esempio n. 18
0
 def post(self):
     # get the post data
     post_data = request.json
     return Auth.login_user(data=post_data)
Esempio n. 19
0
 def post(self):
     # get auth token
     auth_header = request.headers.get('Authorization')
     return Auth.logout(data=auth_header)
Esempio n. 20
0
 def get(self):
     return Auth.get_tokens()
Esempio n. 21
0
 def post(self):
     return Auth.refresh()
Esempio n. 22
0
def check_ownership(user_id):
    logged_user_id = Auth.get_logged_in_user_id(request)
    if user_id == logged_user_id:
        return True
    return False
Esempio n. 23
0
 def get(self):
     """Salir del sistema"""
     auth_header = request.headers.get('Authorization')
     return Auth.logout_usuario(data=auth_header)