Skip to content

Commit

Permalink
Merge pull request adeyosemanputra#185 from sumukhchitloor/master
Browse files Browse the repository at this point in the history
Fixes Registration form issue
  • Loading branch information
adeyosemanputra authored Feb 23, 2023
2 parents cf8cac4 + eba7a29 commit 624aa04
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 21 deletions.
42 changes: 42 additions & 0 deletions app.log
Original file line number Diff line number Diff line change
Expand Up @@ -573,3 +573,45 @@ WARNING:django.request:Not Found: /x
WARNING:django.request:Not Found: /x
WARNING:django.request:Not Found: /x
WARNING:django.request:Not Found: /x
WARNING:django.request:Not Found: /favicon.ico
INFO:django.utils.autoreload:/home/toxin/Project/gsoc/pygoat/introduction/views.py changed, reloading.
INFO:django.utils.autoreload:/home/toxin/Project/gsoc/pygoat/introduction/views.py changed, reloading.
INFO:django.utils.autoreload:/home/toxin/Project/gsoc/pygoat/introduction/views.py changed, reloading.
INFO:django.utils.autoreload:/home/toxin/Project/gsoc/pygoat/introduction/views.py changed, reloading.
INFO:django.utils.autoreload:/home/toxin/Project/gsoc/pygoat/introduction/views.py changed, reloading.
ERROR:django.request:Internal Server Error: /register
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/usr/lib/python3/dist-packages/django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/toxin/Project/gsoc/pygoat/introduction/views.py", line 67, in register
return render(request, 'registration/register.html', {'form': form})
UnboundLocalError: local variable 'form' referenced before assignment
INFO:django.utils.autoreload:/home/toxin/Project/gsoc/pygoat/introduction/views.py changed, reloading.
ERROR:django.request:Internal Server Error: /register
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/usr/lib/python3/dist-packages/django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/toxin/Project/gsoc/pygoat/introduction/views.py", line 62, in register
form.save()
AttributeError: 'RegistrationForm' object has no attribute 'save'
INFO:django.utils.autoreload:/home/toxin/Project/gsoc/pygoat/introduction/views.py changed, reloading.
INFO:django.utils.autoreload:/home/toxin/Project/gsoc/pygoat/introduction/views.py changed, reloading.
INFO:django.utils.autoreload:/home/toxin/Project/gsoc/pygoat/introduction/views.py changed, reloading.
INFO:django.utils.autoreload:/home/toxin/Project/gsoc/pygoat/introduction/views.py changed, reloading.
WARNING:django.request:Not Found: /favicon.ico
WARNING:django.request:Not Found: /introduction/home.html
WARNING:django.request:Not Found: /introduction/home.html/
WARNING:django.request:Not Found: /introduction/home.html/
WARNING:django.request:Not Found: /introduction/home.html
WARNING:django.request:Not Found: /introduction/homepage
WARNING:django.request:Not Found: /introduction/
INFO:django.utils.autoreload:/home/toxin/Project/gsoc/pygoat/introduction/views.py changed, reloading.
WARNING:django.request:Not Found: /introduction/
WARNING:django.request:Not Found: /introduction/home.html
INFO:django.utils.autoreload:/home/toxin/Project/gsoc/pygoat/introduction/views.py changed, reloading.
INFO:django.utils.autoreload:/home/toxin/Project/gsoc/pygoat/introduction/forms.py changed, reloading.
WARNING:django.security.csrf:Forbidden (CSRF token missing or incorrect.): /admin/auth/user/
20 changes: 20 additions & 0 deletions introduction/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User


# Create your forms here.

class NewUserForm(UserCreationForm):
email = forms.EmailField(required=True)

class Meta:
model = User
fields = ("username", "email", "password1", "password2")

def save(self, commit=True):
user = super(NewUserForm, self).save(commit=False)
user.email = self.cleaned_data['email']
if commit:
user.save()
return user
24 changes: 14 additions & 10 deletions introduction/templates/registration/register.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
{% extends "introduction/base.html" %}
{% block content %}
{% load crispy_forms_tags %}
{% block content %}

<div class="jumbotron">
<div class="contaniner">
<form method="post">
{% csrf_token %}
{{form|crispy}}
<button type="submit" class="btn btn-info btn-info">Register</button>
</form>
</div>
{% load crispy_forms_tags %}

<!--Register-->
<div class="container py-5">
<h1>Register</h1>
<form method="POST">
{% csrf_token %}
{{ register_form|crispy }}
<button class="btn btn-primary" type="submit">Register</button>
</form>
<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>
instead.</p>
</div>

{% endblock %}
33 changes: 23 additions & 10 deletions introduction/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import os
from hashlib import md5
import datetime
from .forms import NewUserForm
from django.contrib import messages
#*****************************************Lab Requirements****************************************************#

from .models import FAANG,info,login,comments,otp
Expand Down Expand Up @@ -38,17 +40,28 @@
import requests
#*****************************************Login and Registration****************************************************#


def register(request):
if request.method=="POST":
form = UserCreationForm(request.POST)
if form.is_valid():
form.save()
return redirect("login")

else:
form=UserCreationForm()
return render(request,"registration/register.html",{"form":form,})
if request.method == "POST":
form = NewUserForm(request.POST)
if form.is_valid():
user = form.save()
login(request, user)
messages.success(request, "Registration successful." )
return redirect('/')
messages.error(request, "Unsuccessful registration. Invalid information.")
form = NewUserForm()
return render (request=request, template_name="registration/register.html", context={"register_form":form})

# def register(request):
# if request.method=="POST":
# form = UserCreationForm(request.POST)
# if form.is_valid():
# form.save()
# return redirect("login")

# else:
# form=UserCreationForm()
# return render(request,"registration/register.html",{"form":form,})

def home(request):
if request.user.is_authenticated:
Expand Down
2 changes: 1 addition & 1 deletion lib/python3.10/site-packages/php_wsgi/php_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def __call__(self,environ,start_response):
return self.app(environ,start_response)
content_type = 'text/{}'.format(self._get_content_type(file_location))
if verbose:
print 'SERVING STATIC FILE {0}'.format(file_location)
print ('SERVING STATIC FILE {0}'.format(file_location))
start_response('200',[('content-type',content_type),('User-Agent','Python-php-static')])
return open(file_location,'r').read()
else:
Expand Down

0 comments on commit 624aa04

Please sign in to comment.