-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from pennlabs/fix/accounts
Fix accounts
- Loading branch information
Showing
8 changed files
with
69 additions
and
35 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,20 +1,28 @@ | ||
from django.contrib.auth import get_user_model | ||
from django.contrib.auth.backends import RemoteUserBackend | ||
|
||
from accounts.settings import accounts_settings | ||
|
||
|
||
class LabsUserBackend(RemoteUserBackend): | ||
def authenticate(self, request, remote_user): | ||
if not remote_user: | ||
return | ||
User = get_user_model() | ||
user, created = User.objects.get_or_create(uuid=remote_user) | ||
user, created = User.objects.get_or_create(username=remote_user['username']) | ||
if created: | ||
user.username = user.uuid | ||
user.first_name = remote_user['first_name'] | ||
user.last_name = remote_user['last_name'] | ||
user.email = remote_user['email'] | ||
user.set_unusable_password() | ||
user.save() | ||
try: | ||
user = self.configure_user(request, user) | ||
except TypeError: | ||
user = self.configure_user(user) | ||
|
||
if accounts_settings.ADMIN_PERMISSION in remote_user['product_permission']: | ||
user.is_staff = True | ||
user.is_superuser = True | ||
user.save() | ||
return user if self.user_can_authenticate(user) else None |
This file was deleted.
Oops, something went wrong.
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
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
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