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

Commit

Permalink
feat: Use sites framework and fix bug with url resolution (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
akoumjian authored and relekang committed Apr 29, 2016
1 parent b147989 commit 49b4b7e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions nopassword/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.db import models
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from django.contrib.sites.shortcuts import get_current_site

from .utils import AUTH_USER_MODEL, get_username

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

def login_url(self, secure=False, host=None):
username = get_username(self.user)
host = host or getattr(settings, 'SERVER_URL', None) or 'example.com'
site = get_current_site(None)

This comment has been minimized.

Copy link
@dwinston

dwinston Dec 2, 2016

Doesn't get_current_site() need the request as argument? to fall back to request.get_host() ?

if site:
host = site.domain
else:
host = getattr(settings, 'SERVER_URL', None) or 'example.com'
if getattr(settings, 'NOPASSWORD_HIDE_USERNAME', False):
view = reverse_lazy('nopassword.views.login_with_code', args=[self.code]),
view = reverse_lazy('nopassword.views.login_with_code', kwargs={'login_code': self.code}),
else:
view = reverse_lazy('nopassword.views.login_with_code_and_username',
args=[username, self.code]),
kwargs={'username': username, 'login_code': self.code}),

return '%s://%s%s?next=%s' % (
'https' if secure else 'http',
Expand Down
2 changes: 1 addition & 1 deletion nopassword/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
url(r'^login/$', 'nopassword.views.login', name='login'),
url(r'^login-code/(?P<login_code>[a-zA-Z0-9]+)/$',
'nopassword.views.login_with_code'),
url(r'^login-code/(?P<username>[a-zA-Z0-9_@\.-]+)/(?P<login_code>[a-zA-Z0-9]+)/$',
url(r'^login-code/(?P<username>[a-zA-Z0-9_@\.\+-]+)/(?P<login_code>[a-zA-Z0-9]+)/$',

This comment has been minimized.

Copy link
@dwinston

dwinston Dec 2, 2016

This is an important fix, and I'd like to be able to run my django site with a versioned dependency on django-nopassword rather than pointing to HEAD. Can you release v2.1.2?

Great project, by the way. I had been using Mozilla Persona until I had to shift to another fallback solution (Persona shut down Nov 30) for folks who don't want to use "social" login, and I don't want to store passwords.

This comment has been minimized.

Copy link
@dwinston

This comment has been minimized.

Copy link
@relekang

relekang Dec 2, 2016

Owner

I will look into that next week. I am traveling this weekend. ☺

This comment has been minimized.

Copy link
@relekang

relekang Dec 11, 2016

Owner

@dwinston Did you mean this whole commit or just this line? Parts of this commit did not work so I had to revert some parts in order to get out a new release. I would like to revisit the integration with the sites framework though. That is tracked in #70, please share your thoughts on it if you have any ✌️

This comment has been minimized.

Copy link
@dwinston

dwinston Jan 19, 2017

I just meant this line. I am very happy with v3.0.0 and have been using it in production. Thank you!

This comment has been minimized.

Copy link
@relekang

relekang Jan 20, 2017

Owner

Thanks 🙌

'nopassword.views.login_with_code_and_username'),
url(r'^logout/$', 'nopassword.views.logout'),
]

0 comments on commit 49b4b7e

Please sign in to comment.