Skip to content

Commit

Permalink
Added a sigonout view and made some mods to the wsgi script
Browse files Browse the repository at this point in the history
  • Loading branch information
glenbot committed Jul 30, 2011
1 parent f31395d commit 0764fea
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions apps/codrspace/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
url(r'^signin/$', 'signin_start', name="signin_start"),
url(r'^signin_callback/$', 'signin_callback',
name="signin_callback"),
url(r'^signout/$', 'signout', name="signout"),
)
17 changes: 17 additions & 0 deletions apps/codrspace/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from django.shortcuts import render, redirect, get_object_or_404
from django.utils import simplejson
from django.core.urlresolvers import reverse

from settings import GITHUB_CLIENT_ID
from codrspace.models import CodrSpace
from codrspace.forms import CodrForm
Expand Down Expand Up @@ -44,6 +46,10 @@ def signin_start(request, slug=None, template_name="signin.html"):
return redirect('https://github.com/login/oauth/authorize?client_id=%s' % (
GITHUB_CLIENT_ID))

def signout(request):
if request.user.is_authenticate():
request.user.logout()
return redirect(reverse('signout'))

def _validate_github_response(resp):
"""Raise exception if given response has error"""
Expand Down Expand Up @@ -75,4 +81,15 @@ def signin_callback(request, slug=None, template_name="base.html"):
_validate_github_response(resp)
user = simplejson.loads(resp.content)

try:
user = user.objects.get(username=user['login'])
except:
pass # create user here

try:
profile = user.get_profile()
except:
pass # create profile here


return redirect('http://www.codrspace.com/%s' % (user['login']))
4 changes: 2 additions & 2 deletions deploy/deploy.wsgi
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ from site import addsitedir

sys.path.insert(0, abspath(join(dirname(__file__), "../../")))

from django.conf import settings

os.environ["DJANGO_SETTINGS_MODULE"] = "dash.settings"

from django.conf import settings

sys.path.insert(0, join(settings.PROJECT_ROOT))

from django.core.handlers.wsgi import WSGIHandler
Expand Down

0 comments on commit 0764fea

Please sign in to comment.