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

Resolve #153. Possibilita o usuário editar seus dados #163

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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 brasilio_auth/templates/brasilio_auth/profile_update_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "base.html" %}

{% block content %}

<form method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Update">
</form>

{% endblock %}
5 changes: 3 additions & 2 deletions brasilio_auth/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from django.contrib.auth import views as auth_views
from django.urls import path

from brasilio_auth.views import CreateUserView

from brasilio_auth.views import CreateUserView, ProfileUpdate
from django.contrib.auth.decorators import login_required

views_config = {
'login': auth_views.LoginView.as_view(template_name='brasilio_auth/login.html'),
Expand Down Expand Up @@ -36,4 +36,5 @@
path('troca-senha/atualizada/', views_config['password_reset_complete'], name='password_reset_complete'),
path('logout/', views_config['logout'], name='logout'),
path('entrar/', CreateUserView.as_view(), name='sign_up'),
path('editar-perfil', login_required(ProfileUpdate.as_view()), name='profile_update_form')
)
15 changes: 15 additions & 0 deletions brasilio_auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
from django.contrib.auth import get_user_model, login
from django.views.generic.edit import CreateView
from django.shortcuts import redirect
from django.views.generic.edit import UpdateView
from django.contrib.auth.models import User
from django.urls import reverse

from brasilio_auth.forms import UserCreationForm

Expand All @@ -24,3 +27,15 @@ def form_valid(self, *args, **kwargs):
login(self.request, self.object)
url = self.request.POST.get('next', None) or self.success_url
return redirect(url)


class ProfileUpdate(UpdateView):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Como para acessar essa página o usuário precisa estar logado, precisamos adicionar aqui o decorator login_required - veja exemplo na documentação do Django.

model = User
fields = ['first_name', 'last_name', 'username']
template_name = 'brasilio_auth/profile_update_form.html'

def get_object(self, queryset=None):
return self.request.user

def get_success_url(self):
return reverse('brasilio_auth:profile_update_form')
43 changes: 43 additions & 0 deletions core/migrations/0015_auto_20181117_1827.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Generated by Django 2.1.3 on 2018-11-17 18:27

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('core', '0014_auto_20180908_1902'),
]

operations = [
migrations.AlterField(
model_name='field',
name='frontend_filter',
field=models.BooleanField(blank=True, default=False),
),
migrations.AlterField(
model_name='field',
name='has_choices',
field=models.BooleanField(blank=True, default=False),
),
migrations.AlterField(
model_name='field',
name='null',
field=models.BooleanField(blank=True, default=True),
),
migrations.AlterField(
model_name='field',
name='obfuscate',
field=models.BooleanField(blank=True, default=False),
),
migrations.AlterField(
model_name='field',
name='show',
field=models.BooleanField(blank=True, default=True),
),
migrations.AlterField(
model_name='field',
name='show_on_frontend',
field=models.BooleanField(blank=True, default=False),
),
]
1 change: 1 addition & 0 deletions core/templates/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<i class="material-icons right">arrow_drop_down</i>
</a></li>
<ul id="{{id_prefix}}_authenticated-dropdown" class="dropdown-content">
<li><a href="{% url 'brasilio_auth:profile_update_form' %}"> Editar perfil</a></li>
<li><a href="{% url 'brasilio_auth:logout' %}">Logout</a></li>
</ul>

Expand Down