Ejemplo n.º 1
0
def send_verify_mail(email, discord_tag, host="csua.berkeley.edu"):
    print("Email:", email)
    print("Tag:", discord_tag)
    emailb64 = b64_encode(email.encode("utf8"))
    discord_tagb64 = b64_encode(discord_tag.encode("utf8"))

    token = discord_token_generator.make_token((email, discord_tag))
    html_message = render_to_string(
        "discord_register_email.html",
        {
            "host": host,
            "token": token,
            "email": email,
            "discord_tag": discord_tag,
            "emailb64": emailb64,
            "discord_tagb64": discord_tagb64,
        },
    )
    print("sending email from [email protected] to ", email)
    send_mail(
        subject="CSUA Discord Email Verification",
        message=strip_tags(html_message),
        from_email="*****@*****.**",
        recipient_list=[email],
        html_message=html_message,
    )
Ejemplo n.º 2
0
def register(request):
    if request.method == "POST":
        form = DiscordRegisterForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data.get("email")
            discord_tag = form.cleaned_data.get("discord_tag")
            emailb64 = b64_encode(email.encode("utf8"))
            discord_tagb64 = b64_encode(discord_tag.encode("utf8"))

            token = discord_token_generator.make_token((email, discord_tag))
            html_message = render_to_string(
                "discord_register_email.html",
                {
                    "host": request.get_host(),
                    "token": token,
                    "email": email,
                    "discord_tag": discord_tag,
                    "emailb64": emailb64,
                    "discord_tagb64": discord_tagb64,
                },
            )
            send_mail(
                subject="CSUA Discord Email Verification",
                message=strip_tags(html_message),
                from_email="*****@*****.**",
                recipient_list=[email],
                html_message=html_message,
            )
            return redirect(
                reverse("discord_register_email_sent",
                        kwargs={"emailb64": emailb64}))
    else:
        form = DiscordRegisterForm()
    return render(request, "discord_register.html", {"form": form})
Ejemplo n.º 3
0
def create_user_return_token(email):
    u = User.objects.get_or_none(email=email)
    if u is None:
        new_user = User(email=email)
        new_user.set_password(None)
        new_user.full_clean()
        new_user.save()
        user_token = registration_token_generator.make_token(new_user)
        b64id = b64_encode(bytes(str(new_user.pk).encode()))
        return [user_token, b64id]
    elif not u.is_active:
        user_token = registration_token_generator.make_token(u)
        b64id = b64_encode(bytes(str(u.pk).encode()))
        return [user_token, b64id]
    else:
        return None
Ejemplo n.º 4
0
def register(request):
    if request.method == "POST":
        form = DiscordRegisterForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data.get("email")
            discord_tag = form.cleaned_data.get("discord_tag")
            host = request.get_host()
            emailb64 = b64_encode(email.encode("utf8"))
            send_verify_mail(email, discord_tag, host)
            return redirect(
                reverse("discord_register_email_sent",
                        kwargs={"emailb64": emailb64}))
    else:
        form = DiscordRegisterForm()
    return render(request, "discord_register.html", {"form": form})
Ejemplo n.º 5
0
 def post(self, request):
     dtg = password_token_generator
     try:
         email = request.POST['email']
         user = User.objects.get_or_none(email=email)
         if user is None or not user.is_active:
             error = 'No account found with that Email-id.'
             return render(request,
                           'registration/forgot_password.html',
                           context={'error': error})
     except KeyError:
         error = 'Please enter your Email.'
         return render(request,
                       'registration/forgot_password.html',
                       context={'error': error})
     token = dtg.make_token(user)
     idb64 = b64_encode(bytes(str(user.pk).encode()))
     url = URL + reverse('password_reset_confirm', args=[idb64, token])
     html = render_to_string('email/password_reset.html',
                             context={
                                 'title': "Reset Password",
                                 'head': "Reset Password",
                                 'name': user.name,
                                 'action': {
                                     'name': "Reset my Password",
                                     'href': url
                                 }
                             })
     text = "Dear " + user.name + ",\n" + \
            "Please open the link given below to reset password for your Abhisarga 2020 account. \n" + url + \
            "\nIf you did not request password reset then please ignore this email." + \
            "\nRegards,\nAbhisarga 2020 Team"
     send_mail("Password Reset for Abhisarga 2020", text, html, [email])
     message = {
         "title":
         "Password Reset Confirmation",
         "message":
         "An mail will be sent to your registered email with the link to reset"
         " your password, shortly.",
         "next": {
             "url": reverse('login'),
             "name": 'Return to Login Page'
         }
     }
     return render(request, 'base/message.html', context=message)
Ejemplo n.º 6
0
    def post(self, request):
        dtg = default_token_generator
        try:
            email = request.POST['email']
            user = User.objects.get(email=email)
        except KeyError as e:
            error = 'Enter email id.'
            return render(request,
                          'registration/forgot_password.html',
                          context={'error': error})
        except User.DoesNotExist:
            error = 'No account found with that Email-id.'
            return render(request,
                          'registration/forgot_password.html',
                          context={'error': error})

        token = dtg.make_token(user)
        uidb64 = b64_encode(bytes(str(user.pk).encode()))
        context = {
            'email': user.email,
            'protocol': 'http',
            'domain': settings.DOMAIN,
            'uid': uidb64,
            'token': token,
            'name': user.first_name,
        }
        mail_body = render_to_string('registration/password_reset_email.html',
                                     context=context)
        send_mail("Password Reset", mail_body, [user.email],
                  '*****@*****.**')
        message = {
            "title":
            "Password Reset",
            "heading":
            "Email Sent",
            "message":
            "A mail has been sent to your registered email"
            " with instructions for resetting your password."
        }
        return render(request, 'registration/message.html', context=message)