Files
Chad Whitacre 31035e3e81 Wire up Bitbucket oauth; #149
I tested connecting a Bitbucket account to an existing account in both
merge and non-merge cases. I need to look at signing in using Bitbucket
in the first place, making sure we have links in all the right places.
2013-03-22 15:08:38 -04:00

276 lines
11 KiB
HTML

"""This is called as an internal redirect from /on/blah/associate
"""
import uuid
from aspen import Response
from gittip.models import Participant
website.connect_tokens = {}
# ===== ^L
if not getattr(request, 'internally_redirected_from', None):
raise Response(404)
if user.ANON:
raise Response(404)
# Compute and store a connect_token.
# ==================================
# This is a protection against unauthorized users taking over accounts.
connect_token = uuid.uuid4().hex
connect_key = (user.id, account.platform, account.user_id)
website.connect_tokens[connect_key] = connect_token
other = Participant.query.get(account.participant_id)
user_github_account, user_twitter_account, user_bitbucket_account = \
user.get_accounts_elsewhere()
other_github_account, other_twitter_account, other_bitbucket_account = \
other.get_accounts_elsewhere()
user_giving = user.get_dollars_giving()
user_receiving = user.get_dollars_receiving()
other_giving = other.get_dollars_giving()
other_receiving = other.get_dollars_receiving()
combined_giving = user_giving + other_giving
combined_receiving = user_receiving + other_receiving
fmt = lambda x: '$' + str(int(round(x))) if x > 0 else '-'
if account.platform == 'twitter':
username = user_info['screen_name']
elif account.platform == 'github':
username = user_info['login']
elif account.platform == 'bitbucket':
username = user_info['username']
title = "Please Confirm"
# ===== ^L
{% extends "templates/base.html" %}
{% block box %}
<div class="on-confirm">
<div><img class="platform-icon" src="/assets/icons/{{ account.platform }}.12.png"
/> <span class="highlight">{{ username }}</span> is connected<br />to
<b>{{ other.id }}</b> on Gittip.<br />Reconnect it?</div>
<h2>Now</h2>
<table class="scenario">
<tr>
<td></td>
<td>
<div class="participant">
<div class="participant-padding">
<b>{{ user.id }}</b><br />
<table>
<tr>
<th><i>Gives</i></th>
<td>{{ fmt(user_giving) }}</td>
</tr>
<tr>
<th><i>Receives</i></th>
<td>{{ fmt(user_receiving) }}</td>
</tr>
</table>
<br />
{% if user_twitter_account is not None %}
<img src="/assets/icons/twitter.12.png" />
{{ user_twitter_account.user_info['screen_name'] }}<br />
{% end %}
{% if user_github_account is not None %}
<img src="/assets/icons/github.12.png" />
{{ user_github_account.user_info['login'] }}<br />
{% end %}
{% if user_bitbucket_account is not None %}
<img src="/assets/icons/bitbucket.12.png" />
{{ user_bitbucket_account.user_info['username'] }}<br />
{% end %}
</div>
</div>
</td>
<td>
<div class="participant other">
<div class="participant-padding">
<b>{{ other.id }}</b><br />
<table>
<tr>
<th><i>Gives</i></th>
<td>{{ fmt(other_giving) }}</td>
</tr>
<tr>
<th><i>Receives</i></th>
<td>{{ fmt(other_receiving) }}</td>
</tr>
</table>
<br />
{% if other_twitter_account is not None %}
<img src="/assets/icons/twitter.12.png" />
{% if account.platform == 'twitter' %}<span class="highlight">{% end %}
{{ other_twitter_account.user_info['screen_name'] }}<br />
{% if account.platform == 'twitter' %}</span>{% end %}
{% end %}
{% if other_github_account is not None %}
<img src="/assets/icons/github.12.png" />
{% if account.platform == 'github' %}<span class="highlight">{% end %}
{{ other_github_account.user_info['login'] }}<br />
{% if account.platform == 'github' %}</span>{% end %}
{% end %}
{% if other_bitbucket_account is not None %}
<img src="/assets/icons/bitbucket.12.png" />
{% if account.platform == 'bitbucket' %}<span class="highlight">{% end %}
{{ other_bitbucket_account.user_info['username'] }}<br />
{% if account.platform == 'bitbucket' %}</span>{% end %}
{% end %}
</div>
</div>
</td>
</tr>
</table>
<h2>After Reconnect</h2>
<table class="scenario">
<tr>
<td class="abandoned">
{% if account.platform == 'twitter' and user_twitter_account is not None %}
<span class="account-elsewhere">
<img src="/assets/icons/twitter.12.png" />
{{ user_twitter_account.user_info['screen_name'] }}<br />
</span>
{% end %}
{% if account.platform == 'github' and user_github_account is not None %}
<span class="account-elsewhere">
<img src="/assets/icons/github.12.png" />
{{ user_github_account.user_info['login'] }}<br />
</span>
{% end %}
{% if account.platform == 'bitbucket' and user_bitbucket_account is not None %}
<span class="account-elsewhere">
<img src="/assets/icons/bitbucket.12.png" />
{{ user_bitbucket_account.user_info['username'] }}<br />
</span>
{% end %}
</td>
<td>
<div class="participant">
<div class="participant-padding">
<b>{{ user.id }}</b><br />
<table>
<tr>
{% if obstacles.this_is_others_last_account_elsewhere %}
<th><i>Gives</i></th>
<td>{{ fmt(combined_giving) }}</td>
</tr>
<tr>
<th><i>Receives</i></th>
<td>{{ fmt(combined_receiving ) }}</td>
{% else %}
<th><i>Gives</i></th>
<td>{{ fmt(user_giving) }}</td>
</tr>
<tr>
<th><i>Receives</i></th>
<td>{{ fmt(user_receiving ) }}</td>
{% end %}
</tr>
</table>
<br />
{% if user_twitter_account is not None %}
<span class="account-elsewhere">
<img src="/assets/icons/twitter.12.png" />
{{ user_twitter_account.user_info['screen_name'] }}<br />
</span>
{% end %}
{% if user_github_account is not None %}
<span class="account-elsewhere">
<img src="/assets/icons/github.12.png" />
{{ user_github_account.user_info['login'] }}<br />
</span>
{% end %}
{% if user_bitbucket_account is not None %}
<span class="account-elsewhere">
<img src="/assets/icons/bitbucket.12.png" />
{{ user_bitbucket_account.user_info['username'] }}<br />
</span>
{% end %}
<span class="account-elsewhere">
<img src="/assets/icons/{{ account.platform }}.12.png" />
<span class="highlight">{{ username }}</span>
</span>
</div>
</div>
</td>
{% if obstacles.this_is_others_last_account_elsewhere %}
<td>
<div class="participant other nix">
<div class="participant-padding">
<img id="nix" src="/assets/nix.png" />
<b>{{ other.id }}</b><br />
<br />
</div>
</div>
</td>
{% else %}
<td>
<div class="participant other">
<div class="participant-padding">
<b>{{ other.id }}</b><br />
<table>
<tr>
<th><i>Gives</i></th>
<td>{{ fmt(other_giving) }}</td>
</tr>
<tr>
<th><i>Receives</i></th>
<td>{{ fmt(other_receiving ) }}</td>
</tr>
</table>
<br />
{% if other_github_account is not None and account.platform != 'github' %}
<span class="account-elsewhere">
<img src="/assets/icons/github.12.png" />
{{ other_github_account.user_info['login'] }}<br />
</span>
{% end %}
{% if other_twitter_account is not None and account.platform != 'twitter' %}
<span class="account-elsewhere">
<img src="/assets/icons/twitter.12.png" />
{{ other_twitter_account.user_info['screen_name'] }}<br />
</span>
{% end %}
</div>
</div>
</td>
{% end %}
</tr>
</table>
<div class="nav level-2">
<h2>Reconnect?</h2>
<form action="/on/take-over.html" method="POST">
<input type="hidden" name="platform" value="{{ account.platform }}" />
<input type="hidden" name="user_id" value="{{ account.user_id }}" />
<input type="hidden" name="csrf_token" value="{{ cookie['csrf_token'].value }}" />
<input type="hidden" name="connect_token" value="{{ connect_token }}" />
<button class="selected larger">Yes</button>
<a href="/about/me.html"><button>No</button></a>
</form>
</div>
</div>
{% end %}