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

Commit

Permalink
pep8
Browse files Browse the repository at this point in the history
  • Loading branch information
relekang committed Feb 18, 2013
1 parent 59f0bf4 commit ee35a86
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions django_nopassword/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#Todo: move to settings
TIMEOUT = timedelta(minutes=15)


class EmailBackend:

def authenticate(self, username, code=None):
Expand Down
1 change: 1 addition & 0 deletions django_nopassword/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions django_nopassword/models.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion django_nopassword/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

urlpatterns = patterns('',
url(r'^login/$', 'django_nopassword.views.login'),
url(r'^login-code/(?P<username>[a-zA-Z0-9_@\.-]+)/(?P<login_code>[a-zA-Z0-9]+)/$', 'django_nopassword.views.login_with_code'),
url(r'^login-code/(?P<username>[a-zA-Z0-9_@\.-]+)/(?P<login_code>[a-zA-Z0-9]+)/$',
'django_nopassword.views.login_with_code'),
url(r'^logout/$', 'django_nopassword.views.logout'),
)
6 changes: 4 additions & 2 deletions django_nopassword/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
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():
return render(request, 'registration/sent_mail.html')

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:
Expand Down

0 comments on commit ee35a86

Please sign in to comment.