forked from mirrors/bookwyrm
Allow users to log in with email or username
This commit is contained in:
parent
f825709599
commit
11dd8c8f82
3 changed files with 31 additions and 1 deletions
22
bookwyrm/migrations/0037_auto_20210118_1900.py
Normal file
22
bookwyrm/migrations/0037_auto_20210118_1900.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
# Generated by Django 3.0.7 on 2021-01-18 19:00
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('bookwyrm', '0036_annualgoal'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name='shelfbook',
|
||||||
|
options={'ordering': ('-created_date',)},
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='user',
|
||||||
|
name='email',
|
||||||
|
field=models.EmailField(max_length=254, unique=True),
|
||||||
|
),
|
||||||
|
]
|
|
@ -25,6 +25,7 @@ from . import fields, Review
|
||||||
class User(OrderedCollectionPageMixin, AbstractUser):
|
class User(OrderedCollectionPageMixin, AbstractUser):
|
||||||
''' a user who wants to read books '''
|
''' a user who wants to read books '''
|
||||||
username = fields.UsernameField()
|
username = fields.UsernameField()
|
||||||
|
email = models.EmailField(unique=True)
|
||||||
|
|
||||||
key_pair = fields.OneToOneField(
|
key_pair = fields.OneToOneField(
|
||||||
'KeyPair',
|
'KeyPair',
|
||||||
|
|
|
@ -32,6 +32,13 @@ class Login(View):
|
||||||
login_form = forms.LoginForm(request.POST)
|
login_form = forms.LoginForm(request.POST)
|
||||||
|
|
||||||
localname = login_form.data['localname']
|
localname = login_form.data['localname']
|
||||||
|
if '@' in localname: # looks like an email address to me
|
||||||
|
email = localname
|
||||||
|
try:
|
||||||
|
username = models.User.objects.get(email=email)
|
||||||
|
except models.User.DoesNotExist: # maybe it's a full username?
|
||||||
|
username = localname
|
||||||
|
else:
|
||||||
username = '%s@%s' % (localname, DOMAIN)
|
username = '%s@%s' % (localname, DOMAIN)
|
||||||
password = login_form.data['password']
|
password = login_form.data['password']
|
||||||
user = authenticate(request, username=username, password=password)
|
user = authenticate(request, username=username, password=password)
|
||||||
|
|
Loading…
Reference in a new issue