Skip to content

Commit 624aa04

Browse files
Merge pull request adeyosemanputra#185 from sumukhchitloor/master
Fixes Registration form issue
2 parents cf8cac4 + eba7a29 commit 624aa04

5 files changed

Lines changed: 100 additions & 21 deletions

File tree

app.log

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,3 +573,45 @@ WARNING:django.request:Not Found: /x
573573
WARNING:django.request:Not Found: /x
574574
WARNING:django.request:Not Found: /x
575575
WARNING:django.request:Not Found: /x
576+
WARNING:django.request:Not Found: /favicon.ico
577+
INFO:django.utils.autoreload:/home/toxin/Project/gsoc/pygoat/introduction/views.py changed, reloading.
578+
INFO:django.utils.autoreload:/home/toxin/Project/gsoc/pygoat/introduction/views.py changed, reloading.
579+
INFO:django.utils.autoreload:/home/toxin/Project/gsoc/pygoat/introduction/views.py changed, reloading.
580+
INFO:django.utils.autoreload:/home/toxin/Project/gsoc/pygoat/introduction/views.py changed, reloading.
581+
INFO:django.utils.autoreload:/home/toxin/Project/gsoc/pygoat/introduction/views.py changed, reloading.
582+
ERROR:django.request:Internal Server Error: /register
583+
Traceback (most recent call last):
584+
File "/usr/lib/python3/dist-packages/django/core/handlers/exception.py", line 47, in inner
585+
response = get_response(request)
586+
File "/usr/lib/python3/dist-packages/django/core/handlers/base.py", line 181, in _get_response
587+
response = wrapped_callback(request, *callback_args, **callback_kwargs)
588+
File "/home/toxin/Project/gsoc/pygoat/introduction/views.py", line 67, in register
589+
return render(request, 'registration/register.html', {'form': form})
590+
UnboundLocalError: local variable 'form' referenced before assignment
591+
INFO:django.utils.autoreload:/home/toxin/Project/gsoc/pygoat/introduction/views.py changed, reloading.
592+
ERROR:django.request:Internal Server Error: /register
593+
Traceback (most recent call last):
594+
File "/usr/lib/python3/dist-packages/django/core/handlers/exception.py", line 47, in inner
595+
response = get_response(request)
596+
File "/usr/lib/python3/dist-packages/django/core/handlers/base.py", line 181, in _get_response
597+
response = wrapped_callback(request, *callback_args, **callback_kwargs)
598+
File "/home/toxin/Project/gsoc/pygoat/introduction/views.py", line 62, in register
599+
form.save()
600+
AttributeError: 'RegistrationForm' object has no attribute 'save'
601+
INFO:django.utils.autoreload:/home/toxin/Project/gsoc/pygoat/introduction/views.py changed, reloading.
602+
INFO:django.utils.autoreload:/home/toxin/Project/gsoc/pygoat/introduction/views.py changed, reloading.
603+
INFO:django.utils.autoreload:/home/toxin/Project/gsoc/pygoat/introduction/views.py changed, reloading.
604+
INFO:django.utils.autoreload:/home/toxin/Project/gsoc/pygoat/introduction/views.py changed, reloading.
605+
WARNING:django.request:Not Found: /favicon.ico
606+
WARNING:django.request:Not Found: /introduction/home.html
607+
WARNING:django.request:Not Found: /introduction/home.html/
608+
WARNING:django.request:Not Found: /introduction/home.html/
609+
WARNING:django.request:Not Found: /introduction/home.html
610+
WARNING:django.request:Not Found: /introduction/homepage
611+
WARNING:django.request:Not Found: /introduction/
612+
INFO:django.utils.autoreload:/home/toxin/Project/gsoc/pygoat/introduction/views.py changed, reloading.
613+
WARNING:django.request:Not Found: /introduction/
614+
WARNING:django.request:Not Found: /introduction/home.html
615+
INFO:django.utils.autoreload:/home/toxin/Project/gsoc/pygoat/introduction/views.py changed, reloading.
616+
INFO:django.utils.autoreload:/home/toxin/Project/gsoc/pygoat/introduction/forms.py changed, reloading.
617+
WARNING:django.security.csrf:Forbidden (CSRF token missing or incorrect.): /admin/auth/user/

