Skip to content

Commit

Permalink
resolvendo conflitos do modal
Browse files Browse the repository at this point in the history
  • Loading branch information
mandicrz committed Dec 12, 2024
2 parents 2c6e885 + 11acfc6 commit 2ca7608
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 23 deletions.
Binary file modified mamutes/Users/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file modified mamutes/Users/__pycache__/admin.cpython-312.pyc
Binary file not shown.
Binary file modified mamutes/Users/__pycache__/apps.cpython-312.pyc
Binary file not shown.
Binary file modified mamutes/Users/__pycache__/forms.cpython-312.pyc
Binary file not shown.
Binary file modified mamutes/Users/__pycache__/models.cpython-312.pyc
Binary file not shown.
Binary file modified mamutes/Users/__pycache__/views.cpython-312.pyc
Binary file not shown.
25 changes: 23 additions & 2 deletions mamutes/Users/static/scripts/openModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,32 @@
const btnModal = document.querySelector('#btnModal');
const modal = document.querySelector('#modal');
const btnClose = document.querySelector('#btnClose');
const form = document.querySelector('#recoverAccountForm');
const mensagemContainer = document.querySelector('#mensagemContainer');

btnModal.addEventListener("click", ()=>{
modal.showModal();
});
btnClose.addEventListener("click", ()=>{
modal.close();
})
})()
});

form.addEventListener("submit", (event) => {
event.preventDefault();
const formData = new FormData(form);
fetch(form.action, {
method: 'POST',
body: formData,
headers: {
'X-Requested-With': 'XMLHttpRequest',
},
})
.then(response => response.json())
.then(data => {
mensagemContainer.textContent = data.mensagem;
if (data.success) {
form.reset();
}
})
});
})();
6 changes: 2 additions & 4 deletions mamutes/Users/templates/recoverAccount.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ <h1 class="titulo">Recuperar Conta</h1>
<h2 class="subtitulo">Preencha o formulário</h2>
</div>
</div>
<form action="{% url 'recoverAccount' %}" method="POST" class="formLogin">
<form id="recoverAccountForm" action="{% url 'recoverAccount' %}" method="POST" class="formLogin">
<div class="divsFields">
<p class="tituloInputs">Email</p>
{% csrf_token %}
<input type="email" name="email" id="email" placeholder="Ex.: [email protected]" class="inputForm">
{% if mensagem %}
{{ mensagem }}
{% endif%}
</div>
<div id="mensagemContainer" class="mensagemContainer"></div>
<div class="botoesRecuperar">
<button type="submit" class="submitBotao" value="adicionar" style="border-radius: 8px; background: #1F1A99;">
<span class="addLabel">Enviar</span>
Expand Down
25 changes: 11 additions & 14 deletions mamutes/Users/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.shortcuts import redirect, render
from django.http import HttpResponse
from django.shortcuts import render
from django.http import HttpResponse, JsonResponse
from django.contrib.auth.decorators import user_passes_test
from django.contrib.auth import authenticate, login as login_django
from .models import *
Expand Down Expand Up @@ -36,10 +35,7 @@ def register(request):
return render(request, 'register.html')

def recoverAccount(request):

if request.method == 'GET':
return render(request, 'recoverAccount.html')
else:
if request.method == 'POST':
email = request.POST.get('email')

if MembroEquipe.objects.filter(email__exact=email).exists():
Expand All @@ -55,18 +51,19 @@ def recoverAccount(request):
recipient_list=[email]
)


context = {
response = {
'mensagem': f'Enviamos um email de recuperação de conta para {email}, cheque em sua caixa postal.',
'success': True
}

return render(request, 'recoverAccount.html', context)

else:
context = {
response = {
'mensagem': f'Este email não existe, é necessário que o email tenha registro no sistema para recuperá-lo.',
'success': False
}
return render(request, 'recoverAccount.html', context)

return JsonResponse(response)


def redefinePassword(request, username, token):
user = MembroEquipe.objects.get(username=username)
generator = PasswordResetTokenGenerator()
Expand Down Expand Up @@ -95,4 +92,4 @@ def redefinePassword(request, username, token):
"token": token,
})

return redirect("login")
return redirect("login")
Binary file modified mamutes/db.sqlite3
Binary file not shown.
6 changes: 3 additions & 3 deletions mamutes/mamutes/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

urlpatterns = [
path('admin/', admin.site.urls),
path ('login/', login, name = 'login'),
path('register/', register, name = 'register'),
path('account_recovery/', recoverAccount, name = 'recoverAccount'),
path('login/', login, name='login'),
path('register/', register, name='register'),
path('account_recovery/', recoverAccount, name='recoverAccount'),
path('redefine_password/<str:username>/<str:token>', redefinePassword, name="redefinePassword"),
path('', index, name="index"),
path('competition/', competition, name="competition"),
Expand Down

0 comments on commit 2ca7608

Please sign in to comment.