예제 #1
0
파일: app.py 프로젝트: unkitkr/Interq
def linkedin_logged_in(blueprint, token):
    account_info = linkedin.get('me')
    if account_info.ok:
        account_info_json = account_info.json()
        linkedin_id = account_info_json['id']
        name = account_info_json["localizedFirstName"] + \
            " " + account_info_json["localizedLastName"]
        user_exist = Users.query.filter_by(linkedinid=linkedin_id).first()
        email = linkedin.get(
            'https://api.linkedin.com/v2/clientAwareMemberHandles?q=members&projection=(elements*(primary,type,handle~))')
        email = email.json()
        actual_email = email['elements'][0]['handle~']['emailAddress']
        if not user_exist:
            new_user = Users(linkedinid=linkedin_id,
                             email=actual_email, name=name)
            try:
                db.session.add(new_user)
                db.session.commit()
                login_user(new_user)
            except Exception as e:
                db.session.rollback()
                print(e)
                return jsonify({
                    'Database Error': 'Internal data base error occured. Please try again later.'
                })
        else:
            login_user(user_exist)
예제 #2
0
    def inner(*args, **kwargs):
        if not linkedin.authorized:
            return redirect(url_for("routes.login"))

        # ensure the user exists in the db.
        if 'user_id' not in session:
            try:
                email = linkedin.get(
                    'emailAddress?q=members&projection=(elements*(handle~))')
                email_json = email.json()

                user_email = None
                user_id = None

                if email_json != None:
                    user_email = email_json['elements'][0]['handle~'][
                        'emailAddress']
                    user_id = user_repository.get_user_id(user_email)

                if user_id is None:
                    user = linkedin.get('me')
                    user_json = user.json()

                    if user_json != None:
                        user_firstname_localized = user_json['firstName']
                        user_lastname_localized = user_json['lastName']

                        user_firstname = preferred_locale_value(
                            user_firstname_localized)
                        user_lastname = preferred_locale_value(
                            user_lastname_localized)

                        # add a user to the email
                        user = user_repository.add_user(
                            user_firstname, user_lastname, user_email)
                        user_id = user.user_id

                if user_id != None:
                    session['user_id'] = user_id

            except Exception as e:
                logging.error(
                    "Couldn't parse user or email object: {}".format(e))

        return func(*args, **kwargs)
예제 #3
0
def linkedin_login():
    if not linkedin.authorized:
        return redirect(url_for('linkedin.login'))

    profile_info = linkedin.get('me')
    email_info = linkedin.get(
        'emailAddress?q=members&projection=(elements*(handle~))')

    if profile_info.ok and email_info.ok:
        email_json = email_info.json()
        profile_json = profile_info.json()
        user = {}
        user['email'] = email_json['elements'][0]['handle~']['emailAddress']
        user['firstName'] = profile_json['firstName']['localized']['en_US']
        user['lastName'] = profile_json['lastName']['localized']['en_US']

        return third_party_user_handler(user['email'], user['firstName'],
                                        user['lastName'], 'linkedin')
예제 #4
0
def index():
    if not linkedin.authorized:
        return redirect(url_for("linkedin.login"))
    resp = linkedin.get("me")
    assert resp.ok
    data = resp.json()
    name = "{first} {last}".format(
        first=preferred_locale_value(data["firstName"]),
        last=preferred_locale_value(data["lastName"]),
    )
    return "You are {name} on LinkedIn".format(name=name)
예제 #5
0
파일: app.py 프로젝트: legend1998/FlaskAPI
def Linkedin():
    if not linkedin.authorized:
        return redirect(url_for("linkedin.login"))
    resp = linkedin.get("me")
    data=resp.json()
    name="{first} {last}".format(
        first=getname(data["firstName"]),
        last=getname(data["lastName"])
    )
    flash('Logged in successfully','success')
    return redirect(url_for('index'))
예제 #6
0
def test_context_local(make_app):
    responses.add(responses.GET, "https://google.com")

    # set up two apps with two different set of auth tokens
    app1 = make_app(
        "foo1",
        "bar1",
        redirect_to="url1",
        storage=MemoryStorage({"access_token": "app1"}),
    )
    app2 = make_app(
        "foo2",
        "bar2",
        redirect_to="url2",
        storage=MemoryStorage({"access_token": "app2"}),
    )

    # outside of a request context, referencing functions on the `linkedin` object
    # will raise an exception
    with pytest.raises(RuntimeError):
        linkedin.get("https://google.com")

    # inside of a request context, `linkedin` should be a proxy to the correct
    # blueprint session
    with app1.test_request_context("/"):
        app1.preprocess_request()
        linkedin.get("https://google.com")
        request = responses.calls[0].request
        assert request.headers["Authorization"] == "Bearer app1"

    with app2.test_request_context("/"):
        app2.preprocess_request()
        linkedin.get("https://google.com")
        request = responses.calls[1].request
        assert request.headers["Authorization"] == "Bearer app2"
예제 #7
0
def test_context_local(make_app):
    responses.add(responses.GET, "https://google.com")

    # set up two apps with two different set of auth tokens
    app1 = make_app(
        "foo1",
        "bar1",
        redirect_to="url1",
        storage=MemoryStorage({"access_token": "app1"}),
    )
    app2 = make_app(
        "foo2",
        "bar2",
        redirect_to="url2",
        storage=MemoryStorage({"access_token": "app2"}),
    )

    # outside of a request context, referencing functions on the `linkedin` object
    # will raise an exception
    with pytest.raises(RuntimeError):
        linkedin.get("https://google.com")

    # inside of a request context, `linkedin` should be a proxy to the correct
    # blueprint session
    with app1.test_request_context("/"):
        app1.preprocess_request()
        linkedin.get("https://google.com")
        request = responses.calls[0].request
        assert request.headers["Authorization"] == "Bearer app1"

    with app2.test_request_context("/"):
        app2.preprocess_request()
        linkedin.get("https://google.com")
        request = responses.calls[1].request
        assert request.headers["Authorization"] == "Bearer app2"
예제 #8
0
파일: app.py 프로젝트: unkitkr/Interq
def dashboard():
    account_info = linkedin.get('me')
    session['initial_review_request'] = 0
    if account_info.ok:
        pic_actual = ""
        session["profile_picture"] = ""
        account_info_json = account_info.json()
        name = account_info_json["localizedFirstName"] + \
            " " + account_info_json["localizedLastName"]
        profile_picture = linkedin.get(
            'https://api.linkedin.com/v2/me?projection=(id,profilePicture(displayImage~digitalmediaAsset:playableStreams))')
        profile_picture = profile_picture.json()
        if "profilePicture" in profile_picture:
            pic_actual = profile_picture['profilePicture']['displayImage~']['elements'][3]['identifiers'][0]['identifier']
            session["profile_picture"] = pic_actual
        reviews_written = UserExperience.query.filter_by(
            owner=current_user.uid).all()
        all_companies = Companies.query.all()
        company_review_data = []
        for company in all_companies:
            number = len(UserExperience.query.filter_by(
                company=company.uid).all())
            company_name = company.name
            company_uid = company.uid
            company_data = (company_name, company_uid, number)
            company_review_data.append(company_data)

        payload = {
            'name': name,
            'email': current_user.email,
            'profile_picture': pic_actual,
            'reviews_written': reviews_written,
            'all_companies': company_review_data,
        }
        if 'message' in request.args:
            return render_template('dashboard.html', message=request.args['message'], payload=payload)
        return render_template('dashboard.html', payload=payload)
    else:
        return redirect('/')