|
|
@ -1,6 +1,7 @@ |
|
|
|
import uuid |
|
|
|
|
|
|
|
from django.conf import settings |
|
|
|
from django.contrib.auth import authenticate, login as auth_login |
|
|
|
from django.contrib.auth.models import User |
|
|
|
from django.core.mail import send_mail |
|
|
|
from django.core.urlresolvers import reverse |
|
|
@ -22,11 +23,12 @@ def login(request): |
|
|
|
user.set_password(token) |
|
|
|
user.save() |
|
|
|
|
|
|
|
login_link = reverse("hc-check-token", args=[token]) |
|
|
|
login_link = reverse("hc-check-token", args=[user.username, token]) |
|
|
|
login_link = settings.SITE_ROOT + login_link |
|
|
|
body = "login link: %s" % login_link |
|
|
|
|
|
|
|
send_mail('Log In', body, '[email protected]', [email], fail_silently=False) |
|
|
|
send_mail('Log In', body, '[email protected]', [email], |
|
|
|
fail_silently=False) |
|
|
|
|
|
|
|
# FIXME send login token here |
|
|
|
return redirect("hc-login-link-sent") |
|
|
@ -45,5 +47,13 @@ def login_link_sent(request): |
|
|
|
return render(request, "accounts/login_link_sent.html") |
|
|
|
|
|
|
|
|
|
|
|
def check_token(request): |
|
|
|
return render(request, "accounts/login_link_sent.html") |
|
|
|
def check_token(request, username, token): |
|
|
|
user = authenticate(username=username, password=token) |
|
|
|
if user is not None: |
|
|
|
if user.is_active: |
|
|
|
user.set_unusable_password() |
|
|
|
user.save() |
|
|
|
auth_login(request, user) |
|
|
|
return redirect("hc-checks") |
|
|
|
|
|
|
|
return render(request, "bad_link.html") |