Login and registering

This commit is contained in:
teras 2017-10-07 12:32:56 +03:00
parent 22acfdd029
commit 81e3af7f7d
9 changed files with 279 additions and 25 deletions

101
.gitignore vendored Normal file
View File

@ -0,0 +1,101 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# dotenv
.env
# virtualenv
.venv
venv/
ENV/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/

View File

@ -1,7 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="3521438c-7e51-49b1-9d4b-738e7f383936" name="Default" comment="" />
<list default="true" id="3521438c-7e51-49b1-9d4b-738e7f383936" name="Default" comment="">
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/templates/login.html" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/db.sqlite3" afterPath="$PROJECT_DIR$/db.sqlite3" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/challenges/models.py" afterPath="$PROJECT_DIR$/challenges/models.py" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/challenges/urls.py" afterPath="$PROJECT_DIR$/challenges/urls.py" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/challenges/views.py" afterPath="$PROJECT_DIR$/challenges/views.py" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="TRACKING_ENABLED" value="true" />
<option name="SHOW_DIALOG" value="false" />
@ -29,28 +36,28 @@
<file leaf-file-name="register.html" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/templates/register.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="252">
<caret line="14" column="11" lean-forward="true" selection-start-line="14" selection-start-column="11" selection-end-line="14" selection-end-column="11" />
<state relative-caret-position="0">
<caret line="0" column="15" lean-forward="true" selection-start-line="0" selection-start-column="15" selection-end-line="0" selection-end-column="15" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="models.py" pinned="false" current-in-tab="false">
<file leaf-file-name="models.py" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/challenges/models.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="90">
<caret line="5" column="36" lean-forward="true" selection-start-line="5" selection-start-column="36" selection-end-line="5" selection-end-column="36" />
<state relative-caret-position="252">
<caret line="14" column="3" lean-forward="false" selection-start-line="14" selection-start-column="3" selection-end-line="14" selection-end-column="3" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="views.py" pinned="false" current-in-tab="true">
<file leaf-file-name="views.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/challenges/views.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="468">
<caret line="26" column="19" lean-forward="false" selection-start-line="26" selection-start-column="19" selection-end-line="26" selection-end-column="19" />
<state relative-caret-position="479">
<caret line="37" column="14" lean-forward="false" selection-start-line="37" selection-start-column="14" selection-end-line="37" selection-end-column="14" />
<folding>
<element signature="e#0#36#0" expanded="true" />
</folding>
@ -58,6 +65,16 @@
</provider>
</entry>
</file>
<file leaf-file-name="login.html" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/templates/login.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="144">
<caret line="8" column="23" lean-forward="false" selection-start-line="8" selection-start-column="23" selection-end-line="8" selection-end-column="23" />
<folding />
</state>
</provider>
</entry>
</file>
</leaf>
</split-first>
<split-second>
@ -66,7 +83,7 @@
<entry file="file://$PROJECT_DIR$/challenges/wsgi.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="0">
<caret line="0" column="3" lean-forward="true" selection-start-line="0" selection-start-column="3" selection-end-line="0" selection-end-column="3" />
<caret line="0" column="3" lean-forward="false" selection-start-line="0" selection-start-column="3" selection-end-line="0" selection-end-column="3" />
<folding />
</state>
</provider>
@ -75,8 +92,8 @@
<file leaf-file-name="urls.py" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/challenges/urls.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="450">
<caret line="25" column="72" lean-forward="false" selection-start-line="25" selection-start-column="72" selection-end-line="25" selection-end-column="72" />
<state relative-caret-position="432">
<caret line="24" column="36" lean-forward="false" selection-start-line="24" selection-start-column="36" selection-end-line="24" selection-end-column="36" />
<folding>
<element signature="e#644#676#0" expanded="true" />
</folding>
@ -110,11 +127,12 @@
<option value="$PROJECT_DIR$/models.py" />
<option value="$PROJECT_DIR$/views.py" />
<option value="$PROJECT_DIR$/challenges/settings.py" />
<option value="$PROJECT_DIR$/challenges/urls.py" />
<option value="$PROJECT_DIR$/static/register.html" />
<option value="$PROJECT_DIR$/templates/register.html" />
<option value="$PROJECT_DIR$/challenges/models.py" />
<option value="$PROJECT_DIR$/templates/login.html" />
<option value="$PROJECT_DIR$/challenges/views.py" />
<option value="$PROJECT_DIR$/challenges/urls.py" />
<option value="$PROJECT_DIR$/challenges/models.py" />
</list>
</option>
</component>
@ -176,6 +194,9 @@
<property name="DefaultHtmlFileTemplate" value="HTML File" />
</component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/templates" />
</key>
<key name="MoveFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/templates" />
<recent name="$PROJECT_DIR$/challenges" />
@ -303,7 +324,7 @@
<entry file="file://$PROJECT_DIR$/challenges/wsgi.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="0">
<caret line="0" column="3" lean-forward="true" selection-start-line="0" selection-start-column="3" selection-end-line="0" selection-end-column="3" />
<caret line="0" column="3" lean-forward="false" selection-start-line="0" selection-start-column="3" selection-end-line="0" selection-end-column="3" />
<folding />
</state>
</provider>
@ -345,7 +366,7 @@
<entry file="file://$PROJECT_DIR$/templates/register.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="252">
<caret line="14" column="11" lean-forward="true" selection-start-line="14" selection-start-column="11" selection-end-line="14" selection-end-column="11" />
<caret line="14" column="11" lean-forward="false" selection-start-line="14" selection-start-column="11" selection-end-line="14" selection-end-column="11" />
<folding />
</state>
</provider>
@ -353,20 +374,95 @@
<entry file="file://$PROJECT_DIR$/challenges/models.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="90">
<caret line="5" column="36" lean-forward="true" selection-start-line="5" selection-start-column="36" selection-end-line="5" selection-end-column="36" />
<caret line="5" column="36" lean-forward="false" selection-start-line="5" selection-start-column="36" selection-end-line="5" selection-end-column="36" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/challenges/views.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="468">
<caret line="26" column="19" lean-forward="false" selection-start-line="26" selection-start-column="19" selection-end-line="26" selection-end-column="19" />
<state relative-caret-position="486">
<caret line="27" column="0" lean-forward="false" selection-start-line="27" selection-start-column="0" selection-end-line="27" selection-end-column="0" />
<folding>
<element signature="e#0#36#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/challenges/wsgi.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="0">
<caret line="0" column="3" lean-forward="false" selection-start-line="0" selection-start-column="3" selection-end-line="0" selection-end-column="3" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/manage.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="90">
<caret line="6" column="8" lean-forward="true" selection-start-line="6" selection-start-column="8" selection-end-line="6" selection-end-column="8" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/challenges/__init__.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="0">
<caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/challenges/settings.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="180">
<caret line="41" column="10" lean-forward="false" selection-start-line="41" selection-start-column="0" selection-end-line="41" selection-end-column="10" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/templates/login.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="144">
<caret line="8" column="23" lean-forward="false" selection-start-line="8" selection-start-column="23" selection-end-line="8" selection-end-column="23" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/challenges/urls.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="432">
<caret line="24" column="36" lean-forward="false" selection-start-line="24" selection-start-column="36" selection-end-line="24" selection-end-column="36" />
<folding>
<element signature="e#644#676#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/challenges/views.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="479">
<caret line="37" column="14" lean-forward="false" selection-start-line="37" selection-start-column="14" selection-end-line="37" selection-end-column="14" />
<folding>
<element signature="e#0#36#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/templates/register.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="0">
<caret line="0" column="15" lean-forward="true" selection-start-line="0" selection-start-column="15" selection-end-line="0" selection-end-column="15" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/challenges/models.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="252">
<caret line="14" column="3" lean-forward="false" selection-start-line="14" selection-start-column="3" selection-end-line="14" selection-end-column="3" />
<folding />
</state>
</provider>
</entry>
</component>
</project>

