Skip to content

Very very basic auth & upgrading app #8

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions rodolphe/main/views/decorators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from django.shortcuts import render_to_response
from django.conf import settings
from functools import wraps


def lock_view(request, *args, **kwargs):
return render_to_response('auth.html', {})

def vospapiers(f):
@wraps(f)
def petit_wrap(request, *args, **kwargs):
if settings.PASSWORD:
if settings.PASSWORD in request.get_raw_uri():
request.session["allowed"] = True
if not request.session.get("allowed", False):
return lock_view(request, *args, **kwargs)
return f(request, *args, **kwargs)

return petit_wrap
2 changes: 2 additions & 0 deletions rodolphe/main/views/paging.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

from main.models import Post
from main.forms import PostForm
from main.views.decorators import vospapiers


@vospapiers
def page(request):
paginator = Paginator(Post.objects.filter(active=True, parent=None)
.order_by('-last_resp_at'), 10)
Expand Down
5 changes: 5 additions & 0 deletions rodolphe/main/views/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
from main.forms import PostForm, DeletePostForm
from main.views.thread import view
from main.views.paging import page as home
from main.views.decorators import vospapiers

import json


@vospapiers
def raw(request, post_id):
post = get_object_or_404(Post, id=int(post_id), active=True)
infos = {
Expand All @@ -26,6 +28,7 @@ def raw(request, post_id):
return HttpResponse(json.dumps(infos))


@vospapiers
def edit(request, post_id):
post = get_object_or_404(Post, id=int(post_id), active=True)
if request.method == 'POST':
Expand All @@ -49,6 +52,7 @@ def edit(request, post_id):
return render_to_response('edit.html', context)


@vospapiers
def delete(request, post_id):
post = get_object_or_404(Post, id=int(post_id), active=True)
if request.method == 'POST':
Expand All @@ -71,6 +75,7 @@ def delete(request, post_id):
return render_to_response('delete.html', context)


@vospapiers
def history(request, post_id):
post = get_object_or_404(Post, id=int(post_id), active=True)
hist = [post]
Expand Down
3 changes: 2 additions & 1 deletion rodolphe/main/views/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
from main.models import Post
from main.forms import PostForm
from utils.search import get_search
from main.views.decorators import vospapiers


@vospapiers
def search(request):
q, search = get_search(request)
paginator = Paginator(Post.objects.filter(q, active=True)
Expand Down
2 changes: 2 additions & 0 deletions rodolphe/main/views/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
from main.forms import PostForm
from utils.search import get_search
from utils.tags import TagsSet
from main.views.decorators import vospapiers

import re
from collections import defaultdict
from urllib.parse import urlencode


@vospapiers
def index(request):
indexed_tags = defaultdict(list)
for tag in Tag.objects.all():
Expand Down
3 changes: 3 additions & 0 deletions rodolphe/main/views/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

from main.models import Post
from main.forms import PostForm
from main.views.decorators import vospapiers


@vospapiers
def view(request, post_id):
post = get_object_or_404(Post, id=int(post_id), active=True, parent=None)
if request.method == 'POST':
Expand All @@ -24,6 +26,7 @@ def view(request, post_id):
return render_to_response('view.html', context)


@vospapiers
def new(request):
if request.method == 'POST':
form = PostForm(request.POST, request.FILES, instance=Post.default())
Expand Down
3 changes: 3 additions & 0 deletions rodolphe/rodolphe/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@

TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'templates'),)

# PASSWORD allow to authenticate users with digit based password.
# No effect if PASSWORD is falsy.
PASSWORD = "0123"

# Local settings

Expand Down
27 changes: 14 additions & 13 deletions rodolphe/rodolphe/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@
from django.conf import settings
from django.conf.urls.static import static
from django.views.generic.base import TemplateView
from main.views import paging, thread, post, tag, search, about

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
url(r'^$', 'main.views.paging.page'),
url(r'^$', paging.page, name="home"),

