Commit 8e6380b2 authored by JayCay's avatar JayCay

Signup and Logout added

parent 57cba7a0
...@@ -38,8 +38,11 @@ INSTALLED_APPS = [ ...@@ -38,8 +38,11 @@ INSTALLED_APPS = [
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'widget_tweaks',
'reviews', 'reviews',
'profs', 'profs',
'accounts',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
...@@ -130,3 +133,5 @@ STATICFILES_DIRS = [ ...@@ -130,3 +133,5 @@ STATICFILES_DIRS = [
# Tells django where to put static files after collectstatic # Tells django where to put static files after collectstatic
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
LOGOUT_REDIRECT_URL = 'reviews_index'
\ No newline at end of file
...@@ -15,12 +15,17 @@ Including another URLconf ...@@ -15,12 +15,17 @@ Including another URLconf
""" """
from django.conf.urls import url from django.conf.urls import url
from django.contrib import admin from django.contrib import admin
from django.contrib.auth import views as auth_views
from accounts import views as accounts_views
from reviews import views as reviews_views from reviews import views as reviews_views
from profs import views as profs_views from profs import views as profs_views
urlpatterns = [ urlpatterns = [
url(r'^signup/$', accounts_views.signup, name='signup'),
url(r'^logout/$', auth_views.LogoutView.as_view(), name='logout'),
url(r'^admin/', admin.site.urls), url(r'^admin/', admin.site.urls),
url(r'^$', reviews_views.index, name="reviews_index"), url(r'^$', reviews_views.index, name="reviews_index"),
url(r'^profs/', profs_views.index, name="profs_index"), url(r'^profs/', profs_views.index, name="profs_index"),
......
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class AccountsConfig(AppConfig):
name = 'accounts'
from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
class SignUpForm(UserCreationForm):
email = forms.CharField(max_length=254, required=True, widget=forms.EmailInput())
class Meta:
model = User
fields = ('username', 'email', 'password1', 'password2')
\ No newline at end of file
from django.db import models
# Create your models here.
from django.test import TestCase
# Create your tests here.
from django.contrib.auth import login as auth_login
from django.shortcuts import render, redirect
from .forms import SignUpForm
def signup(request):
if request.method == 'POST':
form = SignUpForm(request.POST)
if form.is_valid():
user = form.save()
auth_login(request, user)
return redirect('reviews_index')
else:
form = SignUpForm()
return render(request, 'templates/signup.html', {'form' : form})
No preview for this file type
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
<ul> <ul>
<li><a href="{% url 'reviews_index' %}">Home</a></li> <li><a href="{% url 'reviews_index' %}">Home</a></li>
<li><a href="{% url 'profs_index' %}">Profs</a></li> <li><a href="{% url 'profs_index' %}">Profs</a></li>
<li>{{ user.username }}</li>
</ul> </ul>
</nav> </nav>
{% block content %} {% block content %}
......
{% load widget_tweaks %}
{% for field in form %}
<div class="form-group">
{{ field.label_tag }}
{% if form.is_bound %}
{% if field.errors %}
{% render_field field class="form-control is-invalid" %}
{% for error in field.errors %}
<div class="invalid-feedback">
{{ error }}
</div>
{% endfor %}
{% else %}
{% render_field field class="form-control is-valid" %}
{% endif %}
{% else %}
{% render_field field class="form-control" %}
{% endif %}
{% if field.help_text %}
<small class="form-text text-muted">
{{field.help_text|safe}}
</small>
{% endif %}
</div>
{% endfor %}
\ No newline at end of file
{% extends 'templates/base.html' %}
{% block content %}
<div class = "container">
<h2>Sign up</h2>
<form method = "post" novalidate>
{% csrf_token %}
{% include 'templates/includes/form.html' %}
<button type = "submit" class = "btn btn-primary">Create an account</button>
</form>
</div>
{% endblock %}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment