saving works now
This commit is contained in:
0
backend/accounts/__init__.py
Normal file
0
backend/accounts/__init__.py
Normal file
3
backend/accounts/admin.py
Normal file
3
backend/accounts/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
6
backend/accounts/apps.py
Normal file
6
backend/accounts/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class AccountsConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'backend.accounts'
|
||||
30
backend/accounts/forms.py
Normal file
30
backend/accounts/forms.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from django import forms
|
||||
from django.contrib.auth.forms import UserCreationForm
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
|
||||
class SignupForm(UserCreationForm):
|
||||
first_name = forms.CharField(
|
||||
label='Nome',
|
||||
max_length=30,
|
||||
required=False,
|
||||
widget=forms.TextInput(attrs={'autofocus': 'autofocus'})
|
||||
)
|
||||
last_name = forms.CharField(label='Sobrenome', max_length=30, required=False) # noqa E501
|
||||
username = forms.CharField(label='Usuário', max_length=150)
|
||||
email = forms.CharField(
|
||||
label='E-mail',
|
||||
max_length=254,
|
||||
help_text='Requerido. Informe um e-mail válido.',
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = (
|
||||
'first_name',
|
||||
'last_name',
|
||||
'username',
|
||||
'email',
|
||||
'password1',
|
||||
'password2'
|
||||
)
|
||||
0
backend/accounts/migrations/__init__.py
Normal file
0
backend/accounts/migrations/__init__.py
Normal file
3
backend/accounts/models.py
Normal file
3
backend/accounts/models.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
62
backend/accounts/templates/accounts/login.html
Normal file
62
backend/accounts/templates/accounts/login.html
Normal file
@@ -0,0 +1,62 @@
|
||||
{% extends "base_login.html" %}
|
||||
{% load static %}
|
||||
|
||||
{% block title %}Login{% endblock title %}
|
||||
|
||||
{% block content %}
|
||||
<div class="col-md-8">
|
||||
<div class="card-group">
|
||||
<div class="card p-4">
|
||||
<div class="card-body">
|
||||
<h1>Login</h1>
|
||||
<!-- <p class="text-muted">Sign In to your account</p> -->
|
||||
|
||||
{% if form.errors %}
|
||||
{% for error in form.non_field_errors %}
|
||||
<p class="alert alert-danger" role="alert"><span style="font-weight:bold">{{ error }}</span></p>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
<form action="." method="POST">
|
||||
{% csrf_token %}
|
||||
<div class="input-group mb-3">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">
|
||||
<i class="icon-user"></i>
|
||||
</span>
|
||||
</div>
|
||||
<input class="form-control" name="username" type="text" placeholder="Usuário" autofocus>
|
||||
</div>
|
||||
<div class="input-group mb-4">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">
|
||||
<i class="icon-lock"></i>
|
||||
</span>
|
||||
</div>
|
||||
<input class="form-control" name="password" type="password" placeholder="Senha">
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">
|
||||
<button class="btn btn-primary px-4" type="submit">Login</button>
|
||||
</div>
|
||||
<div class="col-8 text-right">
|
||||
<a class="btn btn-link px-0" href="">Esqueci minha senha</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="card text-white bg-primary py-5 d-md-down-none" style="width:44%; justify-content: center !important">
|
||||
<div class="card-body text-center" style="flex: none;">
|
||||
<div>
|
||||
<img src="{% static 'img/django-logo-negative.png' %}" alt="django-logo-negative.png" width="150px">
|
||||
<h2>Cadastre-se</h2>
|
||||
<p>Guia de autenticação do Django.</p>
|
||||
<a class="btn btn-primary active mt-3" href="{% url 'signup' %}">Cadastre-se</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
65
backend/accounts/templates/accounts/signup.html
Normal file
65
backend/accounts/templates/accounts/signup.html
Normal file
@@ -0,0 +1,65 @@
|
||||
{% extends "base_login.html" %}
|
||||
{% load static %}
|
||||
{% load widget_tweaks %}
|
||||
|
||||
{% block title %}Signup{% endblock title %}
|
||||
|
||||
{% block content %}
|
||||
<div class="col-md-10">
|
||||
<div class="card-group">
|
||||
<div class="card p-4">
|
||||
<div class="card-body">
|
||||
<h1>Cadastre-se</h1>
|
||||
<p class="text-muted">Crie sua conta.</p>
|
||||
|
||||
<form action="." method="POST">
|
||||
{% csrf_token %}
|
||||
{% for field in form.visible_fields %}
|
||||
<div class="form-group{% if field.errors %} has-error {% endif %}">
|
||||
<label>
|
||||
{% if field.field.required %}
|
||||
<span class="required">{{ field.label }} </span>
|
||||
{% else %}
|
||||
{{ field.label }}
|
||||
{% endif %}
|
||||
</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">
|
||||
{% if field.name == 'email' %}
|
||||
@
|
||||
{% elif field.name == 'password1' or field.name == 'password2' %}
|
||||
<i class="icon-lock"></i>
|
||||
{% elif field.name == 'username' %}
|
||||
<i class="icon-user"></i>
|
||||
{% else %}
|
||||
<i class="icon-emotsmile"></i>
|
||||
{% endif %}
|
||||
</span>
|
||||
</div>
|
||||
{% render_field field class="form-control" placeholder=field.label %}
|
||||
</div>
|
||||
<span class="text-muted">{{ field.help_text }}</span>
|
||||
{% for error in field.errors %}
|
||||
<br> <span class="text-danger">{{ error }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
<button class="btn btn-block btn-success" type="submit">Cadastrar</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card text-white bg-primary py-5 d-md-down-none" style="width:44%; justify-content: center !important">
|
||||
<div class="card-body text-center" style="flex: none;">
|
||||
<div>
|
||||
<img src="{% static 'img/django-logo-negative.png' %}" alt="django-logo-negative.png" width="150px">
|
||||
<h2>Login</h2>
|
||||
<p>Faça login.</p>
|
||||
<a class="btn btn-primary active mt-3" href="{% url 'login' %}">Login</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
3
backend/accounts/tests.py
Normal file
3
backend/accounts/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
13
backend/accounts/urls.py
Normal file
13
backend/accounts/urls.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from django.contrib.auth.views import LoginView, LogoutView
|
||||
from django.urls import path
|
||||
from backend.accounts import views as v
|
||||
|
||||
urlpatterns = [
|
||||
path(
|
||||
'login/',
|
||||
LoginView.as_view(template_name='accounts/login.html'),
|
||||
name='login'
|
||||
),
|
||||
path('logout/', LogoutView.as_view(), name='logout'),
|
||||
path('signup/', v.SignUpView.as_view(), name='signup'),
|
||||
]
|
||||
9
backend/accounts/views.py
Normal file
9
backend/accounts/views.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from django.urls import reverse_lazy
|
||||
from django.views.generic import CreateView
|
||||
from backend.accounts.forms import SignupForm
|
||||
|
||||
|
||||
class SignUpView(CreateView):
|
||||
form_class = SignupForm
|
||||
success_url = reverse_lazy('login')
|
||||
template_name = 'accounts/signup.html'
|
||||
Reference in New Issue
Block a user