Permalink
Browse files

Basic user profile pages & noting login times.

  • Loading branch information...
bradfitz committed Mar 20, 2010
1 parent 9cda690 commit bbd54bc6bd8839bcb47f8df4b21e02430055d6cb
Showing with 97 additions and 13 deletions.
  1. +1 −1 base.html
  2. +6 −0 consumer.py
  3. +1 −1 index.html
  4. +39 −4 main.py
  5. +11 −2 models.py
  6. +4 −4 project.html
  7. +1 −1 static/style.css
  8. +34 −0 user.html
View
@@ -10,7 +10,7 @@
<td align='right'>
{% if user %}
- <p><b>{{ user.display_name }}</b> | <a href="/s/logout">Log out</a></p>
+ <p><a href='{{ user.profile_page_url }}'><b>{{ user.display_name }}</b></a> | <a href="/s/logout">Log out</a></p>
{% else %}
<p><a href="/s/login">Log in</a></p>
{% endif %}
View
@@ -61,6 +61,8 @@
import string
import random
+import models
+
# Set to True if stack traces should be shown in the browser, etc.
_DEBUG = False
@@ -383,6 +385,10 @@ def get(self):
session=self.session.key())
login.put()
+ # update the login time
+ user = models.User(openid_user=login.claimed_id).GetOrCreateFromDatastore()
+ user.put()
+
self.response.headers.add_header('Set-Cookie',
'session=%s; path=/' % session_id)
View
@@ -3,7 +3,7 @@
{% block title %}Contributing{% endblock %}
{% block content %}
- <p style='color: red; font-weight: bold'>WORK IN PROGRESS. SITE NOT YET DONE. Follow along at <a href="http://github.com/bradfitz/contributing">http://github.com/bradfitz/contributing</a></p>
+ <div style='width: 35em; background: #ccc'><p style='color: red; font-weight: bold; text-align: center'>Site is new &amp; a work in progress. Want to <a href='/contributing'>help</a>?</a></div>
<p>This is <b>Contributing</b>, a community resource dedicated to
keeping up-to-date information on how to contribute to open
View
43 main.py
@@ -65,20 +65,33 @@ def get(self):
next_url = self.request.get("next")
if not re.match(r'^/[\w/]*$', next_url):
next_url = '/'
- #logging.info("next_url: %s", next_url)
user = GetCurrentUser(self.request)
- google_login_url = users.create_login_url(next_url)
+ google_login_url = users.create_login_url('/s/notelogin?next=' + next_url)
template_values = {
"user": user,
"google_login_url": google_login_url,
}
self.response.out.write(template.render("login.html", template_values))
+class NoteLoginHandler(webapp.RequestHandler):
+ """Update a just-logged-in user's last_login property and send them along."""
+
+ def get(self):
+ next_url = self.request.get("next")
+ if not re.match(r'^/[\w/]*$', next_url):
+ next_url = '/'
+ user = GetCurrentUser(self.request)
+ if user:
+ user = user.GetOrCreateFromDatastore()
+ user.put() # updates time
+ self.redirect(next_url)
+
+
class LogoutHandler(webapp.RequestHandler):
def get(self):
next_url = self.request.get("next")
- if re.match(r'^/[\w/]*$', next_url):
+ if not re.match(r'^/[\w/]*$', next_url):
next_url = '/'
user = GetCurrentUser(self.request)
if user:
@@ -87,6 +100,26 @@ def get(self):
self.redirect(next_url)
+class UserHandler(webapp.RequestHandler):
+
+ def get(self, user_key):
+ user = GetCurrentUser(self.request)
+ profile_user = models.User.get_by_key_name(user_key)
+ if not profile_user:
+ self.response.set_status(404)
+ return
+ can_edit = user and user.sha1_key == profile_user.sha1_key
+ edit_mode = can_edit and (self.request.get('mode') == "edit")
+ template_values = {
+ "user": user,
+ "profile_user": profile_user,
+ "edit_mode": edit_mode,
+ "can_edit": can_edit,
+ "user_key": user_key,
+ }
+ self.response.out.write(template.render("user.html", template_values))
+
+
class CreateHandler(webapp.RequestHandler):
def get(self):
@@ -132,7 +165,7 @@ def get(self, project_key):
project = models.Project.get_by_key_name(project_key)
if not project:
self.response.set_status(404)
- can_edit = user and user.sha1_key == project.owner.sha1_key
+ can_edit = user and project and user.sha1_key == project.owner.sha1_key
edit_mode = can_edit and (self.request.get('mode') == "edit")
template_values = {
"user": user,
@@ -174,7 +207,9 @@ def main():
('/s/login', LoginHandler),
('/s/logout', LogoutHandler),
('/s/editproject', ProjectEditHandler),
+ ('/s/notelogin', NoteLoginHandler),
('/s/.*', SiteHandler),
+ (r'/u/([a-f0-9]{6,})', UserHandler),
(r'/([a-z][a-z0-9\.\-]*[a-z0-9])/?', ProjectHandler),
],
debug=True)
View
@@ -18,6 +18,7 @@
from google.appengine.api import users
from google.appengine.ext import db
+import logging
import sha
SALT = 'Contributing!'
@@ -29,7 +30,11 @@ class User(db.Model):
openid_user = db.StringProperty(indexed=True, required=False)
url = db.StringProperty(indexed=False)
- last_login = db.DateProperty()
+ last_login = db.DateTimeProperty(auto_now=True)
+
+ @property
+ def last_login_short(self):
+ return str(self.last_login)[0:10]
@property
def display_name(self):
@@ -65,7 +70,7 @@ def LogOut(self, handler, next_url):
handler.redirect(users.create_logout_url(next_url))
return
handler.response.headers.add_header(
- 'Set-Cookie', 'session=')
+ 'Set-Cookie', 'session=; path=/')
handler.redirect(next_url)
def GetOrCreateFromDatastore(self):
@@ -94,6 +99,10 @@ def display_name(self):
return self.pretty_name
return self.name
+ @property
+ def last_edit_short(self):
+ return str(self.last_edit)[0:10]
+
class Contributor(db.Model):
"""A user-project tuple."""
View
@@ -38,7 +38,7 @@
</td>
</tr>
<tr>
- <td align=right>Code repository:</td>
+ <td align=right><nobr>Code repository:</nobr></td>
<td>
{% if edit_mode %}
<input name='code_repo' value="{{ project.code_repo|escape }}" size='40' />
@@ -65,12 +65,12 @@
</tr>
{% else %}
<tr valign='bottom'>
- <td align=right>Maintainer of this<br/>metadata page:</td>
+ <td align=right><nobr>Maintainer of this</nobr><br/><nobr>metadata page:</nobr></td>
<td><a href="{{ project.owner.profile_page_url|escape }}">{{ project.owner.public_name|escape }}</a></td>
</tr>
<tr valign='bottom'>
- <td align=right>Last modified time:</td>
- <td>{{ project.last_edit }} UTC</td>
+ <td align=right>Last modified:</td>
+ <td>{{ project.last_edit_short }}</td>
</tr>
{% endif %}
View
@@ -17,5 +17,5 @@ body {
#topbar a:visited {
text-decoration: none;
- color: #444;
+ color: #000;
}
View
@@ -0,0 +1,34 @@
+{% extends "base.html" %}
+{% block headtitle %}
+ User Profile
+{% endblock %}
+{% block title %}
+ User <em>{{ profile_user.public_name|escape }}</em>
+{% endblock %}
+{% block content %}
+
+{% if can_edit and not edit_mode %}
+[<a href="?mode=edit">edit</a>]
+{% endif %}
+
+<p><b>Last login to Contributing:</b> {{ profile_user.last_login_short }}</p>
+
+{% if edit_mode %}
+<form method='POST' action='/s/edituser'>
+</form>
+{% endif %}
+
+<pre>
+
+
+
+
+TODO(bradfitz):
+* list of projects users maintains metadata for
+* rel=me URL outbound?
+* contact URL?
+* public name? public email? really don't want to turn this
+ into a social networking site, though. but should be
+ a way to bug maintainers to update stuff.</pre>
+
+{% endblock %}

0 comments on commit bbd54bc

Please sign in to comment.