diff --git a/django_nopassword/backends.py b/django_nopassword/backends.py index ff35f39..7779cf3 100644 --- a/django_nopassword/backends.py +++ b/django_nopassword/backends.py @@ -6,6 +6,7 @@ #Todo: move to settings TIMEOUT = timedelta(minutes=15) + class EmailBackend: def authenticate(self, username, code=None): diff --git a/django_nopassword/forms.py b/django_nopassword/forms.py index 6fceaa1..a9ac9c8 100644 --- a/django_nopassword/forms.py +++ b/django_nopassword/forms.py @@ -4,6 +4,7 @@ from django.utils.translation import ugettext_lazy as _ from django_nopassword.models import LoginCode + class AuthenticationForm(forms.Form): """ Base class for authenticating users. Extend this to get a form that accepts diff --git a/django_nopassword/models.py b/django_nopassword/models.py index 46e82e7..8118ec7 100644 --- a/django_nopassword/models.py +++ b/django_nopassword/models.py @@ -1,21 +1,22 @@ # -*- coding: utf-8 -*- -from random import choice import string +from random import choice +from datetime import datetime from django.conf import settings from django.core.mail import send_mail from django.core.urlresolvers import reverse from django.db import models -from datetime import datetime from django.contrib.auth.models import User from django.utils.translation import ugettext_lazy as _ -class LoginCode (models.Model): + +class LoginCode(models.Model): user = models.ForeignKey(User, related_name='login_codes', editable=False, verbose_name=_('user')) code = models.CharField(max_length=2, editable=False, verbose_name=_('code')) timestamp = models.DateTimeField(editable=False) next = models.TextField(editable=False, blank=True) - def __unicode__ (self): + def __unicode__(self): return "%s - %s" % (self.user, self.timestamp) def save(self, *args, **kwargs): @@ -34,7 +35,6 @@ def save(self, *args, **kwargs): [self.user.email], ) - @classmethod def create_code_for_user(cls, user, next=None): code = cls.generate_code() diff --git a/django_nopassword/urls.py b/django_nopassword/urls.py index 88f3596..38dc860 100644 --- a/django_nopassword/urls.py +++ b/django_nopassword/urls.py @@ -3,6 +3,7 @@ urlpatterns = patterns('', url(r'^login/$', 'django_nopassword.views.login'), - url(r'^login-code/(?P[a-zA-Z0-9_@\.-]+)/(?P[a-zA-Z0-9]+)/$', 'django_nopassword.views.login_with_code'), + url(r'^login-code/(?P[a-zA-Z0-9_@\.-]+)/(?P[a-zA-Z0-9]+)/$', + 'django_nopassword.views.login_with_code'), url(r'^logout/$', 'django_nopassword.views.logout'), ) \ No newline at end of file diff --git a/django_nopassword/views.py b/django_nopassword/views.py index 3e3e33c..96b46a4 100644 --- a/django_nopassword/views.py +++ b/django_nopassword/views.py @@ -6,7 +6,8 @@ from django_nopassword.forms import AuthenticationForm from django.contrib.auth import login as auth_login, logout as auth_logout, authenticate -def login (request): + +def login(request): if request.method == 'POST': form = AuthenticationForm(data=request.POST) if form.is_valid(): @@ -14,7 +15,8 @@ def login (request): return django_login(request, authentication_form=AuthenticationForm) -def login_with_code (request, username, login_code): + +def login_with_code(request, username, login_code): user = authenticate(username=username, code=login_code) if user is None: