mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-27 10:44:33 +00:00
Made Suggested Changes
This commit is contained in:
parent
0290f68ae6
commit
6011a7adfa
@ -22,7 +22,6 @@ Forms for first boot module.
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import requests
|
import requests
|
||||||
import subprocess
|
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib import auth
|
from django.contrib import auth
|
||||||
@ -43,6 +42,7 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class State1Form(ValidNewUsernameCheckMixin, auth.forms.UserCreationForm):
|
class State1Form(ValidNewUsernameCheckMixin, auth.forms.UserCreationForm):
|
||||||
"""Firstboot state 1: create a new user."""
|
"""Firstboot state 1: create a new user."""
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.request = kwargs.pop('request')
|
self.request = kwargs.pop('request')
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
@ -103,22 +103,6 @@ class State1Form(ValidNewUsernameCheckMixin, auth.forms.UserCreationForm):
|
|||||||
messages.success(self.request, message)
|
messages.success(self.request, message)
|
||||||
|
|
||||||
|
|
||||||
class SubdomainWidget(forms.widgets.TextInput):
|
|
||||||
"""Append the domain to the subdomain bootstrap input field"""
|
|
||||||
def __init__(self, domain, *args, **kwargs):
|
|
||||||
"""Intialize the widget by storing the domain value."""
|
|
||||||
super().__init__(*args, **kwargs)
|
|
||||||
self.domain = domain
|
|
||||||
|
|
||||||
def render(self, *args, **kwargs):
|
|
||||||
"""Return the HTML for the widget."""
|
|
||||||
inputfield = super().render(*args, **kwargs)
|
|
||||||
return """<div class="input-group">
|
|
||||||
{0}
|
|
||||||
<span class="input-group-addon">{1}</span>
|
|
||||||
</div>""".format(inputfield, self.domain)
|
|
||||||
|
|
||||||
|
|
||||||
class State5Form(forms.Form):
|
class State5Form(forms.Form):
|
||||||
"""Set up freedombox.me pagekite subdomain"""
|
"""Set up freedombox.me pagekite subdomain"""
|
||||||
DOMAIN_APPENDIX = '.freedombox.me'
|
DOMAIN_APPENDIX = '.freedombox.me'
|
||||||
|
|||||||
@ -26,10 +26,11 @@ from django.conf import settings
|
|||||||
import logging
|
import logging
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from plinth import kvstore, module_loader
|
from plinth import kvstore, module_loader
|
||||||
from django.shortcuts import render
|
|
||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
firstboot_steps = []
|
||||||
|
|
||||||
|
|
||||||
class FirstBootMiddleware(object):
|
class FirstBootMiddleware(object):
|
||||||
"""Forward to firstboot page if firstboot isn't finished yet."""
|
"""Forward to firstboot page if firstboot isn't finished yet."""
|
||||||
@ -37,7 +38,11 @@ class FirstBootMiddleware(object):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def process_request(request):
|
def process_request(request):
|
||||||
"""Handle a request as Django middleware request handler."""
|
"""Handle a request as Django middleware request handler."""
|
||||||
state = kvstore.get_default('firstboot_state', 0)
|
old_state = kvstore.get_default('firstboot_state', 0)
|
||||||
|
state = kvstore.get_default('setup_state', 0)
|
||||||
|
if state == 0 and old_state == 10:
|
||||||
|
state = 1
|
||||||
|
kvstore.set('setup_state', 1)
|
||||||
user_requests_firstboot = is_firstboot(request.path)
|
user_requests_firstboot = is_firstboot(request.path)
|
||||||
user_requests_login = request.path.startswith(reverse(settings.LOGIN_URL))
|
user_requests_login = request.path.startswith(reverse(settings.LOGIN_URL))
|
||||||
help_index_url = reverse('help:index')
|
help_index_url = reverse('help:index')
|
||||||
@ -77,8 +82,10 @@ def get_firstboot_steps():
|
|||||||
|
|
||||||
def next_step():
|
def next_step():
|
||||||
""" Returns the next first boot step required to run """
|
""" Returns the next first boot step required to run """
|
||||||
steps = get_firstboot_steps()
|
global firstboot_steps
|
||||||
for step in steps:
|
if len(firstboot_steps) == 0:
|
||||||
|
firstboot_steps = get_firstboot_steps()
|
||||||
|
for step in firstboot_steps:
|
||||||
done = kvstore.get_default(step.get('id'), 0)
|
done = kvstore.get_default(step.get('id'), 0)
|
||||||
if done == 0:
|
if done == 0:
|
||||||
return step.get('url')
|
return step.get('url')
|
||||||
@ -90,3 +97,14 @@ def mark_step_done(id):
|
|||||||
:param id: id of the firstboot step
|
:param id: id of the firstboot step
|
||||||
"""
|
"""
|
||||||
kvstore.set(id, 1)
|
kvstore.set(id, 1)
|
||||||
|
global firstboot_steps
|
||||||
|
if len(firstboot_steps) == 0:
|
||||||
|
firstboot_steps = get_firstboot_steps()
|
||||||
|
setup_done = True
|
||||||
|
for step in firstboot_steps:
|
||||||
|
done = kvstore.get_default(step.get('id'), 0)
|
||||||
|
if done == 0:
|
||||||
|
setup_done = False
|
||||||
|
break
|
||||||
|
if setup_done:
|
||||||
|
kvstore.set('setup_state', 1)
|
||||||
|
|||||||
@ -15,19 +15,11 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
|
||||||
from django.contrib import messages
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.http.response import HttpResponseRedirect
|
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.urls import reverse_lazy
|
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
from django.views.generic import CreateView, FormView, TemplateView
|
from django.views.generic import CreateView, FormView, TemplateView
|
||||||
|
|
||||||
from plinth import cfg
|
|
||||||
from plinth import kvstore
|
|
||||||
from plinth import network
|
from plinth import network
|
||||||
from plinth.errors import DomainRegistrationError
|
|
||||||
from .forms import State1Form, State5Form
|
|
||||||
from .middleware import mark_step_done, next_step
|
from .middleware import mark_step_done, next_step
|
||||||
|
|
||||||
|
|
||||||
@ -51,7 +43,7 @@ def state10(request):
|
|||||||
"""
|
"""
|
||||||
# Make sure that a user exists before finishing firstboot
|
# Make sure that a user exists before finishing firstboot
|
||||||
if User.objects.all():
|
if User.objects.all():
|
||||||
mark_step_done('firstboot_state')
|
mark_step_done('firstboot_state10')
|
||||||
|
|
||||||
connections = network.get_connection_list()
|
connections = network.get_connection_list()
|
||||||
|
|
||||||
|
|||||||
@ -27,7 +27,6 @@ import logging
|
|||||||
|
|
||||||
from plinth import cfg
|
from plinth import cfg
|
||||||
from plinth.errors import ActionError, DomainRegistrationError
|
from plinth.errors import ActionError, DomainRegistrationError
|
||||||
from plinth.modules.first_boot.forms import SubdomainWidget
|
|
||||||
from plinth.modules.pagekite.utils import PREDEFINED_SERVICES, run
|
from plinth.modules.pagekite.utils import PREDEFINED_SERVICES, run
|
||||||
from plinth.utils import format_lazy
|
from plinth.utils import format_lazy
|
||||||
|
|
||||||
@ -38,6 +37,7 @@ LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class TrimmedCharField(forms.CharField):
|
class TrimmedCharField(forms.CharField):
|
||||||
"""Trim the contents of a CharField"""
|
"""Trim the contents of a CharField"""
|
||||||
|
|
||||||
def clean(self, value):
|
def clean(self, value):
|
||||||
"""Clean and validate the field value"""
|
"""Clean and validate the field value"""
|
||||||
if value:
|
if value:
|
||||||
@ -46,6 +46,23 @@ class TrimmedCharField(forms.CharField):
|
|||||||
return super(TrimmedCharField, self).clean(value)
|
return super(TrimmedCharField, self).clean(value)
|
||||||
|
|
||||||
|
|
||||||
|
class SubdomainWidget(forms.widgets.TextInput):
|
||||||
|
"""Append the domain to the subdomain bootstrap input field"""
|
||||||
|
|
||||||
|
def __init__(self, domain, *args, **kwargs):
|
||||||
|
"""Intialize the widget by storing the domain value."""
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.domain = domain
|
||||||
|
|
||||||
|
def render(self, *args, **kwargs):
|
||||||
|
"""Return the HTML for the widget."""
|
||||||
|
inputfield = super().render(*args, **kwargs)
|
||||||
|
return """<div class="input-group">
|
||||||
|
{0}
|
||||||
|
<span class="input-group-addon">{1}</span>
|
||||||
|
</div>""".format(inputfield, self.domain)
|
||||||
|
|
||||||
|
|
||||||
class ConfigurationForm(forms.Form):
|
class ConfigurationForm(forms.Form):
|
||||||
"""Configure PageKite credentials and frontend"""
|
"""Configure PageKite credentials and frontend"""
|
||||||
|
|
||||||
@ -191,7 +208,6 @@ class BaseCustomServiceForm(forms.Form):
|
|||||||
|
|
||||||
|
|
||||||
class DeleteCustomServiceForm(BaseCustomServiceForm):
|
class DeleteCustomServiceForm(BaseCustomServiceForm):
|
||||||
|
|
||||||
def delete(self, request):
|
def delete(self, request):
|
||||||
service = self.convert_formdata_to_service(self.cleaned_data)
|
service = self.convert_formdata_to_service(self.cleaned_data)
|
||||||
utils.run(['remove-service', '--service', json.dumps(service)])
|
utils.run(['remove-service', '--service', json.dumps(service)])
|
||||||
@ -244,6 +260,8 @@ class AddCustomServiceForm(BaseCustomServiceForm):
|
|||||||
messages.error(request, _('This service already exists'))
|
messages.error(request, _('This service already exists'))
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
class State5Form(forms.Form):
|
class State5Form(forms.Form):
|
||||||
"""Set up freedombox.me pagekite subdomain"""
|
"""Set up freedombox.me pagekite subdomain"""
|
||||||
DOMAIN_APPENDIX = '.freedombox.me'
|
DOMAIN_APPENDIX = '.freedombox.me'
|
||||||
|
|||||||
@ -21,7 +21,6 @@ from django.urls import reverse, reverse_lazy
|
|||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.views.generic import View, TemplateView
|
from django.views.generic import View, TemplateView
|
||||||
from django.views.generic.edit import FormView
|
from django.views.generic.edit import FormView
|
||||||
from plinth import kvstore
|
|
||||||
from plinth.errors import DomainRegistrationError
|
from plinth.errors import DomainRegistrationError
|
||||||
|
|
||||||
from . import utils
|
from . import utils
|
||||||
|
|||||||
@ -28,9 +28,10 @@ from django.utils.translation import ugettext as _, ugettext_lazy
|
|||||||
from plinth import actions
|
from plinth import actions
|
||||||
from plinth.errors import ActionError
|
from plinth.errors import ActionError
|
||||||
|
|
||||||
# Usernames used by optional services (that might not be installed yet).
|
|
||||||
from plinth.modules.security import set_restricted_access
|
from plinth.modules.security import set_restricted_access
|
||||||
|
|
||||||
|
# Usernames used by optional services (that might not be installed yet).
|
||||||
|
|
||||||
RESERVED_USERNAMES = [
|
RESERVED_USERNAMES = [
|
||||||
'debian-deluged',
|
'debian-deluged',
|
||||||
'Debian-minetest',
|
'Debian-minetest',
|
||||||
@ -55,6 +56,7 @@ GROUP_CHOICES = (
|
|||||||
|
|
||||||
class ValidNewUsernameCheckMixin(object):
|
class ValidNewUsernameCheckMixin(object):
|
||||||
"""Mixin to check if a username is valid for created new user."""
|
"""Mixin to check if a username is valid for created new user."""
|
||||||
|
|
||||||
def clean_username(self):
|
def clean_username(self):
|
||||||
"""Check for username collisions with system users."""
|
"""Check for username collisions with system users."""
|
||||||
username = self.cleaned_data['username']
|
username = self.cleaned_data['username']
|
||||||
@ -244,8 +246,10 @@ class UserChangePasswordForm(SetPasswordForm):
|
|||||||
|
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
class State1Form(ValidNewUsernameCheckMixin, auth.forms.UserCreationForm):
|
class State1Form(ValidNewUsernameCheckMixin, auth.forms.UserCreationForm):
|
||||||
"""Firstboot state 1: create a new user."""
|
"""Firstboot state 1: create a new user."""
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.request = kwargs.pop('request')
|
self.request = kwargs.pop('request')
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|||||||
@ -22,10 +22,9 @@ from django.contrib.messages.views import SuccessMessageMixin
|
|||||||
from django.urls import reverse, reverse_lazy
|
from django.urls import reverse, reverse_lazy
|
||||||
from django.views.generic.edit import (CreateView, DeleteView, UpdateView,
|
from django.views.generic.edit import (CreateView, DeleteView, UpdateView,
|
||||||
FormView)
|
FormView)
|
||||||
from django.views.generic import ListView, CreateView
|
from django.views.generic import ListView, CreateView as CV
|
||||||
from django.utils.translation import ugettext as _, ugettext_lazy
|
from django.utils.translation import ugettext as _, ugettext_lazy
|
||||||
from plinth import cfg
|
from plinth import cfg
|
||||||
from plinth import kvstore
|
|
||||||
|
|
||||||
from .forms import CreateUserForm, UserChangePasswordForm, UserUpdateForm, State1Form
|
from .forms import CreateUserForm, UserChangePasswordForm, UserUpdateForm, State1Form
|
||||||
|
|
||||||
@ -169,7 +168,7 @@ class UserChangePassword(ContextMixin, SuccessMessageMixin, FormView):
|
|||||||
return super(UserChangePassword, self).form_valid(form)
|
return super(UserChangePassword, self).form_valid(form)
|
||||||
|
|
||||||
|
|
||||||
class State1View(CreateView):
|
class State1View(CV):
|
||||||
"""Create user account and log the user in."""
|
"""Create user account and log the user in."""
|
||||||
template_name = 'firstboot_state1.html'
|
template_name = 'firstboot_state1.html'
|
||||||
form_class = State1Form
|
form_class = State1Form
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user