from django.shortcuts import render
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from sesame import utils
from django.core.mail import send_mail


def login_page(request):
    if request.method == "POST":
        email = request.POST.get("emailId")
        user = User.objects.get(email=email)
        login_token = utils.get_query_string(user)
        login_link = "http://127.0.0.1:8000/customers/{}".format(login_token)

        html_message = """
        <p>Hi there,</p>
        <p>Here is your <a href="{}">magic link</a> </p>
        <p>Thanks,</p>
        <p>Django Admin</p>
        """.format(login_link)

        send_mail(
            'Django Magic Link',
            html_message,
            'wishlist@kissflow.com',
            [email],
            fail_silently=False,
            html_message = html_message
        )
        return render(request, "login.html", context={"message":"Please check your email for magic link."})

    return render(request, "login.html")

@login_required
def customers_home_page(request):
    return render(request, "customers/index.html")
[((32, 11, 32, 40), 'django.shortcuts.render', 'render', ({(32, 18, 32, 25): 'request', (32, 27, 32, 39): '"""login.html"""'}, {}), "(request, 'login.html')", False, 'from django.shortcuts import render\n'), ((36, 11, 36, 50), 'django.shortcuts.render', 'render', ({(36, 18, 36, 25): 'request', (36, 27, 36, 49): '"""customers/index.html"""'}, {}), "(request, 'customers/index.html')", False, 'from django.shortcuts import render\n'), ((11, 15, 11, 44), 'django.contrib.auth.models.User.objects.get', 'User.objects.get', (), '', False, 'from django.contrib.auth.models import User\n'), ((12, 22, 12, 50), 'sesame.utils.get_query_string', 'utils.get_query_string', ({(12, 45, 12, 49): 'user'}, {}), '(user)', False, 'from sesame import utils\n'), ((22, 8, 29, 9), 'django.core.mail.send_mail', 'send_mail', (), '', False, 'from django.core.mail import send_mail\n'), ((30, 15, 30, 107), 'django.shortcuts.render', 'render', (), '', False, 'from django.shortcuts import render\n')]