mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
plinth/*: Rename plinth/ folder to freedombox/
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
1 parent
dd0161a7e5
commit
23b6aff290
1264 files changed
No files matched your search
@@ -0,0 +1,35 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
from django import forms
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from plinth import cfg
|
||||
from plinth.modules import first_boot
|
||||
|
||||
|
||||
class FirstbootWizardSecretForm(forms.Form):
|
||||
"""Form to collect and validate the first boot wizard secret."""
|
||||
secret = forms.CharField(
|
||||
label='', help_text=_(
|
||||
'Enter the secret generated during {box_name} installation. '
|
||||
'This secret can be obtained by running the command "sudo '
|
||||
'cat /var/lib/plinth/firstboot-wizard-secret" on your {box_name}'.
|
||||
format(box_name=_(cfg.box_name))), required=False,
|
||||
widget=forms.PasswordInput(
|
||||
attrs={'placeholder': _('Firstboot Wizard Secret')}))
|
||||
|
||||
def validate_secret(self, secret):
|
||||
"""Match the secret provided by the user with the one
|
||||
generated during installation.
|
||||
"""
|
||||
secret_file_path = first_boot.get_secret_file_path()
|
||||
with open(secret_file_path, encoding='utf-8') as secret_file:
|
||||
if secret != secret_file.read().strip():
|
||||
self.add_error('secret', 'Invalid secret')
|
||||
|
||||
def clean(self):
|
||||
"""Override clean to add form validation logic."""
|
||||
cleaned_data = super().clean()
|
||||
if first_boot.firstboot_wizard_secret_exists():
|
||||
self.validate_secret(cleaned_data.get("secret"))
|
||||
return cleaned_data
|
||||
Reference in new issue
Block a user