url(r'^view/(?P<post_id>\d+)$', 'main.views.thread.view'),
url(r'^new$', 'main.views.thread.new'),
url(r'^view/(?P<post_id>\d+)$', thread.view, name="view"),
url(r'^new$', thread.new),

url(r'^raw/(?P<post_id>\d+)$', 'main.views.post.raw'),
url(r'^edit/(?P<post_id>\d+)$', 'main.views.post.edit'),
url(r'^del/(?P<post_id>\d+)$', 'main.views.post.delete'),
url(r'^h/(?P<post_id>\d+)$', 'main.views.post.history'),
url(r'^raw/(?P<post_id>\d+)$', post.raw, name="raw"),
url(r'^edit/(?P<post_id>\d+)$', post.edit, name="edit"),
url(r'^del/(?P<post_id>\d+)$', post.delete, name="delete"),
url(r'^h/(?P<post_id>\d+)$', post.history, name="history"),

url(r'^tags$', 'main.views.tag.index'),
url(r'^tag/(?P<pattern>(~?\w+)(\|~?\w+)*)$', 'main.views.tag.search'),
url(r'^tags$', tag.index),
url(r'^tag/(?P<pattern>(~?\w+)(\|~?\w+)*)$', tag.search, name="search_tag"),

url(r'^search$', 'main.views.search.search'),
url(r'^search$', search.search, name="search"),

url(r'^about$', 'main.views.about.about'),
url(r'^markdown$', 'main.views.about.markdown'),
url(r'^render$', 'main.views.about.render'),
url(r'^about$', about.about, name="about"),
url(r'^markdown$', about.markdown, name="about"),
url(r'^render$', about.render),

url(r'^admin/', include(admin.site.urls)),
url(r'^captcha/', include('captcha.urls')),
Expand Down
45 changes: 45 additions & 0 deletions rodolphe/templates/auth.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<html>
<head>
<style>
form {
text-align: center;
}
button {
width: 100px;
height: 100px;
font-size: 5em;
margin: 10px;
}
</style>
<script>
function compose(e) {
num = e.target.innerHTML;
document.getElementById("number").value += num;
}
</script>
</head>
<body>
<form action="">
<input id="number" name="number" type="text" />
<br/>
<button id="box">&#9990;</button>
<br />
<button onclick="compose(event); return false;">1</button>
<button onclick="compose(event); return false;">2</button>
<button onclick="compose(event); return false;">3</button>
<br />
<button onclick="compose(event); return false;">4</button>
<button onclick="compose(event); return false;">5</button>
<button onclick="compose(event); return false;">6</button>
<br />
<button onclick="compose(event); return false;">7</button>
<button onclick="compose(event); return false;">8</button>
<button onclick="compose(event); return false;">9</button>
<br/>
<button onclick="compose(event); return false;">0</button>
</form>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-beta1/jquery.min.js"></script>
</body>
</html>

2 changes: 1 addition & 1 deletion rodolphe/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h1>{{SITE_NAME}} <small>{% # pagetitle %}</small></h1>

<nav class="navbar" role="navigation">
<ul class="nav navbar-nav">
<li><a href="{% url 'main.views.home' %}">{% bootstrap_icon "home" %} {% trans "home" %}</a></li>
<li><a href="{% url 'home' %}">{% bootstrap_icon "home" %} {% trans "home" %}</a></li>
<li><a href="{% url 'main.views.thread.new' %}">{% bootstrap_icon "plus" %} {% trans "participate" %}</a></li>
<li><a href="{% url 'main.views.about.about' %}">{% bootstrap_icon "info-sign" %} {% trans "about" %}</a></li>
<li><a href="{% url 'main.views.tag.index' %}">{% bootstrap_icon "tag" %} {% trans "tags" %}</a></li>
Expand Down
8 changes: 4 additions & 4 deletions stable-req.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Django==1.6.1
Django==1.9.2
Markdown==2.3.1
Pillow==2.3.0
django-bootstrap3==4.7.0
django-simple-captcha==0.4.1
django-bootstrap3
django-simple-captcha
fake-factory==0.3.2
six==1.5.2
six