Esempio n. 1
0
def signin_with_linkedin():
    """ LinkedIn Signin """
    request_data = request.get_json()
    if not request_data or not "email" in request_data:
        return error_response(400, 'Invalid data supplied')

    try:
        user = get_user_by_public_url(request_data["email"])
        if not user:
            return error_response(401, 'Failed to sign in with LinkedIn')

        auth_token = encode_auth_token(user.public_id.hex)  # uuid to string
        if not auth_token:
            return error_response(500, 'Something went wrong!')

        return {
            'response': {
                'statusCode': 200,
                'statusText': 'OK'
            },
            'data': {
                'status': True,
                'message': 'Successfully logged in.',
                'token': auth_token
            }
        }
    except Exception as e:
        pass

    return error_response(500, 'Failed to login. Try again later.')
Esempio n. 2
0
def user_signup():
    """
    Register a normal user

    There will be no url field,
    so replace it with the email as a workaround(for the primary key)
    """
    request_data = request.get_json()
    if not request_data or not "name" in request_data or not "email" in request_data or not "password" in request_data or not "phone" in request_data or not "headline" in request_data or not "location" in request_data or not "skills" in request_data:
        return error_response(400, 'Invalid data supplied')

    try:
        user = get_current_user_by_url(request_data["email"])
        if user:
            return error_response(409, 'User already exists. Please Log in.')

        new_user = normalize_new_user_data(request_data)
        user_public_id = save_user(new_user, True)
        current_user = get_current_user_by_id(user_public_id)
        current_user.set_password(request_data["password"])
        db.session.commit()

        task = chain(search_and_store_results.s(user_public_id),
                     scrape_search_result_profiles.s()).apply_async(
                         countdown=5)  # ToDo: save to a particular queue

        auth_token = encode_auth_token(
            current_user.public_id.hex)  # uuid to string
        if not auth_token:
            return error_response(500, 'Something went wrong!')

        return {
            'response': {
                'statusCode': 201,
                'statusText': 'OK'
            },
            'data': {
                'status': True,
                'message': 'Successfully registered.',
                'token': auth_token
            }
        }
    except SQLAlchemyError as e:
        db.session.rollback()
    except Exception as e:
        pass

    return error_response(500, 'Failed to signup. Try again later.')
Esempio n. 3
0
def signup_with_linkedin():
    request_data = request.get_json()
    if not request_data or not "name" in request_data or not "email" in request_data or not "headline" in request_data or not "skills" in request_data or not "image" in request_data:
        return error_response(400, 'Invalid data supplied')

    try:
        user = get_user_by_public_url(request_data["email"])
        if user:
            return error_response(409, 'User already exists. Please Log in.')

        new_user = normalize_new_user_data(request_data)
        user_public_id = save_user(new_user, True)
        db.session.commit()

        task = chain(search_and_store_results.s(user_public_id),
                     scrape_search_result_profiles.s()).apply_async(
                         countdown=5)  # ToDo: save to a particular queue

        current_user = get_user_by_public_id(user_public_id)
        auth_token = encode_auth_token(
            current_user.public_id.hex)  # uuid to string
        if not auth_token:
            return error_response(500, 'Something went wrong!')

        return {
            'response': {
                'statusCode': 201,
                'statusText': 'OK'
            },
            'data': {
                'status': True,
                'message': 'Successfully registered.',
                'token': auth_token
            }
        }
    except Exception as e:
        pass

    return error_response(500, 'Failed to signup. Try again later.')