Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementado fluxo com templates para login #30

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions backend/devpro/base/templates/base/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<title>{% block title %}Título Padrão{% endblock %}</title>
</head>
<body>
{% block body %}{% endblock body %}
</body>
</html>
20 changes: 20 additions & 0 deletions backend/devpro/base/templates/base/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% extends 'base/base.html' %}
{% block title %}Página de Template Django da DevPro{% endblock title %}

{% block body %}
<h1>Página de Template Django da DevPro</h1>
<p>Essa página pode ser alterada de acordo com a home do seu projeto</p>
<h2>Página Login</h2>
<p>Esse projeto já veio com login do Django configurado:</p>
{% if request.user.is_authenticated %}
<a href="{% url 'password_change' %}">Alterar senha</a>
<form action="{% url 'logout' %}" method="post">
{% csrf_token %}
<input type="submit" value="Sair">
</form>

{% else %}
<a href="{% url 'login' %}">Página de Login</a>
{% endif %}

{% endblock body %}
11 changes: 11 additions & 0 deletions backend/devpro/base/templates/registration/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends 'base/base.html' %}
{% block title %}Página de Login{% endblock title %}
{% block body %}
<h1>Página de Login</h1>
<form action="{% url 'login' %}" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Logar">
</form>
<a href="{% url 'password_reset' %}">Esqueceu a senha</a>
{% endblock body %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends 'base/base.html' %}
{% load i18n static %}
{% block title %}Página de Recuperação de senha{% endblock title %}
{% block body %}
<h1>{% translate 'Password change' %}</h1>
<p>{% translate 'Your password was changed.' %}</p>

