Miki Tebeka avatar Miki Tebeka committed 29160b3


Comments (0)

Files changed (2)

         <div class="header">
             The URL Shortener
+            <span class="right">
+                {{ login }}
+            </span>
         <form method="post">
             <label for="url">Url:</label><input name="url" /> 
             <input type="submit" value="Shorten">
         <div class="footer">
-            G'day folks
+            G'day {{ user }}
 An AppEngine Demo.
 from google.appengine.ext import webapp
+from google.appengine.api import users
 import jinja2
 class Home(webapp.RequestHandler):
     def get(self):
         template = get_template('index.html')
-        self.response.out.write(template.render())
+        env = {
+            'login' : self.login_html(),
+            'user' : users.get_current_user() or 'stranger'
+        }
+        self.response.out.write(template.render(**env))
     def post(self):
         url = self.request.get('url')
         self.response.out.write('You asked to shorten: {0}'.format(url))
+    def login_html(self):
+        '''Login/Logout HTML sinppet.'''
+        user = users.get_current_user()
+        if user:
+            fn, txt = users.create_logout_url, 'Logout'
+        else:
+            fn, txt = users.create_login_url, 'Login'
+        return '<a href="{0}">{1}</a>'.format(fn(self.request.uri), txt)
 app = webapp.WSGIApplication([
     ('/', Home),
 ], debug=True)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.