Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

Commit

Permalink
First stab at adding UUID to user profile
Browse files Browse the repository at this point in the history
  • Loading branch information
ozten committed Aug 11, 2010
1 parent c510c21 commit 583fe4b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
35 changes: 35 additions & 0 deletions apps/users/models.py
@@ -0,0 +1,35 @@
from uuid import uuid4

from django.db import models
from django.utils.translation import ugettext_lazy as _

from django.contrib.auth.models import User

from django.db.models.signals import post_save

class UserProfile(models.Model):
"""
Provides a place for 1:1 attributes that
are associated with a SSO user.
The sso_uuid is a RFC 4122 style UUID
which is assigned at object creation.
It is the only ID which a client SSO application
should use. Email, username, etc are not guaranteed
to be stable.
Access via get_profile() method on a User object
"""
user = models.OneToOneField(User)
sso_uuid = models.CharField(_('UUID'), max_length=36, default=str(uuid4()))

def user_saved(sender, **kwargs):
""" After a new user is saved in the db
we should create their profile.
"""
if User == sender:
if 'created' in kwargs and kwargs['created']:
profile = UserProfile(user=kwargs['instance'])
profile.save()

post_save.connect(user_saved)
4 changes: 4 additions & 0 deletions apps/users/templates/users/profile.html
Expand Up @@ -17,6 +17,10 @@ <h2>{% block title %}User Info{% endblock %}</h2>
<th>Email Address</th>
<td>{{ user.email }}</td>
</tr>
<tr>
<th>UUID (debugging)</th>
<td>{{ user.get_profile().sso_uuid }}</td>
</tr>
</table>

<h2>Associated Sites</h2>
Expand Down
3 changes: 2 additions & 1 deletion settings.py
Expand Up @@ -134,12 +134,13 @@ def JINJA_CONFIG():
'django.contrib.messages',

'cas_provider',

'registration',
'sso',
'users',
)

AUTH_PROFILE_MODULE = 'users.UserProfile'

# Tests
TEST_RUNNER = 'test_utils.runner.RadicalTestSuiteRunner'

Expand Down

0 comments on commit 583fe4b

Please sign in to comment.