Commit 3e89bbc3f87eae2545c1add5710ad7b089d2278a
Committed by
Sergio Oliveira
1 parent
1e559f6d
Exists in
master
and in
13 other branches
Reimplemented way to create user through browserid
Added more fields to create user with custom model Signed-off-by: Carlos Oliveira <carlospecter@gmail.com> Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
Showing
1 changed file
with
22 additions
and
0 deletions
Show diff stats
colab/accounts/auth.py
| 1 | +import re | ||
| 1 | 2 | ||
| 2 | from django_browserid.auth import BrowserIDBackend | 3 | from django_browserid.auth import BrowserIDBackend |
| 3 | 4 | ||
| 5 | + | ||
| 4 | class ColabBrowserIDBackend(BrowserIDBackend): | 6 | class ColabBrowserIDBackend(BrowserIDBackend): |
| 5 | def filter_users_by_email(self, email): | 7 | def filter_users_by_email(self, email): |
| 6 | return self.User.objects.filter(emails__address=email) | 8 | return self.User.objects.filter(emails__address=email) |
| 9 | + | ||
| 10 | + def create_user(self, email): | ||
| 11 | + username = "colab_" + re.split('@', email)[0] | ||
| 12 | + password = None | ||
| 13 | + extra_fields = { | ||
| 14 | + 'first_name': "Colab", | ||
| 15 | + 'last_name': "Colab", | ||
| 16 | + } | ||
| 17 | + | ||
| 18 | + user = self.User.objects.filter(emails__address=email) | ||
| 19 | + | ||
| 20 | + if len(user) is not 0: | ||
| 21 | + return user | ||
| 22 | + | ||
| 23 | + return self.User.objects.create_user( | ||
| 24 | + username, | ||
| 25 | + email, | ||
| 26 | + password, | ||
| 27 | + **extra_fields | ||
| 28 | + ) |