Skip to content

Commit

Permalink
Remove old password reset files
Browse files Browse the repository at this point in the history
  • Loading branch information
pablodiegoss committed Nov 21, 2024
1 parent 2bd9741 commit cbbcd3e
Show file tree
Hide file tree
Showing 11 changed files with 4 additions and 346 deletions.
8 changes: 0 additions & 8 deletions src/users/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,6 @@ def clean(self):
return cleaned_data


class RecoverPasswordForm(forms.Form):
username_or_email = forms.CharField(label="username / email", max_length="50")


class RecoverPasswordCodeForm(forms.Form):
verification_code = forms.CharField(label="Verification code", max_length="200")


class UploadMarkerForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(UploadMarkerForm, self).__init__(*args, **kwargs)
Expand Down
22 changes: 0 additions & 22 deletions src/users/jinja2/users/invalid-recovering-email.jinja2

This file was deleted.

31 changes: 0 additions & 31 deletions src/users/jinja2/users/recover-edit-password.jinja2

This file was deleted.

31 changes: 0 additions & 31 deletions src/users/jinja2/users/recover-password-code.jinja2

This file was deleted.

46 changes: 0 additions & 46 deletions src/users/jinja2/users/recover-password.jinja2

This file was deleted.

22 changes: 0 additions & 22 deletions src/users/jinja2/users/wrong-verification-code.jinja2

This file was deleted.

1 change: 1 addition & 0 deletions src/users/services/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .recaptcha_service import *
35 changes: 0 additions & 35 deletions src/users/services/email_service.py

This file was deleted.

24 changes: 0 additions & 24 deletions src/users/services/encrypt_service.py

This file was deleted.

23 changes: 0 additions & 23 deletions src/users/services/user_service.py

This file was deleted.

107 changes: 3 additions & 104 deletions src/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
login,
update_session_auth_hash,
)

from django.utils.translation import gettext_lazy as _
from django.contrib.auth.decorators import login_required
from django.contrib.auth.forms import SetPasswordForm
from django.http import Http404, JsonResponse
Expand All @@ -22,14 +24,12 @@
ExhibitForm,
PasswordChangeForm,
ProfileForm,
RecoverPasswordCodeForm,
RecoverPasswordForm,
SignupForm,
UploadMarkerForm,
UploadObjectForm,
)
from .models import Profile
from .services import ( EmailService,EncryptService ,BOT_SCORE, create_assessment, UserService)
from .services import (BOT_SCORE, create_assessment)
from django.urls import reverse_lazy
from django.contrib.auth.views import PasswordResetView
from django.contrib.messages.views import SuccessMessageMixin
Expand Down Expand Up @@ -84,107 +84,6 @@ class ResetPasswordView(SuccessMessageMixin, PasswordResetView):
"please make sure you've entered the address you registered with, and check your spam folder.")
success_url = reverse_lazy('home')

def recover_password(request):
if request.method == "POST":
if settings.RECAPTCHA_ENABLED:
recaptcha_token = request.POST.get("g-recaptcha-response")
assessment = create_assessment(
token=recaptcha_token, recaptcha_action="recover_password"
)
score = assessment.get("riskAnalysis", {}).get("score", -1)
if score <= BOT_SCORE:
return redirect("home")

recover_password_form = RecoverPasswordForm(request.POST)

if recover_password_form.is_valid():
username_or_email = recover_password_form.cleaned_data.get(
"username_or_email"
)
user_service = UserService()
username_or_email_is_valid = user_service.check_if_username_or_email_exist(
username_or_email
)
if not username_or_email_is_valid:
return redirect("invalid_recovering_email_or_username")

global global_recovering_email
global_recovering_email = user_service.get_user_email(username_or_email)

global global_verification_code
encrypt_service = EncryptService()
global_verification_code = encrypt_service.generate_verification_code(
global_recovering_email
)

build_message_and_send_to_user(global_recovering_email)

return redirect("recover-code")

recover_password_form = RecoverPasswordForm()
return render(
request,
"users/recover-password.jinja2",
{
"form": recover_password_form,
"recaptcha_enabled": settings.RECAPTCHA_ENABLED,
"recaptcha_site_key": settings.RECAPTCHA_SITE_KEY,
},
)


def build_message_and_send_to_user(email):
message = f"You have requested a new password. This is your verification code: {global_verification_code}\nCopy it and put into the field."
email_service = EmailService(message)
multipart_message = email_service.build_multipart_message(email)
email_service.send_email_to_recover_password(multipart_message)


def recover_code(request):
if request.method == "POST":
form = RecoverPasswordCodeForm(request.POST)

if form.is_valid():
code = form.cleaned_data.get("verification_code")

log.warning("Inserido: %s", code)
log.warning("Correto: %s", global_verification_code)

if code == global_verification_code:
global recover_password_user
recover_password_user = User.objects.get(email=global_recovering_email)
return redirect("recover-edit-password")

return redirect("wrong-verification-code")
return redirect("home")

form = RecoverPasswordCodeForm()
return render(request, "users/recover-password-code.jinja2", {"form": form})


def recover_edit_password(request):
if request.method == "POST":
form = SetPasswordForm(recover_password_user, data=request.POST)

if form.is_valid():
form.save()

return redirect("login")
else:
form = SetPasswordForm(recover_password_user)

return render(request, "users/recover-edit-password.jinja2", {"form": form})


@require_http_methods(["GET"])
def wrong_verification_code(request):
return render(request, "users/wrong-verification-code.jinja2")


@require_http_methods(["GET"])
def invalid_recovering_email_or_username(request):
return render(request, "users/invalid-recovering-email.jinja2")


@login_required
@require_http_methods(["GET"])
Expand Down

0 comments on commit cbbcd3e

Please sign in to comment.