Skip to content

Commit

Permalink
Merge pull request #15 from betatim/direct-link
Browse files Browse the repository at this point in the history
Support for direct linking to a repo
  • Loading branch information
anaderi committed Oct 7, 2015
2 parents 8e7392b + 60837ba commit 417572d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
29 changes: 25 additions & 4 deletions everware/authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class WelcomeHandler(BaseHandler):
def _render(self, login_error=None, username=None):
return self.render_template('login.html',
next=url_escape(self.get_argument('next', default='')),
repo_url=url_escape(self.get_argument('repo_url', default='')),
username=username,
login_error=login_error,
)
Expand Down Expand Up @@ -76,12 +77,19 @@ def get(self):

redirect_uri = self.authenticator.oauth_callback_url or guess_uri
self.log.info('oauth redirect: %r', redirect_uri)


repo_url = self.get_argument('repo_url', '')

state = {'unique': 42}
if repo_url:
state['repo_url'] = repo_url

self.authorize_redirect(
redirect_uri=redirect_uri,
client_id=self.authenticator.client_id,
scope=[],
response_type='code')
response_type='code',
extra_params={'state': self.create_signed_value('state', repr(state))})


class GitHubLoginHandler(OAuthLoginHandler, GitHubMixin):
Expand All @@ -95,12 +103,25 @@ class BitbucketLoginHandler(OAuthLoginHandler, BitbucketMixin):
class GitHubOAuthHandler(BaseHandler):
@gen.coroutine
def get(self):
# TODO: Check if state argument needs to be checked
# Check state argument, should be there and contain a dict
# as created in OAuthLoginHandler
state = self.get_secure_cookie('state', self.get_argument('state', ''))
if state is None:
raise web.HTTPError(403)

state = eval(state)
self.log.debug('State dict: %s', state)
state.pop('unique')

username = yield self.authenticator.authenticate(self)
if username:
user = self.user_from_username(username)
self.set_login_cookie(user)
self.redirect(self.hub.server.base_url)
if 'repo_url' in state:
self.log.debug("Redirect with %s", state)
self.redirect(self.hub.server.base_url +'/home?'+urllib.parse.urlencode(state))
else:
self.redirect(self.hub.server.base_url)
else:
# todo: custom error page?
raise web.HTTPError(403)
Expand Down
1 change: 1 addition & 0 deletions everware/homehandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class HomeHandler(BaseHandler):
def get(self):
html = self.render_template('home.html',
user=self.get_current_user(),
repo_url=self.get_argument('repo_url', ''),
)
self.finish(html)

Expand Down
3 changes: 3 additions & 0 deletions share/static/html/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ <h1>everware</h1>
id="repo_input"
tabindex="1"
placeholder="URL of git repository"
{% if repo_url %}
value="{{repo_url}}"
{% endif %}
/>
</div>
<input
Expand Down
4 changes: 4 additions & 0 deletions share/static/html/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ <h1>everware</h1>
{{ custom_html }}
{% elif login_service %}
<div class="service-login">
{% if repo_url %}
<a class='btn btn-github btn-lg' href='oauth_login?repo_url={{repo_url}}'>
{% else %}
<a class='btn btn-github btn-lg' href='oauth_login'>
{% endif %}
Sign in with {{login_service}}
</a>
</div>
Expand Down

0 comments on commit 417572d

Please sign in to comment.