Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
CaioDuart3 committed Dec 8, 2024
2 parents 7739c13 + 6fe7bf8 commit c4090b3
Show file tree
Hide file tree
Showing 23 changed files with 31 additions and 31 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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified mamutes/Users/migrations/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion mamutes/Users/templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ <h3 class="apresentation-text-h3">Faça seu login e continue</h3>

</div>
</div>
<a class="forgot-my-password" href="{% url 'recuperarConta' %}">Esqueci minha senha</a>
<a class="forgot-my-password" href="{% url 'recoverAccount' %}">Esqueci minha senha</a>
</div>
<button class="btn-login" type="submit">Fazer login</button>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<h1 class="titulo">Recuperar Conta</h1>
<h2 class="subtitulo">Preencha o formulário</h2>
</div>
<form action="{% url 'recuperarConta' %}" method="POST" class="formLogin">
<form action="{% url 'recoverAccount' %}" method="POST" class="formLogin">
<div class="divsFields">
<p class="tituloInputs">Email</p>
{% csrf_token %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ <h1 class="greeting-login-h1">Bem-vindo de <b class="greeting-login-h1-colorizer
</div>
<h3 class="apresentation-text-h3">Redefina sua senha para recuperar seu login</h3>
</div>
<form class="form-login" action="{% url 'redefinirSenha' username=username token=token %}" method="POST">
<form class="form-login" action="{% url 'redefinePassword' username=username token=token %}" method="POST">
{% csrf_token %}
<div class="form-login-inputs">
<div class="container-inputs">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<h1 class="titulo">Adicionar novo membro</h1>
<h2 class="subtitulo">Preencha o formulário</h2>
</div>
<form action="{%url 'cadastro'%}" method="post" class="formLogin">{% csrf_token %}
<form action="{%url 'register'%}" method="post" class="formLogin">{% csrf_token %}
<div class="formPrincipal">
<div class="divsFields">
<p class="tituloInputs">Nome completo</p>
Expand Down
48 changes: 24 additions & 24 deletions mamutes/Users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ def login (request):
return render (request, 'login.html')
else:
username = request.POST.get('username')
senha = request.POST.get('password')
user_password = request.POST.get('password')

user = authenticate(username=username, password=senha)
user = authenticate(username=username, password=user_password)

if user is not None:
login_django (request, user)
Expand All @@ -33,25 +33,25 @@ def isSuperUser(user):


@user_passes_test(isSuperUser)
def cadastro(request):
return render(request, 'cadastro.html')
def register(request):
return render(request, 'register.html')

def recuperarConta(request):
def recoverAccount(request):

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

if MembroEquipe.objects.filter(email__exact=email).exists():
geradorToken = PasswordResetTokenGenerator()
usuario = MembroEquipe.objects.get(email=email)
token = geradorToken.make_token(usuario)
username = usuario.username
tokenGenerator = PasswordResetTokenGenerator()
user = MembroEquipe.objects.get(email=email)
token = tokenGenerator.make_token(user)
username = user.username

send_mail(
subject="Redefinição de senha",
message=f"Uma requisição de redefinição de senha foi feita no site da Mamutes do Cerrado para a conta vinculada a este email, para prosseguir com a redefinição de senha basta acessar o seguinte link: http://127.0.0.1:8000/redefinirSenha/{username}/{token}. Caso a requisição não tenha sido feita por você, por favor ignore este email.",
message=f"Uma requisição de redefinição de senha foi feita no site da Mamutes do Cerrado para a conta vinculada a este email, para prosseguir com a redefinição de senha basta acessar o seguinte link: http://127.0.0.1:8000/redefine_password/{username}/{token}. Caso a requisição não tenha sido feita por você, por favor ignore este email.",
from_email=settings.EMAIL_HOST_USER,
recipient_list=[email]
)
Expand All @@ -61,37 +61,37 @@ def recuperarConta(request):
'mensagem': f'Enviamos um email de recuperação de conta para {email}, cheque em sua caixa postal.',
}

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

else:
context = {
'mensagem': f'Este email não existe, é necessário que o email tenha registro no sistema para recuperá-lo.',
}
return render(request, 'recuperarConta.html', context)
def redefinirSenha(request, username, token):
usuario = MembroEquipe.objects.get(username=username)
gerador = PasswordResetTokenGenerator()
return render(request, 'recoverAccount.html', context)
def redefinePassword(request, username, token):
user = MembroEquipe.objects.get(username=username)
generator = PasswordResetTokenGenerator()

if request.method == "POST":
senha = request.POST.get("password1")
confirmar_senha = request.POST.get("password2")
user_password = request.POST.get("password1")
check_password = request.POST.get("password2")

if senha != confirmar_senha:
if user_password != check_password:
print('As senhas não coincidem')
return render(request, 'redefinirSenha.html', {
return render(request, 'redefinePassword.html', {
"username": username,
"token": token,
"mensagem": "As senhas não coincidem."
})

usuario.set_password(senha)
usuario.save()
user.set_password(user_password)
user.save()
print('Senha redefinida com sucesso')
return redirect("login")

if gerador.check_token(usuario, token):
if generator.check_token(user, token):
print('Token válido')
return render(request, 'redefinirSenha.html', {
return render(request, 'redefinePassword.html', {
"username": username,
"token": token,
})
Expand Down
Binary file modified mamutes/db.sqlite3
Binary file not shown.
Binary file modified mamutes/mamutes/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file modified mamutes/mamutes/__pycache__/settings.cpython-312.pyc
Binary file not shown.
Binary file modified mamutes/mamutes/__pycache__/urls.cpython-312.pyc
Binary file not shown.
Binary file modified mamutes/mamutes/__pycache__/wsgi.cpython-312.pyc
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,7 +5,7 @@
urlpatterns = [
path('admin/', admin.site.urls),
path ('login/', views.login, name = 'login'),
path('cadastro/', views.cadastro, name = 'cadastro'),
path('recuperarConta/', views.recuperarConta, name = 'recuperarConta'),
path('redefinirSenha/<str:username>/<str:token>', views.redefinirSenha, name="redefinirSenha"),
path('register/', views.register, name = 'register'),
path('account_recovery/', views.recoverAccount, name = 'recoverAccount'),
path('redefine_password/<str:username>/<str:token>', views.redefinePassword, name="redefinePassword"),
]

0 comments on commit c4090b3

Please sign in to comment.