Created
March 29, 2010 00:57
-
-
Save sgammon/347202 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
application: judes-login-test | |
runtime: python | |
version: 1 | |
api_version: 1 | |
handlers: | |
- url: /.* | |
script: main.py | |
login: required |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from google.appengine.ext import db, webapp | |
from google.appengine.api import users | |
## User profile record | |
class Profile(db.Model): | |
lastname = db.StringProperty() | |
firstname = db.StringProperty() | |
favorite_color = db.StringProperty() | |
user_account = db.UserProperty() | |
class RegistrationPage(webapp.RequestHandler): | |
## if accessed via GET, show registration form | |
def get(self): | |
## check if there is already a user profile. if there is, greet user. else, print registration form | |
p = Profile.get_by_key_name(users.get_current_user().email()) | |
if p is not None: | |
self.response.out.write("Welcome back, "+p.firstname+" "+p.lastname+"!") | |
else: | |
self.response.out.write("<html><body><p>Registration form</p><form action='/' method='post'><p>firstname: <input name='firstname' /></p><p>lastname: <input name='lastname' /></p><p>favorite_color: <input name='favorite_color' /></p><input type='submit' /></form></body></html>") | |
## if accessed via POST, commit record | |
def post(self): | |
## Get the currently logged in user | |
current_user = users.get_current_user() | |
## Get the posted variables | |
f_firstname = self.request.get('firstname') | |
f_lastname = self.request.get('lastname') | |
f_favorite_color = self.request.get('favorite_color') | |
## Create and commit the user profile record | |
p = Profile(key_name=current_user.email(), | |
firstname=f_firstname, | |
lastname=f_lastname, | |
favorite_color=f_favorite_color | |
user_account=current_user) | |
p.put() | |
## Redirect back to root | |
self.redirect("/") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment