Basic register/login/logout
This commit is contained in:
1 parent
3551cd1feb
commit
f3b6d797f6
9 files changed
+97
-5
No files matched your search
Whitespace-only changes.
Binary file not shown.
+40
-3
@@ -1,5 +1,16 @@
|
|||||||
from django.shortcuts import render as djangoRender
|
from django.shortcuts import render as djangoRender
|
||||||
|
|
||||||
|
from django.http import HttpResponse, HttpResponseRedirect
|
||||||
|
|
||||||
|
from django.contrib.auth import authenticate
|
||||||
|
from django.contrib.auth import login as loginUser
|
||||||
|
from django.contrib.auth import logout as logoutUser
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
from OpenBench.config import *
|
||||||
|
|
||||||
# Wrap django.shortcuts.render to add framework settings
|
# Wrap django.shortcuts.render to add framework settings
|
||||||
def render(request, template, data):
|
def render(request, template, data):
|
||||||
data.update(FRAMEWORK_DEFAULTS)
|
data.update(FRAMEWORK_DEFAULTS)
|
||||||
@@ -8,13 +19,39 @@ def render(request, template, data):
|
|||||||
## ADMIN
|
## ADMIN
|
||||||
|
|
||||||
def register(request):
|
def register(request):
|
||||||
pass
|
|
||||||
|
# User trying to view the registration page
|
||||||
|
if request.method == 'GET':
|
||||||
|
return render(request, 'register.html', {})
|
||||||
|
|
||||||
|
# Attempt to create and login the new user
|
||||||
|
user = User.objects.create_user(
|
||||||
|
request.POST['username'],
|
||||||
|
request.POST['email'],
|
||||||
|
request.POST['password']
|
||||||
|
)
|
||||||
|
|
||||||
|
# Login the user and return to index
|
||||||
|
user.save()
|
||||||
|
loginUser(request, user)
|
||||||
|
return HttpResponseRedirect("/index/")
|
||||||
|
|
||||||
def login(request):
|
def login(request):
|
||||||
pass
|
|
||||||
|
# User trying to view the login page
|
||||||
|
if request.method == "GET":
|
||||||
|
return render(request, "login.html", {})
|
||||||
|
|
||||||
|
# Attempt to login the user, and return to index
|
||||||
|
user = authenticate(username=request.POST["username"], password=request.POST["password"])
|
||||||
|
loginUser(request, user)
|
||||||
|
return HttpResponseRedirect("/index/")
|
||||||
|
|
||||||
def logout(request):
|
def logout(request):
|
||||||
pass
|
|
||||||
|
# Logout the user and return to index
|
||||||
|
logoutUser(request)
|
||||||
|
return HttpResponseRedirect("/index/")
|
||||||
|
|
||||||
## CONTENT VIEWING
|
## CONTENT VIEWING
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ ALLOWED_HOSTS = ['*']
|
|||||||
SETTINGS_DIR = os.path.dirname(__file__)
|
SETTINGS_DIR = os.path.dirname(__file__)
|
||||||
PROJECT_PATH = os.path.join(SETTINGS_DIR, os.pardir)
|
PROJECT_PATH = os.path.join(SETTINGS_DIR, os.pardir)
|
||||||
PROJECT_PATH = os.path.abspath(PROJECT_PATH)
|
PROJECT_PATH = os.path.abspath(PROJECT_PATH)
|
||||||
TEMPLATE_PATH = os.path.join(PROJECT_PATH,'templates')
|
TEMPLATE_PATH = os.path.join(PROJECT_PATH,'Templates')
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
'django.contrib.admin',
|
'django.contrib.admin',
|
||||||
@@ -60,7 +60,7 @@ ROOT_URLCONF = 'OpenSite.urls'
|
|||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
'DIRS': [],
|
'DIRS': [TEMPLATE_PATH, ],
|
||||||
'APP_DIRS': True,
|
'APP_DIRS': True,
|
||||||
'OPTIONS': {
|
'OPTIONS': {
|
||||||
'context_processors': [
|
'context_processors': [
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
{% extends "OpenBench/base.html" %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
Login
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block style %}
|
||||||
|
{% load static %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<form method="POST" action="/login/">
|
||||||
|
{% csrf_token %}
|
||||||
|
<label type="text">Username</label>
|
||||||
|
<input type="text" name="username"></br>
|
||||||
|
<label type="text">Password</label>
|
||||||
|
<input type="password" name="password"></br>
|
||||||
|
<input type="submit" name="submit" value="Login">
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
{% extends "OpenBench/base.html" %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
Register
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block style %}
|
||||||
|
{% load static %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<form id="registerForm" method="POST" action="/register/">
|
||||||
|
{% csrf_token %}
|
||||||
|
<label type="text">Username</label>
|
||||||
|
<input type="text" name="username"></br>
|
||||||
|
<label type="text">Password</label>
|
||||||
|
<input type="password" name="password"></br>
|
||||||
|
<label type="text">Email</label>
|
||||||
|
<input type="text" name="email"></br>
|
||||||
|
<input type="submit" name="submit" value="Create User">
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
rm db.sqlite3
|
||||||
|
rm -r OpenBench/migrations/*
|
||||||
|
rm -r OpenBench/__pycache__/*
|
||||||
|
rm -r OpenSite/__pycache__/*
|
||||||
|
|
||||||
|
python3 manage.py makemigrations
|
||||||
|
python3 manage.py migrate
|
||||||
|
python3 manage.py migrate --run-syncdb
|
||||||
BIN
Binary file not shown.
Reference in new issue
Block a user