Skip to content
This repository was archived by the owner on May 5, 2020. It is now read-only.

Commit 49b4b7e

Browse files
akoumjianrelekang
authored andcommitted
feat: Use sites framework and fix bug with url resolution (#65)
1 parent b147989 commit 49b4b7e

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

nopassword/models.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from django.db import models
1010
from django.utils import timezone
1111
from django.utils.translation import ugettext_lazy as _
12+
from django.contrib.sites.shortcuts import get_current_site
1213

1314
from .utils import AUTH_USER_MODEL, get_username
1415

@@ -35,12 +36,16 @@ def save(self, *args, **kwargs):
3536

3637
def login_url(self, secure=False, host=None):
3738
username = get_username(self.user)
38-
host = host or getattr(settings, 'SERVER_URL', None) or 'example.com'
39+
site = get_current_site(None)
40+
if site:
41+
host = site.domain
42+
else:
43+
host = getattr(settings, 'SERVER_URL', None) or 'example.com'
3944
if getattr(settings, 'NOPASSWORD_HIDE_USERNAME', False):
40-
view = reverse_lazy('nopassword.views.login_with_code', args=[self.code]),
45+
view = reverse_lazy('nopassword.views.login_with_code', kwargs={'login_code': self.code}),
4146
else:
4247
view = reverse_lazy('nopassword.views.login_with_code_and_username',
43-
args=[username, self.code]),
48+
kwargs={'username': username, 'login_code': self.code}),
4449

4550
return '%s://%s%s?next=%s' % (
4651
'https' if secure else 'http',

nopassword/urls.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
url(r'^login/$', 'nopassword.views.login', name='login'),
66
url(r'^login-code/(?P<login_code>[a-zA-Z0-9]+)/$',
77
'nopassword.views.login_with_code'),
8-
url(r'^login-code/(?P<username>[a-zA-Z0-9_@\.-]+)/(?P<login_code>[a-zA-Z0-9]+)/$',
8+
url(r'^login-code/(?P<username>[a-zA-Z0-9_@\.\+-]+)/(?P<login_code>[a-zA-Z0-9]+)/$',
99
'nopassword.views.login_with_code_and_username'),
1010
url(r'^logout/$', 'nopassword.views.logout'),
1111
]

0 commit comments

Comments
 (0)