Skip to content

Commit

Permalink
Auto login after register, solved a visual error
Browse files Browse the repository at this point in the history
The error was that the invalid-feedback of forms wasn't displayed. The problem was solved with that link : twbs/bootstrap#23454 (comment)
  • Loading branch information
SpicyPaper committed Mar 14, 2019
1 parent 767fc83 commit 27ef0a5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 38 deletions.
18 changes: 18 additions & 0 deletions PayPixPlace/paypixplaceapp/migrations/0010_auto_20190314_1348.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.1.7 on 2019-03-14 12:48

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('paypixplaceapp', '0009_auto_20190313_1121'),
]

operations = [
migrations.AlterField(
model_name='user',
name='email',
field=models.CharField(max_length=255, unique=True),
),
]
2 changes: 1 addition & 1 deletion PayPixPlace/paypixplaceapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Color(models.Model):
hex = models.CharField(max_length=9)

class User(AbstractUser):
email = models.CharField(max_length=255)
email = models.CharField(max_length=255, unique=True)
password = models.CharField(max_length=255)
pix = models.IntegerField(default=200)
max_ammo = models.IntegerField(default=3)
Expand Down
3 changes: 3 additions & 0 deletions PayPixPlace/paypixplaceapp/static/paypixplaceapp/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.invalid-feedback {
display: block;
}
32 changes: 1 addition & 31 deletions PayPixPlace/users/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,34 +45,4 @@ class Meta:
'email',
'first_name',
'last_name'
)

"""
class CreateCanvas(forms.ModelForm):
CHOICES=[(0,'Public'),
(1,'Community'),
(2,'Private')]
place = forms.ChoiceField(choices=CHOICES, widget=forms.RadioSelect, initial=1)
class Meta:
model = Canvas
fields = ( 'name', 'theme', 'width', 'place', 'is_profit_on' )
labels = {
'is_profit_on': 'Enable profit for 250 PIX! - You will get 10% of the PIX that users spent on this canvas, if this is enabled!',
}
def __init__(self, *args, **kwargs):
super(CreateCanvas, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_method = 'POST'
self.helper.form_action = './'
self.helper.layout = Layout(
PrependedText('name', '<i class="fas fa-user"></i>'),
PrependedText('theme', '<i class="fas fa-book"></i>'),
PrependedText('width', '<i class="fas fa-arrows-alt-h"></i>'),
'is_profit_on',
InlineRadios('place', css_class='p-0'),
StrictButton('Create Canvas', type='submit', css_class='btn-outline-info'),
)
"""
)
18 changes: 12 additions & 6 deletions PayPixPlace/users/views.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
from django.shortcuts import render, redirect
from .forms import RegisterForm, UpdateForm
from django.contrib import messages
from django.contrib.auth import authenticate, login
from django.contrib.auth.decorators import login_required
from django.shortcuts import redirect, render

from .forms import RegisterForm, UpdateForm

def register(request):
if request.method == "POST":
form = RegisterForm(request.POST)
if form.is_valid():
form.save()
messages.success(request, f'Your account has been created! You are now able to log in')
return redirect('login')
new_user = form.save()
messages.success(request, "Thank you for registering. You are now logged in.")
new_user = authenticate(username=form.cleaned_data['username'],
password=form.cleaned_data['password1'],
)
login(request, new_user)
return redirect('paypixplace-home')
else:
form = RegisterForm()

Expand All @@ -30,4 +36,4 @@ def profile(request):
'title': 'Profile',
'u_form': u_form
}
return render(request, 'users/profile.html', context)
return render(request, 'users/profile.html', context)

0 comments on commit 27ef0a5

Please sign in to comment.