mirror of
https://github.com/ajurna/cbwebreader.git
synced 2025-12-06 06:17:17 +00:00
added authentication
This commit is contained in:
@@ -38,6 +38,7 @@ INSTALLED_APPS = (
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'comic',
|
||||
'comic_auth',
|
||||
)
|
||||
|
||||
MIDDLEWARE_CLASSES = (
|
||||
@@ -101,3 +102,7 @@ USE_TZ = True
|
||||
# https://docs.djangoproject.com/en/1.8/howto/static-files/
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
|
||||
LOGIN_REDIRECT_URL = '/comic/'
|
||||
|
||||
LOGIN_URL = '/login/'
|
||||
@@ -17,6 +17,8 @@ from django.conf.urls import include, url
|
||||
from django.contrib import admin
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^login/', 'comic_auth.views.comic_login'),
|
||||
url(r'^logout/', 'comic_auth.views.comic_logout'),
|
||||
url(r'^comic/', include('comic.urls')),
|
||||
url(r'^admin/', include(admin.site.urls)),
|
||||
]
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="">
|
||||
<meta name="author" content="Ajurna">
|
||||
<link rel="icon" href="../../favicon.ico">
|
||||
|
||||
<title>{% block title %}CB Reader{% endblock %}</title>
|
||||
@@ -36,14 +36,14 @@
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
<a class="navbar-brand" href="#">CBReader</a>
|
||||
<a class="navbar-brand" href="/comic/">CBReader</a>
|
||||
</div>
|
||||
<div id="navbar" class="collapse navbar-collapse">
|
||||
<ul class="nav navbar-nav">
|
||||
{% block navbar %}
|
||||
<li class="active"><a href="/comic/">Home</a></li>
|
||||
<li><a href="settings/">Settings</a></li>
|
||||
<li><a href="#contact">Contact</a></li>
|
||||
<li><a href="/logout/">Logout</a></li>
|
||||
{% endblock %}
|
||||
</ul>
|
||||
</div><!--/.nav-collapse -->
|
||||
@@ -51,9 +51,7 @@
|
||||
</nav>
|
||||
<ol class="breadcrumb">
|
||||
{% block breadcrumb %}
|
||||
<li><a href="#">Home</a></li>
|
||||
<li><a href="#">Library</a></li>
|
||||
<li class="active">Data</li>
|
||||
<li><a href="/">Home</a></li>
|
||||
{% endblock %}
|
||||
</ol>
|
||||
<div class="container">
|
||||
|
||||
@@ -2,13 +2,14 @@ from django.http import HttpResponse
|
||||
from django.template import RequestContext
|
||||
from django.utils.http import urlsafe_base64_decode
|
||||
from django.shortcuts import render
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
||||
from comic.models import Setting, ComicBook
|
||||
from util import generate_breadcrumbs, generate_directory
|
||||
|
||||
from os import path
|
||||
|
||||
|
||||
@login_required
|
||||
def comic_list(request, comic_path=''):
|
||||
base_dir = Setting.objects.get(name='BASE_DIR').value
|
||||
comic_path = urlsafe_base64_decode(comic_path)
|
||||
@@ -20,7 +21,7 @@ def comic_list(request, comic_path=''):
|
||||
})
|
||||
return render(request, 'comic/comic_list.html', context)
|
||||
|
||||
|
||||
@login_required
|
||||
def read_comic(request, comic_path, page):
|
||||
base_dir = Setting.objects.get(name='BASE_DIR').value
|
||||
page = int(page)
|
||||
@@ -42,7 +43,7 @@ def read_comic(request, comic_path, page):
|
||||
})
|
||||
return render(request, 'comic/read_comic.html', context)
|
||||
|
||||
|
||||
@login_required
|
||||
def get_image(_, comic_path, page):
|
||||
base_dir = Setting.objects.get(name='BASE_DIR').value
|
||||
page = int(page)
|
||||
|
||||
0
comic_auth/__init__.py
Normal file
0
comic_auth/__init__.py
Normal file
3
comic_auth/admin.py
Normal file
3
comic_auth/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
0
comic_auth/migrations/__init__.py
Normal file
0
comic_auth/migrations/__init__.py
Normal file
3
comic_auth/models.py
Normal file
3
comic_auth/models.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
20
comic_auth/templates/comic_auth/login.html
Normal file
20
comic_auth/templates/comic_auth/login.html
Normal file
@@ -0,0 +1,20 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}CBreader Login{% endblock %}
|
||||
{% block content %}
|
||||
|
||||
<div class="col-md-4 col-md-offset-4">
|
||||
{% if error %}
|
||||
<div class="alert alert-danger" role="alert"><p>Your username and password didn't match. Please try again.</p></div>
|
||||
{% endif %}
|
||||
<form method="post" class="form-signin">
|
||||
{% csrf_token %}
|
||||
<h2 class="form-signin-heading">Please sign in</h2>
|
||||
<label for="inputUser" class="sr-only">Username</label>
|
||||
<input type="text" name="user" id="inputUser" class="form-control" placeholder="Username" required autofocus>
|
||||
<label for="inputPassword" class="sr-only">Password</label>
|
||||
<input type="password" name="password" id="inputPassword" class="form-control" placeholder="Password" required>
|
||||
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
3
comic_auth/tests.py
Normal file
3
comic_auth/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
28
comic_auth/views.py
Normal file
28
comic_auth/views.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from django.shortcuts import render, redirect
|
||||
from django.shortcuts import RequestContext
|
||||
from django.contrib.auth import authenticate, login, logout
|
||||
|
||||
|
||||
def comic_login(request):
|
||||
if request.POST:
|
||||
user = authenticate(username=request.POST['user'],
|
||||
password=request.POST['password'])
|
||||
if user is not None:
|
||||
if user.is_active:
|
||||
login(request, user)
|
||||
if request.GET.has_key('next'):
|
||||
return redirect(request.GET['next'])
|
||||
else:
|
||||
return redirect('/comic/')
|
||||
else:
|
||||
context = RequestContext(request, {
|
||||
'error': True
|
||||
})
|
||||
return render(request, 'comic_auth/login.html', context)
|
||||
else:
|
||||
context = RequestContext(request, {})
|
||||
return render(request, 'comic_auth/login.html', context)
|
||||
|
||||
def comic_logout(request):
|
||||
logout(request)
|
||||
return redirect('/login/')
|
||||
Reference in New Issue
Block a user