{% endblock body %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{% extends 'base/base.html' %}
{% load i18n static %}
{% block title %}Página de Reset de senha{% endblock title %}
{% block body %}
<h1>Página de Alteração de senha</h1>
<div id="content-main">

<form method="post">{% csrf_token %}
<div>
{% if form.errors %}
<p class="errornote">
{% blocktranslate count counter=form.errors.items|length %}Please correct the error below.
{% plural %}Please correct the errors below.{% endblocktranslate %}
</p>
{% endif %}


<p>{% translate 'Please enter your old password, for security’s sake, and then enter your new password twice so we can verify you typed it in correctly.' %}</p>

<fieldset class="module aligned wide">

<div class="form-row">
{{ form.old_password.errors }}
<div class="flex-container">{{ form.old_password.label_tag }} {{ form.old_password }}</div>
</div>

<div class="form-row">
{{ form.new_password1.errors }}
<div class="flex-container">{{ form.new_password1.label_tag }} {{ form.new_password1 }}</div>
{% if form.new_password1.help_text %}
<div class="help"{% if form.new_password1.id_for_label %}
id="{{ form.new_password1.id_for_label }}_helptext"{% endif %}>{{ form.new_password1.help_text|safe }}</div>
{% endif %}
</div>

<div class="form-row">
{{ form.new_password2.errors }}
<div class="flex-container">{{ form.new_password2.label_tag }} {{ form.new_password2 }}</div>
{% if form.new_password2.help_text %}
<div class="help"{% if form.new_password2.id_for_label %}
id="{{ form.new_password2.id_for_label }}_helptext"{% endif %}>{{ form.new_password2.help_text|safe }}</div>
{% endif %}
</div>

</fieldset>

<div class="submit-row">
<input type="submit" value="{% translate 'Change my password' %}" class="default">
</div>

</div>
</form>
</div>

{% endblock body %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends 'base/base.html' %}
{% load i18n static %}
{% block title %}Página de Recuperação de senha{% endblock title %}
{% block body %}
<h1>{% translate 'Password reset' %}</h1>
<p>{% translate "Your password has been set. You may go ahead and log in now." %}</p>

<p><a href="{{ login_url }}">{% translate 'Log in' %}</a></p>

{% endblock body %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{% extends 'base/base.html' %}
{% load i18n static %}
{% block title %}Página de Reset de Senha{% endblock title %}
{% block body %}
<h1>{% translate 'Password reset confirmation' %}</h1>
{% if validlink %}

<p>{% translate "Please enter your new password twice so we can verify you typed it in correctly." %}</p>

<form method="post">{% csrf_token %}
<input type="hidden" autocomplete="username" value="{{ form.user.get_username }}">
<div class="form-row field-password1">
{{ form.new_password1.errors }}
<div class="flex-container">
<label for="id_new_password1">{% translate 'New password:' %}</label>
{{ form.new_password1 }}
</div>
</div>
<div class="form-row field-password2">
{{ form.new_password2.errors }}
<div class="flex-container">
<label for="id_new_password2">{% translate 'Confirm password:' %}</label>
{{ form.new_password2 }}
</div>
</div>
<div class="submit-row">
<input type="submit" value="{% translate 'Change my password' %}">
</div>
</form>

{% else %}

<p>{% translate "The password reset link was invalid, possibly because it has already been used. Please request a new password reset." %}</p>

{% endif %}

{% endblock body %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends 'base/base.html' %}
{% load i18n static %}
{% block title %}Página de Recuperação de senha{% endblock title %}
{% block body %}
<h1>{% translate 'Password reset' %}</h1>
<p>{% translate 'We’ve emailed you instructions for setting your password, if an account exists with the email you entered. You should receive them shortly.' %}</p>

<p>{% translate 'If you don’t receive an email, please make sure you’ve entered the address you registered with, and check your spam folder.' %}</p>


{% endblock body %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends 'base/base.html' %}
{% load i18n static %}
{% block title %}Página de Recuperação de senha{% endblock title %}
{% block body %}
<h1>{% translate 'Password reset' %}</h1>
<p>{% translate 'Forgotten your password? Enter your email address below, and we’ll email instructions for setting a new one.' %}</p>

<form method="post">{% csrf_token %}
<div>
<p>{{ form.email.errors }}</p>
<div>
<label for="id_email">{% translate 'Email address:' %}</label>
{{ form.email }}
</div>
</div>

<input type="submit" value="{% translate 'Reset my password' %}">

</form>

{% endblock body %}
3 changes: 3 additions & 0 deletions backend/devpro/base/tests/test_home.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def test_home_status(client):
resp = client.get('/')
assert resp.status_code == 200
6 changes: 6 additions & 0 deletions backend/devpro/base/tests/test_login.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.urls import reverse


def test_login_page_status(client):
resp = client.get(reverse('login'))
assert resp.status_code == 200
7 changes: 7 additions & 0 deletions backend/devpro/base/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.urls import path

from devpro.base import views

urlpatterns = [
path('', views.home, name='home'),
]
6 changes: 5 additions & 1 deletion backend/devpro/base/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# from django.shortcuts import render
from django.shortcuts import render


# Create your views here.

def home(request):
return render(request, 'base/home.html')
7 changes: 6 additions & 1 deletion backend/devpro/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@
# Internationalization
# https://docs.djangoproject.com/en/5.0/topics/i18n/

LANGUAGE_CODE = 'en-us'
LOGOUT_REDIRECT_URL = LOGIN_REDIRECT_URL = '/'

LANGUAGE_CODE = 'pt-br'

TIME_ZONE = 'UTC'

Expand All @@ -117,6 +119,9 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.0/howto/static-files/

if DEBUG:
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"


AWS_STORAGE_BUCKET_NAME = config('AWS_STORAGE_BUCKET_NAME', default='').strip()

Expand Down
4 changes: 3 additions & 1 deletion backend/devpro/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path
from django.urls import path, include

urlpatterns = [
path('admin/', admin.site.urls),
path('', include('devpro.base.urls')),
path('accounts/', include('django.contrib.auth.urls')),
]

if settings.AWS_STORAGE_BUCKET_NAME == '':
Expand Down
Loading