Commit 084acdc4 authored by Jomaro Rodrigues's avatar Jomaro Rodrigues

login feito

parent 1c8687da
......@@ -8,6 +8,7 @@ url = "https://pypi.python.org/simple"
[dev-packages]
coverage = "*"
ipython = "*"
[packages]
......
This diff is collapsed.
......@@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/1.9/ref/settings/
"""
import os
from django.contrib import messages
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
......@@ -39,8 +40,10 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'django_extensions',
'widget_tweaks',
'adega',
'public',
'uploads'
]
......@@ -88,6 +91,11 @@ DATABASES = {
}
AUTHENTICATION_BACKENDS = ['public.auth.EmailBackend']
LOGIN_URL = 'public:index'
# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators
......@@ -121,6 +129,11 @@ USE_L10N = True
USE_TZ = True
MESSAGE_TAGS = {
messages.ERROR: 'danger'
}
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/
......
......@@ -35,6 +35,24 @@ h1#title {
}
/* ========================================= MESSAGES */
.alert {
border-radius: 0;
}
#messages {
margin-left: -15px;
margin-right: -15px;
margin-bottom: 1.7em;
}
#messages div[role=alert] {
margin: 0;
}
/* ========================================= FOOTER */
footer {
background-color: #263646;
......@@ -82,6 +100,7 @@ footer h3 {
.sidebar li a {
flex-grow: 1;
outline: none;
}
.sidebar .drop {
......@@ -143,3 +162,8 @@ footer h3 {
.sub-menu {
border-left:5px solid #4a7d73;
}
.content {
padding: 2em;
}
\ No newline at end of file
......@@ -20,7 +20,7 @@
   
{% endcomment %}
<div class="col-md-1">
<span class="navbar-text"><a href="#">Sair</a></span>
<span class="navbar-text"><a href="{% url 'logout' %}">Sair</a></span>
</div>
</div>
</nav>
......
......@@ -27,10 +27,21 @@
<aside class="col-md-2 sidebar">
{% include 'adega/sidebar.html' %}
</aside>
<section id="content" class="col-md-10">
{% block content %}
<section class="col-md-10">
{% if messages %}
<div id="messages">
{% for message in messages %}
<div class="alert alert-{{ message.tags }}" role="alert">
<div class="container">{{ message }}</div>
</div>
{% endfor %}
</div>
{% endif %}
<div id="content">
{% block content %}
{% endblock %}
{% endblock %}
</div>
</section>
</div>
</section>
......
......@@ -8,7 +8,9 @@ urlpatterns = [
url(r'^uploads/', include('uploads.urls', namespace='uploads')),
url(r'^login/', views.login, name='login'),
url(r'^public/', include('public.urls', namespace='public')),
url(r'^logout/$', views.logout, name='logout'),
url(r'^admin/', admin.site.urls),
]
from django.shortcuts import render, redirect
from django.contrib.auth.decorators import login_required
from django.contrib.auth import logout as process_logout
@login_required
def dashboard(request):
return render(request, 'adega/dashboard.html', {'title': 'Dashboard'})
def login(request):
@login_required
def logout(request):
process_logout(request)
return render(request, 'adega/login.html', {})
return redirect('public:index')
from django.contrib.auth import get_user_model
from django.contrib.auth.backends import ModelBackend
from django.contrib import messages
class EmailBackend(ModelBackend):
def authenticate(self, username=None, password=None, **kwargs):
UserModel = get_user_model()
print(kwargs)
try:
user = UserModel.objects.get(email=username)
except UserModel.DoesNotExist:
return None
else:
if user.check_password(password):
if not user.is_active:
if 'request' in kwargs:
messages.warning(kwargs['request'],
'Seu usuário está desativado, contate a equipe de administração')
else:
print('HandmadeWarning: this user is not active')
return None
return user
return None
from django import forms
class LoginForm(forms.Form):
email = forms.EmailField(label='Email')
password = forms.CharField(max_length=100, widget=forms.PasswordInput)
{% load static %}<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="icon" href="{% static 'favicon.ico' %}" type="image/x-icon" />
<title>{% if title %}{{ title}} | {% endif %}A.D.E.G.A.</title>
<link rel="stylesheet" href="{% static 'flatly/bootstrap.min.css' %}"/>
<link href="https://use.fontawesome.com/releases/v5.0.8/css/all.css" rel="stylesheet">
<link rel="stylesheet" href="{% static 'fontawesome5/css/fa-regular.min.css' %}"/>
<link rel="stylesheet" href="{% static 'adega/css/styles.css' %}"/>
<script defer src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script defer src="{% static 'bootstrap4/js/bootstrap.bundle.min.js' %}"></script>
<script defer src="{% static 'adega/js/scripts.js' %}"></script>
<link rel="preload" href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic" as="style"/>
</head>
<body>
<section id="header">
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<span class="navbar-brand mr-auto">ADEGA</span>
</nav>
</section>
{% if messages %}
<div class="messages">
{% for message in messages %}
<div class="alert alert-{{ message.tags }}" role="alert">
<div class="container">{{ message }}</div>
</div>
{% endfor %}
</div>
{% endif %}
<section id="wrap-page" class="container">
{% block content %}
{% endblock content %}
</section>
<footer>
<div class="container">
<div class="row">
<div class="col-md-4">
<h3>Links</h3>
<ul>
<li><a href="http://pet.inf.ufpr.br/projetos/adega.html">Página oficial do projeto</a></li>
<li><a href="http://gitlab.c3sl.ufpr.br/pet/adega">Código fonte</a></li>
<li><a href="#">Desenvolvedores</a></li>
</ul>
</div>
<div class="col-md-4 offset-md-4">
<h3>Mantido por</h3>
<a href="http://pet.inf.ufpr.br">
<img src="/static/pet/logo_preto.png" width="75%">
</a>
</div>
</div>
</div>
</footer>
</body>
</html>
\ No newline at end of file
{% extends 'public/base.html' %}
{% load widget_tweaks %}
{% block content %}
<div class="row">
<section class="col-md-8 content">
<h2>O projeto adega</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Integer auctor pellentesque lacus eget tincidunt.
Nam eu blandit est, sed vestibulum arcu. Phasellus ut tempus sapien.
Nunc vitae justo quis elit mattis ullamcorper eu ut lorem.
Sed ut interdum enim. Maecenas orci lectus, euismod sed
gravida fermentum, pretium non dui. Mauris vehicula nisl in
suscipit lacinia.</p>
<p>Sed a risus eu sapien dictum faucibus a sed massa.
Curabitur non sapien non ipsum tincidunt sodales sed eu libero.
Vestibulum ac libero laoreet, fermentum dui id, maximus ex.
Ut sit amet turpis nulla. Sed ac sapien tortor.
Donec vel sollicitudin risus. Lorem ipsum dolor sit amet,
consectetur adipiscing elit.</p>
<p>Mauris consequat justo sit amet turpis lacinia congue vel at sapien.
In orci orci, tincidunt sed velit quis, posuere feugiat eros.
Morbi volutpat eros a sagittis dictum. Integer nec leo eget felis
mattis venenatis. Pellentesque sed ligula commodo augue lobortis
accumsan ac tempor velit. Duis pharetra mattis orci, commodo
bibendum ex luctus at. Nullam nisl est, mattis id augue dignissim,
varius maximus quam.</p>
</section>
<section id="content" class="col-md-4 content">
<h2>Login</h2>
<form method="POST">
{% csrf_token %}
{% if form.errors %}
<ul>
{% for error in form.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
<div class="form-group">
<label for="{{ form.email.id_for_label }}">{{ form.email.label }}</label>
{% if form.email.errors %}
<ul>
{% for error in form.email.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
{{ form.email|add_class:"form-control" }}
</div>
<div class="form-group">
<label for="{{ form.password.id_for_label }}">{{ form.password.label }}</label>
{% if form.password.errors %}
<ul>
{% for error in form.password.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
{{ form.password|add_class:"form-control" }}
</div>
<input type="submit" class="btn btn-primary" value="Entrar"/>
</form>
</section>
</div>
{% endblock content %}
from django.conf.urls import url
from public import views
urlpatterns = [
url(r'^$', views.index, name="index"),
]
\ No newline at end of file
from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login
from public.forms import LoginForm
def index(request):
if request.user.is_authenticated:
return redirect('dashboard')
if request.method == 'POST':
form = LoginForm(request.POST)
if form.is_valid():
email = form.cleaned_data['email']
password = form.cleaned_data['password']
user = authenticate(request, username=email, password=password)
if user is not None:
login(request, user)
return redirect(request.GET.get('next', 'dashboard'))
else:
return redirect('public:index')
return render(request, 'public/index.html', {'form': LoginForm()})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment