updated apps.lyric.views for simpler login authentication and error messaging; .tests.test_views have new test method to assert either authentication condition has properly occurred
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
from django.contrib import auth, messages
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.mail import send_mail
|
||||
from django.shortcuts import redirect
|
||||
from django.urls import reverse
|
||||
from .models import Token, User
|
||||
from ..dashboard.forms import ItemForm
|
||||
from .models import Token
|
||||
|
||||
def send_login_email(request):
|
||||
email = request.POST["email"]
|
||||
@@ -27,12 +25,10 @@ def send_login_email(request):
|
||||
|
||||
def login(request):
|
||||
uid = request.GET.get("token")
|
||||
if not uid:
|
||||
return redirect("/")
|
||||
|
||||
user = auth.authenticate(request, uid=uid)
|
||||
if user is not None:
|
||||
user.backend = "apps.lyric.authentication.PasswordlessAuthenticationBackend"
|
||||
auth.login(request, user)
|
||||
|
||||
else:
|
||||
messages.error(request, "Invalid login link!—please request a new one")
|
||||
return redirect("/")
|
||||
|
||||
Reference in New Issue
Block a user