-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,3 +127,6 @@ dmypy.json | |
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# Django | ||
migrations/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from django.contrib.auth import get_user_model | ||
from django.contrib.auth.backends import ModelBackend | ||
|
||
UserModel = get_user_model() | ||
|
||
|
||
class EmailOrUsernameLogin(ModelBackend): | ||
def authenticate(self, request, username=None, password=None, **kwargs): | ||
if '@' in username: | ||
args = {'email': username} | ||
else: | ||
args = {'username': username} | ||
|
||
if username is None or password is None: | ||
return | ||
|
||
try: | ||
user = UserModel.objects.get(**args) | ||
except UserModel.DoesNotExist: | ||
# Run the default password hasher once to reduce the timing | ||
# difference between an existing and a nonexistent user (#20760). | ||
UserModel().set_password(password) | ||
else: | ||
if user.check_password(password) and \ | ||
self.user_can_authenticate(user): | ||
return user |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from django.contrib import admin | ||
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin | ||
from django.utils.translation import gettext as _ | ||
|
||
from core import models | ||
|
||
|
||
class UserModel(BaseUserAdmin): | ||
"""User admin class.""" | ||
ordering = ['username'] | ||
list_display = ['email', 'username', | ||
'first_name', 'last_name', 'gender', 'stage', 'bio'] | ||
fieldsets = ( | ||
( | ||
_('Personal Information'), | ||
{ | ||
'fields': ('first_name', 'last_name', 'stage', 'bio') | ||
} | ||
), | ||
( | ||
_('Contact Information'), | ||
{ | ||
'fields': ('username', 'email') | ||
}, | ||
), | ||
( | ||
_('Permissions'), | ||
{ | ||
'fields': ('is_active', 'is_staff', 'is_superuser') | ||
} | ||
), | ||
( | ||
_('Important Information'), | ||
{ | ||
'fields': ('id', 'last_login') | ||
} | ||
) | ||
) | ||
|
||
add_fieldsets = ( | ||
( | ||
_('Person Information'), | ||
{ | ||
'classes': ('wide',), | ||
'fields': ('first_name', 'last_name', 'stage', 'bio') | ||
} | ||
), | ||
( | ||
_('Account Information'), | ||
{ | ||
'classes': ('wide',), | ||
'fields': ('username', 'email', 'password1', 'password2') | ||
} | ||
) | ||
) | ||
|
||
|
||
admin.site.register(models.User) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class CoreConfig(AppConfig): | ||
name = 'core' |