mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-02-25 08:43:36 +00:00
moved firstboot handling to a firstboot middleware
This commit is contained in:
parent
cf03ee160a
commit
19f36f67d9
25
modules/first_boot/middleware.py
Normal file
25
modules/first_boot/middleware.py
Normal file
@ -0,0 +1,25 @@
|
||||
import logging
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.http.response import HttpResponseRedirect
|
||||
|
||||
from withsqlite.withsqlite import sqlite_db
|
||||
import cfg
|
||||
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class FirstBootMiddleware:
|
||||
""" Forward to firstboot page if firstboot isn't finished yet """
|
||||
def process_request(self, request):
|
||||
with sqlite_db(cfg.store_file, table='firstboot') as database:
|
||||
if not 'state' in database:
|
||||
# Permanent redirect causes the browser to cache the redirect,
|
||||
# preventing the user from navigating to /plinth until the
|
||||
# browser is restarted.
|
||||
return HttpResponseRedirect(reverse('first_boot:index'))
|
||||
|
||||
if database['state'] < 5:
|
||||
LOGGER.info('First boot state - %d', database['state'])
|
||||
return HttpResponseRedirect(reverse('first_boot:state%d' %
|
||||
database['state']))
|
||||
@ -183,6 +183,13 @@ def configure_django():
|
||||
LOGIN_URL=cfg.server_dir + '/accounts/login/',
|
||||
LOGIN_REDIRECT_URL=cfg.server_dir + '/',
|
||||
LOGOUT_URL=cfg.server_dir + '/accounts/logout/',
|
||||
MIDDLEWARE_CLASSES = (
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'modules.first_boot.middleware.FirstBootMiddleware',
|
||||
),
|
||||
ROOT_URLCONF='urls',
|
||||
SESSION_ENGINE='django.contrib.sessions.backends.file',
|
||||
SESSION_FILE_PATH=sessions_directory,
|
||||
|
||||
20
views.py
20
views.py
@ -21,30 +21,10 @@ Main Plinth views
|
||||
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.http.response import HttpResponseRedirect
|
||||
import logging
|
||||
|
||||
from withsqlite.withsqlite import sqlite_db
|
||||
import cfg
|
||||
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def index(request):
|
||||
"""Serve the main index page"""
|
||||
# TODO: Move firstboot handling to firstboot module somehow
|
||||
with sqlite_db(cfg.store_file, table='firstboot') as database:
|
||||
if not 'state' in database:
|
||||
# Permanent redirect causes the browser to cache the redirect,
|
||||
# preventing the user from navigating to /plinth until the
|
||||
# browser is restarted.
|
||||
return HttpResponseRedirect(reverse('first_boot:index'))
|
||||
|
||||
if database['state'] < 5:
|
||||
LOGGER.info('First boot state - %d', database['state'])
|
||||
return HttpResponseRedirect(reverse('first_boot:state%d' %
|
||||
database['state']))
|
||||
|
||||
if request.user.is_authenticated():
|
||||
return HttpResponseRedirect(reverse('apps:index'))
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user