mirror of
https://github.com/ajurna/cbwebreader.git
synced 2025-12-06 14:17:19 +00:00
added authentication
This commit is contained in:
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