View File

@ -1,6 +1,20 @@
from django.db import models
'''class User:
user
class Challenge:
class ChallengeTag:
id =
name
description
class UserChallenge:
id
user
challenge
'''
class Challenge(models.Model):
#id =
name = models.CharField(256)
description = models.TextField()
#tags

View File

@ -22,5 +22,6 @@ from challenges import views
urlpatterns = [
url(r'^$', views.index),
url(r'^admin/', admin.site.urls),
url(r'^login/', views.login_view),
url(r'^register/', views.register),
] + static(settings.STATIC_URL, document_root=settings.STATICFILES_DIRS)

View File

@ -3,7 +3,7 @@ from django.template import loader, RequestContext
from django.shortcuts import render_to_response, render
from django.views.decorators.csrf import csrf_protect
from django.contrib.auth.models import User
from django.contrib.auth import authenticate, login
def index(request):
if request.method == 'GET':
@ -14,16 +14,41 @@ def index(request):
def register(request):
if request.method == 'GET':
return render(request, 'register.html')
#return HttpResponse(loader.get_template('register.html').render())
elif request.method == 'POST':
username = request.POST['username']
password = request.POST['password']
password_confirmation = request.POST['password_confirmation']
if len(password) < 8:
return HttpResponse("password too short")
if password != password_confirmation:
return HttpResponse("passwords do not match")
user = User.objects.create_user('username', 'email@email.email', password)
user.save()
if not User.objects.filter(username=username).exists():
user = User.objects.create_user(username, password=password)
user.save()
else:
return HttpResponse("user exist")
return HttpResponse("DONE")
return HttpResponse("User {} created".format(username))
@csrf_protect
def login_view(request):
if request.method == 'GET':
auth_user = 'no user'
if request.user.is_authenticated:
auth_user = request.user.username
return render(request, 'login.html', {'auth_user': auth_user})
elif request.method == 'POST':
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
login(request, user)
return HttpResponse('request suq')
else:
return HttpResponse('invalid username or password')

Binary file not shown.

17
templates/login.html Normal file
View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login</title>
</head>
<body>
<h1>login</h1>
<h1>{{ auth_user }}</h1>
<form id="reg" action="/login/" method="POST">
{% csrf_token %}
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
<input type="submit" />
</form>
</body>
</html>