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")
[((1012, 1041), 'django.shortcuts.render', 'render', (['request', '"""login.html"""'], {}), "(request, 'login.html')\n", (1018, 1041), False, 'from django.shortcuts import render\n'), ((1104, 1143), 'django.shortcuts.render', 'render', (['request', '"""customers/index.html"""'], {}), "(request, 'customers/index.html')\n", (1110, 1143), False, 'from django.shortcuts import render\n'), ((321, 350), 'django.contrib.auth.models.User.objects.get', 'User.objects.get', ([], {'email': 'email'}), '(email=email)\n', (337, 350), False, 'from django.contrib.auth.models import User\n'), ((373, 401), 'sesame.utils.get_query_string', 'utils.get_query_string', (['user'], {}), '(user)\n', (395, 401), False, 'from sesame import utils\n'), ((681, 812), 'django.core.mail.send_mail', 'send_mail', (['"""Django Magic Link"""', 'html_message', '"""wishlist@kissflow.com"""', '[email]'], {'fail_silently': '(False)', 'html_message': 'html_message'}), "('Django Magic Link', html_message, 'wishlist@kissflow.com', [\n    email], fail_silently=False, html_message=html_message)\n", (690, 812), False, 'from django.core.mail import send_mail\n'), ((907, 1004), 'django.shortcuts.render', 'render', (['request', '"""login.html"""'], {'context': "{'message': 'Please check your email for magic link.'}"}), "(request, 'login.html', context={'message':\n    'Please check your email for magic link.'})\n", (913, 1004), False, 'from django.shortcuts import render\n')]