Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
List accounts (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed Sep 13, 2012
1 parent a9f40c8 commit e1dcd8d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 57 deletions.
43 changes: 0 additions & 43 deletions gittip/networks/twitter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import requests
from aspen import json, log, Response
from gittip import db, networks


Expand All @@ -11,47 +9,6 @@ def upsert(user_info):
)


def oauth_dance(website, qs):
"""Given a querystring, return a dict of user_info.
The querystring should be the querystring that we get from Twitter when
we send the user to the return value of oauth_url above.
See also:
http://developer.twitter.com/v3/oauth/
"""

log("Doing an OAuth dance with Twitter.")

if 'denied' in qs:
raise Response(500, str(qs['denied']))

data = { 'code': qs['code'].encode('US-ASCII')
, 'client_id': website.twitter_customer_key
, 'client_secret': website.twitter_customer_secret
}
r = requests.post("https://api.twitter.com/oauth/access_token", data=data)
assert r.status_code == 200, (r.status_code, r.text)

back = dict([pair.split('=') for pair in r.text.split('&')]) # XXX
if 'error' in back:
raise Response(400, back['error'].encode('utf-8'))
assert back.get('token_type', '') == 'bearer', back
access_token = back['access_token']

r = requests.get( "https://api.twitter.com/user"
, headers={'Authorization': 'token %s' % access_token}
)
assert r.status_code == 200, (r.status_code, r.text)
user_info = json.loads(r.text)
log("Done with OAuth dance with Twitter for %s (%s)."
% (user_info['login'], user_info['id']))

return user_info


def resolve(user_id):
"""Given str, return a participant_id.
"""
Expand Down
2 changes: 1 addition & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h1>
alt="Gittip - Personal Funding" /></a>
</h1>
{% if user.ANON %}
<div id="you-are">Sign in using <a
<div id="you-are">Sign in using <a href="/on/twitter/redirect">Twitter</a> or <a
href="{{ github.oauth_url(website, u'opt-in') }}">GitHub</a>.</div>
{% else %}
<div id="you-are">
Expand Down
2 changes: 1 addition & 1 deletion templates/participant.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</div>

{% if can_tip and user.ANON %}
<h2>Sign in using
<h2>Sign in using <a href="/on/twitter/redirect">Twitter</a> or
<a href="{{ github.oauth_url(website, u'opt-in', username) }}">
GitHub</a> to tip {{ username }}.</h2>
{% elif can_tip %}
Expand Down
36 changes: 24 additions & 12 deletions www/%participant_id/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,9 @@

SELECT = """

SELECT p.*
, s.network
, s.user_info
FROM participants p
JOIN social_network_users s
ON p.id = s.participant_id
WHERE p.id = %s
SELECT *
FROM participants
WHERE id = %s

"""
participant = db.fetchone(SELECT, (path['participant_id'],))
Expand All @@ -53,6 +49,13 @@
request.redirect(to)


ACCOUNTS = """
SELECT * FROM social_network_users WHERE participant_id=%s;
"""
accounts = db.fetchall(ACCOUNTS, (participant_id,))
assert accounts is not None


if not user.ANON:
if user.id == participant_id:
tips, total = get_tips_and_total(user.id)
Expand All @@ -61,7 +64,6 @@
else:
my_tip = get_tip(user.id, participant['id'])

github_user_info = participant['user_info']
can_tip = True
backed_amount = get_backed_amount(participant['id'])
tip_or_pledge = "tip"
Expand Down Expand Up @@ -565,13 +567,23 @@ <h3>Funding Goal</h3>

<h3>Linked Accounts</h3>
<ul id="accounts">
{% for account in accounts %}
<li>
<img src="{{ github_user_info.get('avatar_url', '/assets/%s/no-avatar.png' % __version__) }}" />
{{ github_user_info.get('login') }} {% if github_user_info.get('name') %}({{ github_user_info.get('name') }}){% end %}<br />
<a href="{{ github_user_info.get('html_url', '') }}">
{{ github_user_info.get('html_url', '') }}
{% if account['network'] == 'github' %}
<img src="{{ account['user_info'].get('avatar_url', '/assets/%s/no-avatar.png' % __version__) }}" />
{{ account['user_info'].get('login') }} {% if account['user_info'].get('name') %}({{ account['user_info'].get('name') }}){% end %}<br />
<a href="{{ account['user_info'].get('html_url', '') }}">
{{ account['user_info'].get('html_url', '') }}
</a>
{% elif account['network'] == 'twitter' %}
<img src="{{ account['user_info'].get('profile_image_url_https', '/assets/%s/no-avatar.png' % __version__) }}" />
{{ account['user_info'].get('screen_name') }} {% if account['user_info'].get('name') %}({{ account['user_info'].get('name') }}){% end %}<br />
<a href="{{ account['user_info'].get('html_url', '') }}">
{{ account['user_info'].get('html_url', '') }}
</a>
{% end %}
</li>
{% end %}
</ul>

{% if user.ADMIN %}
Expand Down
1 change: 1 addition & 0 deletions www/on/twitter/associate
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ if screen_name is None:
log(u"We got a user_info from Twitter with no screen_name [%s, %s]"
% (action, then))
raise Response(400)
user_info['html_url'] = "https://twitter.com/" + screen_name

# Do something.
log(u"%s wants to %s" % (screen_name, action))
Expand Down

0 comments on commit e1dcd8d

Please sign in to comment.