Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registration and entries #28

Merged
merged 1 commit into from Jul 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions Makefile
Expand Up @@ -3,9 +3,9 @@
SHELL := /bin/bash

install:
$(shell sudo sh build.sh)
$(shell curl -sSL https\://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python)
$(shell poetry install)
sudo sh build.sh
curl -sSL https\://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python
poetry install

assets:
yarn run build
cd app ; yarn run build
6 changes: 5 additions & 1 deletion app/assets/style.css
Expand Up @@ -92,4 +92,8 @@ nav ul li a, nav ul li span, header .action {

.entry li {
list-style-type: none;
}
}

.login li {
list-style-type: none;
}
4 changes: 2 additions & 2 deletions app/src/login.ts
Expand Up @@ -2,7 +2,7 @@ let userLogin = () => {
document.body.innerHTML +=
`
<div id="login" class="paper">
<form action="/login" method="post">
<form action="/user/login" method="post">
<div class="login">
<ul>
<li><label for="username">Username:</label></li>
Expand All @@ -22,7 +22,7 @@ let userLogin = () => {
'password': (document.getElementById('password') as any).value
}

fetch('/login', {
fetch('/user/login', {
method: 'POST',
headers: {
'Accept': 'application/json',
Expand Down
8 changes: 3 additions & 5 deletions app/src/register.ts
Expand Up @@ -2,7 +2,7 @@ let userRegister = () => {
document.body.innerHTML +=
`
<div id="login" class="paper">
<form action="/register" method="post">
<form action="/user/register" method="post">
<div class="login">
<ul>
<li><label for="username">Username:</label></li>
Expand All @@ -23,24 +23,22 @@ let userRegister = () => {
'active': 1
}

fetch('/register', {
fetch('/user/register', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(credentials)
})
.then(resp=>resp.text)
.then(resp=>resp.text())
.then(text=> {
console.log(text)
/*
if (text == 'success') {
document.location.replace('/')
} else {
document.location.reload()
}
*/
})
})
}
Expand Down
2 changes: 1 addition & 1 deletion entries/views.py
Expand Up @@ -7,7 +7,7 @@

def entries(request):
e = Entries.objects.filter(user=request.user.id)
return render(request, 'pastes.html', {'pastes': e})
return render(request, 'entries.html', {'entries': e})


def delete(request, id):
Expand Down
3 changes: 2 additions & 1 deletion templates/entries.html
@@ -1,4 +1,5 @@
{% extends 'base.html' %}
{% block content %}
<script src="{{ url_for('static', filename='lib/entries.js') }}"></script>
{% load static %}
<script src="{% static "/assets/lib/entries.js" %}"></script>
{% endblock %}
4 changes: 0 additions & 4 deletions templates/login.html

This file was deleted.

4 changes: 0 additions & 4 deletions templates/register.html

This file was deleted.

5 changes: 5 additions & 0 deletions templates/registration/login.html
@@ -0,0 +1,5 @@
{% extends 'base.html' %}
{% block content %}
{% load static %}
<script src="{% static "/assets/lib/login.js" %}"></script>
{% endblock %}
5 changes: 5 additions & 0 deletions templates/registration/register.html
@@ -0,0 +1,5 @@
{% extends 'base.html' %}
{% block content %}
{% load static %}
<script src="{% static "/assets/lib/register.js" %}"></script>
{% endblock %}
13 changes: 13 additions & 0 deletions user/forms.py
@@ -0,0 +1,13 @@
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User


class RegisterForm(UserCreationForm):
class Meta:
model = User
fields = ('username', 'password1', 'password2', )
help_texts = {
'username': None,
'password1': None,
'password2': None,
}
1 change: 1 addition & 0 deletions user/urls.py
Expand Up @@ -19,4 +19,5 @@

urlpatterns = [
path('', include('django.contrib.auth.urls')),
url(r'^register/$', views.register, name='register'),
]
24 changes: 22 additions & 2 deletions user/views.py
@@ -1,3 +1,23 @@
from django.shortcuts import render
from django.contrib.auth import login, authenticate
from django.shortcuts import render, redirect

# Create your views here.
from .forms import RegisterForm


def index_view(request):
return render(request, 'index.html')


def register(request):
if request.method == 'POST':
form = RegisterForm(request.POST)
if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
password = form.cleaned_data.get('password1')
user = authenticate(username=username, password=password)
login(request, user)
return redirect('/')
else:
form = RegisterForm()
return render(request, 'registration/register.html', {'form': form})