Skip to content

Commit

Permalink
Merge pull request #195 from open-plan-tool/feature/add-account-email…
Browse files Browse the repository at this point in the history
…-verification-process

Feature/add account email verification process
  • Loading branch information
Bachibouzouk authored Oct 28, 2022
2 parents e789359 + fec87d8 commit 80f8b74
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 24 deletions.
2 changes: 0 additions & 2 deletions app/users/forms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from django import forms
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Field

from .models import CustomUser

Expand Down
1 change: 0 additions & 1 deletion app/users/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.contrib.auth.models import AbstractUser
from django.db import models


class CustomUser(AbstractUser):
Expand Down
9 changes: 0 additions & 9 deletions app/users/tokens.py

This file was deleted.

19 changes: 7 additions & 12 deletions app/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@
from django.core.mail import EmailMessage, send_mail, BadHeaderError
from django.db.models import Q
from django.http import HttpResponse
from django.http.response import HttpResponseRedirect
from django.shortcuts import render, redirect
from django.template.loader import render_to_string
from django.urls.base import reverse
from django.utils.encoding import force_bytes
from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode
from django.views.decorators.http import require_http_methods

from .forms import CustomUserCreationForm, CustomUserChangeForm
from .models import CustomUser

Expand All @@ -28,11 +25,9 @@
def signup(request):
if request.method == "POST":
form = CustomUserCreationForm(request.POST)
# print(form.errors.as_data())
if form.is_valid():
user = form.save(commit=False)
# user.is_active = False
user.is_active = True
user.is_active = False
user.save()
current_site = get_current_site(request)
mail_subject = "Activate your account."
Expand All @@ -47,9 +42,9 @@ def signup(request):
)
to_email = form.cleaned_data.get("email")
email = EmailMessage(mail_subject, message, to=[to_email])
# email.send()
# return HttpResponse('Please confirm your email address to complete the registration')
return HttpResponseRedirect(reverse("login"))
email.send()
messages.info(request, "Please confirm your email address to complete the registration")
return redirect("home")
else:
form = CustomUserCreationForm()
return render(request, "registration/signup.html", {"form": form})
Expand All @@ -64,11 +59,11 @@ def activate(request, uidb64, token):
if user is not None and default_token_generator.check_token(user, token):
user.is_active = True
user.save()
return HttpResponse(
"Thank you for your email confirmation. Now you can login your account."
)
messages.success(request, "Thank you for your email confirmation. Now you can login your account.")
return redirect("login")
else:
return HttpResponse("Activation link is invalid!")
return redirect("home")


@login_required
Expand Down

0 comments on commit 80f8b74

Please sign in to comment.