Exemple #1
0
def register():
    print 'DAFUK....'
    @async
    @copy_current_request_context
    def fetch_and_populate_current_user_from_linkedin_async(db):
        fetch_and_populate_current_user_from_linkedin(db)

    # TODO better error handling.. what's the way to do it?
    if 'user_id' in session:
        print 'User already exists and logged in...'
        return redirect(url_for('index'))
    user = get_current_linkedin_user()
    if user and user.is_registered:
        print 'User already exists and is registered...'
        return redirect(url_for('index'))
    if not get_linkedin_oauth_token():
        print 'User not logged in...'
        return redirect(url_for('index'))
    if not user:
        print 'creating hollow user with linkedin_id = ' + str(get_linkedin_id())
        user = User(get_linkedin_id())
        db.session.add(user)
        db.session.commit()

    log_event(session.get('user_id'), 'register', {'ip': request.remote_addr})
    fetch_and_populate_current_user_from_linkedin_async(db)
    print 'F*****G DONE'
    return render_template('loading.html', current_user=user)
Exemple #2
0
def index():
    if not get_linkedin_oauth_token():
        log_event(None, 'home', {'ip': request.remote_addr})
        return render_template('home.html')
    if 'user_id' not in session:
        return login_callback()
    return redirect(url_for('feed'))
Exemple #3
0
def feed(show_intro, filter):
    user = get_current_user()
    if not user:
        return redirect(url_for('index'))
    # get feed companies
    feed_companies_query = feed_companies_query_template.format(user.id)
    companies_results = db.engine.execute(feed_companies_query)
    # get feed friends
    feed_friends_query = feed_friends_query_template.format(user.id)
    friends_results = db.engine.execute(feed_friends_query)
    # populate dicts with resulting companies and friends
    companies = get_companies_and_friends_feed_info_from_query_results(companies_results, friends_results)
    # split into 4 vertical columns
    companies_vertical = prepare_companies_for_feed(companies, filter) 
    # pick ahri index
    ahri_column = random.randint(1, 4)
    ahri_row = random.randint(1, len(companies_vertical[0]) / 2 + 1)
    # count how many are still scraping
    feed_companies_pending_query = feed_companies_pending_query_template.format(user.id)
    pending_result = db.engine.execute(feed_companies_pending_query)
    for row in pending_result:
        pending_count = row[0]
    # fetch vetted companies
    exclude_inlist = ",".join([str(id) for id in companies])
    feed_vetted_companies_query = feed_vetted_companies_query_template.format(user.id, exclude_inlist)
    vetted_companies_results = db.engine.execute(feed_vetted_companies_query)
    vetted_companies = get_companies_and_friends_feed_info_from_query_results(vetted_companies_results, [])
    # split into 4 vertical columns
    vetted_companies_vertical = prepare_companies_for_feed(vetted_companies) 
    # log event
    log_event(user.id, 'feed', {'ip': request.remote_addr, 'companies_count': len(companies)})
    # print page
    return render_template('feed.html', companies_vertical=companies_vertical, vetted_companies_vertical=vetted_companies_vertical, pending_count=pending_count, current_user=user, show_intro=show_intro, ahri_column=ahri_column, ahri_row=ahri_row)
Exemple #4
0
def send_linkedin_message(friend_id):
    current_user = get_current_user()
    if not current_user:
        return 'Not logged in...' # TODO better error
    data = json.loads(request.data)
    subject =  data.get('subject')
    body = data.get('body')
    body += "\n\n-------------------------\nSent from StartupLinx\nwww.startuplinx.co\nConnecting Students with Startups"
    recipient = User.query.get(friend_id)
    if not recipient:
        return 'ERROR: Recipient not found' # TODO return real error
    message = json.dumps({
        "recipients": {
            "values": [
                {
                  "person": {
                    "_path": "/people/" + str(recipient.linkedin_id)
                   }
                }
            ]
        },
        "subject": subject,
        "body": body
    })
    print current_user.name.encode('utf8') + ' sending linkedin message to ' + recipient.name.encode('utf8') + ':'
    response = post_linkedin_message(message)
    print '...Sent! response data = ' + str(response.data)
     # TODO better error handling
    log_event(current_user.id, 'send_message', {
        'ip': request.remote_addr, 
        'recipient_id': recipient.id,
        'recipient_name': recipient.name,
        'subject': subject,
        'body': body,
        'linkedin_response': response.data
    })
    print 'Logged event'
    resp = json.dumps({'status': 'ok'})
    if 'errorCode' in response.data or 'error' in response.data:
        resp = json.dumps({'status': 'error'})
    print 'send message resp = ' + str(resp)
    return resp
Exemple #5
0
def profile(company_id):
    user = get_current_user()
    if not user: 
        return redirect(url_for('index'))
    # avoid SQL injections
    company_id = int(company_id)
    # get company
    profile_company_query = profile_company_query_template.format(company_id)
    company_result = db.engine.execute(profile_company_query).fetchone()
    # get friends
    if user.is_admin and session.get('admin_mode'):
        # if admin mode is on, show all employees
        profile_friends_query = profile_all_employees_query_template.format(company_id)
    else:
        # otherwise, just user's friends
        profile_friends_query = profile_friends_query_template.format(user.id, company_id)
    friends_results = db.engine.execute(profile_friends_query)
    # populate dict with resulting company and friends
    company = get_company_and_friends_profile_info_from_query_results(company_result, friends_results)
    if not company:
        return 'ERROR -- no company found'
    log_event(user.id, 'profile', {'ip': request.remote_addr, 'company_id': company['id'], 'company_name': company['name']})
    return render_template('profile.html', company=company, current_user=user)
Exemple #6
0
def logout():
    log_event(session.get('user_id'), 'logout', {'ip': request.remote_addr})
    session.pop('user_id', None)
    session.pop('admin_mode', None)
    linkedin_logout()
    return redirect(url_for('index'))
Exemple #7
0
def about():
    log_event(session.get('user_id'), 'about', {'ip': request.remote_addr})
    return render_template('about.html')