Skip to content

Commit

Permalink
create user working
Browse files Browse the repository at this point in the history
  • Loading branch information
sjcshin committed Apr 16, 2022
1 parent 546ed11 commit e3ea015
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 37 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ phittest/pages/__pycache__/urls.cpython-38.pyc
phittest/pages/__pycache__/views.cpython-38.pyc
phittest/phittest/__pycache__/settings.cpython-38.pyc
phittest/phittest/__pycache__/urls.cpython-38.pyc
phittest/accounts/__pycache__/forms.cpython-38.pyc
phittest/accounts/__pycache__/views.cpython-38.pyc
phittest/phittest/__pycache__/urls.cpython-38.pyc
__pycache__
Binary file modified phittest/accounts/__pycache__/forms.cpython-38.pyc
Binary file not shown.
Binary file modified phittest/accounts/__pycache__/views.cpython-38.pyc
Binary file not shown.
26 changes: 14 additions & 12 deletions phittest/accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ class LoginForm(forms.Form):


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

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

def save(self, commit=True):
user = super(RegisterForm, self).save(commit=False)
user.email = self.cleaned_data['email']
if commit:
user.save()
return user
first_name = forms.CharField(max_length=50)
last_name = forms.CharField(max_length=50)
email = forms.EmailField(required=True)

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

def save(self, commit=True):
user = super(RegisterForm, self).save(commit=False)
user.email = self.cleaned_data['email']
if commit:
user.save()
return user
16 changes: 16 additions & 0 deletions phittest/accounts/templates/accounts/register_success.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% load static %}

{% block content %}
<!DOCTYPE html>
<head>
<title>
Registration Success
</title>
</head>
<body style=text-align:center;margin:250px>
<h1>Account successfully created.</h1>
<br>
<p>Username: {{ request.session.account_created }}</p><br><br>
<a href="{% url 'login' %}"><button class='w-100 btn btn-lg btn-primary' style=max-width:160px;>Back to Login</button></a>
</body>
{% endblock %}
27 changes: 17 additions & 10 deletions phittest/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,20 @@ def logout_view(request):


def register_view(request):
if request.method == "POST":
form = RegisterForm(request.POST)
if form.is_valid():
user = form.save()
login(request, user)
messages.success(request, "Registration successful." )
return redirect("main:homepage")
messages.error(request, "Unsuccessful registration. Invalid information.")
form = RegisterForm()
return render (request=request, template_name="accounts/register.html", context={"form":form})
request.session['account_created'] = None

if request.method == "POST":
form = RegisterForm(request.POST)
if form.is_valid():
user = form.save()
request.session['account_created'] = user.username
messages.success(request, "Registration successful.")
return redirect(reverse("register_success"))
messages.error(request, "Unsuccessful registration. Invalid information.")

form = RegisterForm()
return render (request, "accounts/register.html", {"form":form})


def register_success_view(request):
return render(request, 'accounts/register_success.html')
Binary file modified phittest/db.sqlite3
Binary file not shown.
12 changes: 0 additions & 12 deletions phittest/pages/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,6 @@

class SurveyForm(forms.ModelForm):
"""Contains definition for the survey."""
# incomplete_emptying = forms.IntegerField(label='Incomplete Emptying', max_length=100)
# incomplete_emptying = forms.IntegerField(widget=RadioSelect(choices=SurveyChoices.choices))
# frequency = forms.IntegerField(choices=CHOICES.choices, widget=forms.RadioSelect)
# intermittency = forms.IntegerField(choices=CHOICES.choices, widget=forms.RadioSelect)
# urgency = forms.IntegerField(choices=CHOICES.choices, widget=forms.RadioSelect)
# weak_stream = forms.IntegerField(choices=CHOICES.choices, widget=forms.RadioSelect)
# straining = forms.IntegerField(choices=CHOICES.choices, widget=forms.RadioSelect)
# nocturia = forms.IntegerField(choices=CHOICES.choices, widget=forms.RadioSelect)
# quality_of_life = forms.IntegerField(choices=CHOICES.choices, widget=forms.RadioSelect)
# total_score = forms.IntegerField(choices=CHOICES.choices, widget=forms.RadioSelect)


class Meta:
"""Metadata options for this form."""
model = Survey
Expand Down
Binary file modified phittest/phittest/__pycache__/urls.cpython-38.pyc
Binary file not shown.
3 changes: 2 additions & 1 deletion phittest/phittest/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
from django.contrib import admin
from django.urls import path, include

from accounts.views import login_view, logout_view, register_view
from accounts.views import login_view, logout_view, register_success_view, register_view

urlpatterns = [
path('admin/', admin.site.urls),
path('', include('pages.urls')),
path('login/', login_view, name='login'),
path('logout/', logout_view, name='logout'),
path('register/', register_view, name='register'),
path('register/success', register_success_view, name='register_success')
]
2 changes: 1 addition & 1 deletion phittest/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ <h1>PHIT-Test</h1>
</li>
{% endif %}
<a href="#" style="padding-left: 0px" class="nav-link username">
User: {{request.user.username}}</a>
User: {{request.user.first_name}} {{request.user.last_name}}</a>
<a id="id_logout" href="{% url 'logout' %}"><button type="button"
class="btn btn-sm btn-danger" style="float: right;">Logout</button></a>
</ul>
Expand Down
5 changes: 4 additions & 1 deletion phittest/templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ <h2>Log In</h2>
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Log In</button>

<br>
<a href="{% url 'register' %}">
Create Account
</a>
</form>

0 comments on commit e3ea015

Please sign in to comment.