This repository has been archived by the owner on Jan 12, 2022. It is now read-only.
forked from fwenzel/secret-squirrel
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First stab at adding UUID to user profile
- Loading branch information
Showing
3 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
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
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