sexta parte 2
This commit is contained in:
0
accounts/__init__.py
Normal file
0
accounts/__init__.py
Normal file
3
accounts/admin.py
Normal file
3
accounts/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
14
accounts/forms.py
Normal file
14
accounts/forms.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from django import forms
|
||||
from django.contrib.auth.forms import get_user_model
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
class AccountSignUpForm(forms.ModelForm):
|
||||
password = forms.CharField(max_length=20,label='Senha',widget=forms.PasswordInput)
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ['username', 'email', 'password']
|
||||
|
||||
|
||||
|
||||
0
accounts/migrations/__init__.py
Normal file
0
accounts/migrations/__init__.py
Normal file
3
accounts/models.py
Normal file
3
accounts/models.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
3
accounts/tests.py
Normal file
3
accounts/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
4
accounts/urls.py
Normal file
4
accounts/urls.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from django.urls import path
|
||||
from accounts.views import AccountCreateView
|
||||
|
||||
urlpatterns = [ path('accounts/signup/', AccountCreateView.as_view(), name='signup')]
|
||||
24
accounts/views.py
Normal file
24
accounts/views.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from django.shortcuts import render
|
||||
from django.views.generic.edit import CreateView
|
||||
from django.urls import reverse_lazy
|
||||
from django.contrib.auth.hashers import make_password
|
||||
from django.contrib.auth.forms import get_user_model
|
||||
from django.contrib import messages
|
||||
from accounts.forms import AccountSignUpForm
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
class AccountCreateView(CreateView):
|
||||
model = User
|
||||
form_class = AccountSignUpForm
|
||||
template_name = 'registration/signup_from.html'
|
||||
form_class = AccountSignUpForm
|
||||
success_url = reverse_lazy('login')
|
||||
sucess_message = 'Conta criada com sucesso!'
|
||||
|
||||
def form_valid(self, form):
|
||||
form.instance.password = make_password(form.cleaned_data['password'])
|
||||
form.save()
|
||||
messages.success(self.request, 'Conta criada com sucesso!')
|
||||
return super(AccountCreateView, self).form_valid(form)
|
||||
|
||||
Reference in New Issue
Block a user