Permalink
Browse files

More OpenID login work.

  • Loading branch information...
1 parent 06c1c13 commit 04ef8335c5071d072fbeca9a71f592f55b9223ea @bradfitz committed Mar 14, 2010
Showing with 31 additions and 7 deletions.
  1. +18 −6 consumer.py
  2. +12 −0 main.py
  3. +1 −1 templates/base.html
View
@@ -58,11 +58,17 @@
from openid.extensions import pape, sreg
import fetcher
import store
+import string
+import random
# Set to True if stack traces should be shown in the browser, etc.
_DEBUG = False
+def GenKeyName(length=8, chars=string.letters + string.digits):
+ return ''.join([random.choice(chars) for i in xrange(length)])
+
+
class Session(db.Expando):
"""An in-progress OpenID login."""
claimed_id = db.StringProperty()
@@ -366,12 +372,18 @@ def get(self):
logging.debug('Login status %s for claimed_id %s' %
(response.status, self.session.claimed_id))
- if self.session.store_and_display:
- login = Login(status=response.status,
- claimed_id=self.session.claimed_id,
- server_url=self.session.server_url,
- session=self.session.key())
- login.put()
+ if response.status != 'success':
+ self.render(locals())
+ return
+
+ session_id = GenKeyName(length=16)
+
+ login = Login(key_name=session_id,
+ status=response.status,
+ claimed_id=self.session.claimed_id,
+ server_url=self.session.server_url,
+ session=self.session.key())
+ login.put()
self.render(locals())
View
12 main.py
@@ -26,6 +26,18 @@
import models
+
+
+
+def GetCurrentUser(request):
+ """Returns a User entity (OpenID or Google) or None."""
+ user = users.get_current_user()
+ if user:
+ return user
+ session_id = self.request.cookies.get('session', '')
+ if not session_id:
+ return None
+
class MainHandler(webapp.RequestHandler):
View
@@ -27,7 +27,7 @@
<div id="body">
-<form method="post" action="/s/login">
+<form method="post" action="/s/startopenid">
Enter your OpenID URL:
<table><tr><td>

0 comments on commit 04ef833

Please sign in to comment.