introduction/forms.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from django import forms
2+
from django.contrib.auth.forms import UserCreationForm
3+
from django.contrib.auth.models import User
4+
5+
6+
# Create your forms here.
7+
8+
class NewUserForm(UserCreationForm):
9+
email = forms.EmailField(required=True)
10+
11+
class Meta:
12+
model = User
13+
fields = ("username", "email", "password1", "password2")
14+
15+
def save(self, commit=True):
16+
user = super(NewUserForm, self).save(commit=False)
17+
user.email = self.cleaned_data['email']
18+
if commit:
19+
user.save()
20+
return user
Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
{% extends "introduction/base.html" %}
2-
{% block content %}
3-
{% load crispy_forms_tags %}
2+
{% block content %}
43

5-
<div class="jumbotron">
6-
<div class="contaniner">
7-
<form method="post">
8-
{% csrf_token %}
9-
{{form|crispy}}
10-
<button type="submit" class="btn btn-info btn-info">Register</button>
11-
</form>
12-
</div>
4+
{% load crispy_forms_tags %}
5+
6+
<!--Register-->
7+
<div class="container py-5">
8+
<h1>Register</h1>
9+
<form method="POST">
10+
{% csrf_token %}
11+
{{ register_form|crispy }}
12+
<button class="btn btn-primary" type="submit">Register</button>
13+
</form>
14+
<p class="text-center">If you already have an account, <button type="submit" class="btn btn-info" style="margin-bottom:20px"><a href="/login" style="color: rgb(255, 255, 255); text-decoration: none;">Login</a></button>
15+
instead.</p>
1316
</div>
17+
1418
{% endblock %}

introduction/views.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import os
1212
from hashlib import md5
1313
import datetime
14+
from .forms import NewUserForm
15+
from django.contrib import messages
1416
#*****************************************Lab Requirements****************************************************#
1517

1618
from .models import FAANG,info,login,comments,otp
@@ -38,17 +40,28 @@
3840
import requests
3941
#*****************************************Login and Registration****************************************************#
4042

41-
4243
def register(request):
43-
if request.method=="POST":
44-
form = UserCreationForm(request.POST)
45-
if form.is_valid():
46-
form.save()
47-
return redirect("login")
48-
49-
else:
50-
form=UserCreationForm()
51-
return render(request,"registration/register.html",{"form":form,})
44+
if request.method == "POST":
45+
form = NewUserForm(request.POST)
46+
if form.is_valid():
47+
user = form.save()
48+
login(request, user)
49+
messages.success(request, "Registration successful." )
50+
return redirect('/')
51+
messages.error(request, "Unsuccessful registration. Invalid information.")
52+
form = NewUserForm()
53+
return render (request=request, template_name="registration/register.html", context={"register_form":form})
54+
55+
# def register(request):
56+
# if request.method=="POST":
57+
# form = UserCreationForm(request.POST)
58+
# if form.is_valid():
59+
# form.save()
60+
# return redirect("login")
61+
62+
# else:
63+
# form=UserCreationForm()
64+
# return render(request,"registration/register.html",{"form":form,})
5265

5366
def home(request):
5467
if request.user.is_authenticated:

lib/python3.10/site-packages/php_wsgi/php_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def __call__(self,environ,start_response):
9999
return self.app(environ,start_response)
100100
content_type = 'text/{}'.format(self._get_content_type(file_location))
101101
if verbose:
102-
print 'SERVING STATIC FILE {0}'.format(file_location)
102+
print ('SERVING STATIC FILE {0}'.format(file_location))
103103
start_response('200',[('content-type',content_type),('User-Agent','Python-php-static')])
104104
return open(file_location,'r').read()
105105
else:

0 commit comments

Comments
 (0)