This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 309
/
Copy pathredirect.spt
90 lines (74 loc) · 3.54 KB
/
redirect.spt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"""Part of Bountysource account connection.
Redirect users to Bountysource. We get them again at ./associate.
"""
import re
from urllib import urlencode
from aspen import log, Response
from gittip.elsewhere import bountysource
[-----------------------------]
# You need to be logged in to link a Bountysource account.
if user.ANON:
raise Response(404)
# Build params which are passed to Bountysource for creating a linked account.
connect_params = {
'redirect_url': website.bountysource_callback,
'external_access_token': bountysource.create_access_token(user.participant),
'login': user.participant.username
}
# Collect extra params from accounts elsewhere.
# =============================================
# The following attributes will be added to connect_params from linked accounts
# if present: email, first_name, last_name, avatar_url. These are used to
# prefill the account creation screen on Bountysource.
for account in user.participant.get_accounts_elsewhere():
# Note: returns None for accounts that haven't been linked yet
if account is None:
continue
# from Github
if account.platform == 'github':
# split single name string into parts
name_parts = re.split('\s+', account.user_info.get('name', '').strip())
if not connect_params.get('login'):
connect_params['login'] = account.user_info.get('login')
if not connect_params.get('email'):
connect_params['email'] = account.user_info.get('email')
if not connect_params.get('avatar_url'):
connect_params['avatar_url'] = account.user_info.get('avatar_url')
if not connect_params.get('first_name'):
if len(name_parts) >= 1:
connect_params['first_name'] = name_parts[0]
if not connect_params.get('last_name'):
if len(name_parts) >= 2:
connect_params['last_name'] = name_parts[-1]
# from Twitter
if account.platform == 'twitter':
# split single name string into parts
name_parts = re.split('/s+', account.user_info.get('name').strip())
if not connect_params.get('login'):
connect_params['login'] = account.user_info.get('screen_name')
if not connect_params.get('avatar_url'):
connect_params['avatar_url'] = \
account.user_info.get('profile_image_url_https')
if not connect_params.get('first_name'):
if name_parts:
connect_params['first_name'] = name_parts[0]
if not connect_params.get('last_name'):
if len(name_parts) >= 2:
connect_params['last_name'] = name_parts[-1]
# from Bitbucket
if account.platform == 'bitbucket':
if not connect_params.get('login'):
connect_params['login'] = account.user_info.get('username')
if not connect_params.get('avatar_url'):
connect_params['avatar_url'] = account.user_info.get('avatar')
if not connect_params.get('first_name'):
connect_params['first_name'] = account.user_info.get('first_name')
if not connect_params.get('last_name'):
connect_params['last_name'] = account.user_info.get('last_name')
# build redirect URL to Bountysource from collected data
auth_url = "%s#auth/gittip/confirm?%s" % ( bountysource.www_host
, urlencode(connect_params)
)
log("Redirect to Bountysource for authorization: %s" % connect_params)
request.redirect(auth_url)
[-----------------------------] text/plain