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

criado formulário de login close #47 #48

Merged
merged 1 commit into from
Nov 20, 2023
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
47 changes: 47 additions & 0 deletions pypro/base/templates/registration/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{% extends 'base/base.html' %}
{% load static %}
{% block title %}Python Pro - Login{% endblock title %}
{% block body %}
<div class="container">
<div class="row">
<div class="col">

{% if form.errors %}
<p>Your username and password didn't match. Please try again.</p>
{% endif %}

{% if next %}
{% if user.is_authenticated %}
<p>Your account doesn't have access to this page. To proceed,
please login with an account that has access.</p>
{% else %}
<p>Please login to see this page.</p>
{% endif %}
{% endif %}

<form method="post" action="{% url 'login' %}">
{% csrf_token %}
<table>
<tr>
<td>{{ form.username.label_tag }}</td>
<td>{{ form.username }}</td>
</tr>
<tr>
<td>{{ form.password.label_tag }}</td>
<td>{{ form.password }}</td>
</tr>
</table>

<input type="submit" value="login">
<input type="hidden" name="next" value="{{ next }}">
</form>

{# Assumes you set up the password_reset view in your URLconf #}
<p><a href="{% url 'password_reset' %}">Esqueceu sua senha?</a></p>



</div>
</div>
</div>
{% endblock body %}
32 changes: 32 additions & 0 deletions pypro/base/tests/test_login.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import pytest
from django.urls import reverse
from model_mommy import mommy


@pytest.fixture
def resp(client, db):
return client.get(reverse('login'))


def test_login_form_page(resp):
assert resp.status_code == 200


@pytest.fixture
def usuario(db, django_user_model):
usuario_modelo = mommy.make(django_user_model)
senha = 'senha'
usuario_modelo.set_password(senha)
usuario_modelo.save()
usuario_modelo.senha_plana = senha
return usuario_modelo


@pytest.fixture
def resp_post(client, usuario):
return client.post(reverse('login'), {'username': usuario.email, 'password': usuario.senha_plana})


def test_login_redirect(resp_post):
assert resp_post.status_code == 302
assert resp_post.url == reverse('modulos:indice')
4 changes: 4 additions & 0 deletions pypro/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@
ALLOWED_HOSTS = ['*']

AUTH_USER_MODEL = 'base.User'

LOGIN_REDIRECT_URL = '/modulos/'

# Application definition


INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
Expand Down
1 change: 1 addition & 0 deletions pypro/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

urlpatterns = [
path('admin/', admin.site.urls),
path('contas/', include('django.contrib.auth.urls')),
path('', include('pypro.base.urls')),
path('aperitivos/', include('pypro.aperitivos.urls')),
path('modulos/', include('pypro.modulos.urls')),
Expand Down
Loading