mirror of
https://github.com/chibicitiberiu/ytsm.git
synced 2024-02-24 05:43:31 +00:00
Fixed registration step of first time setup. General improvements to settings and first time setup wizard.
This commit is contained in:
45
app/YtManagerApp/views/forms/auth.py
Normal file
45
app/YtManagerApp/views/forms/auth.py
Normal file
@ -0,0 +1,45 @@
|
||||
from crispy_forms.helper import FormHelper
|
||||
from crispy_forms.layout import Submit
|
||||
from django import forms
|
||||
from django.contrib.auth.forms import AuthenticationForm, UserCreationForm
|
||||
from django.urls import reverse_lazy
|
||||
|
||||
|
||||
class ExtendedAuthenticationForm(AuthenticationForm):
|
||||
remember_me = forms.BooleanField(label='Remember me', required=False, initial=False)
|
||||
|
||||
def clean(self):
|
||||
remember_me = self.cleaned_data.get('remember_me')
|
||||
if remember_me:
|
||||
expiry = 3600 * 24 * 30
|
||||
else:
|
||||
expiry = 0
|
||||
self.request.session.set_expiry(expiry)
|
||||
|
||||
return super().clean()
|
||||
|
||||
|
||||
class ExtendedUserCreationForm(UserCreationForm):
|
||||
email = forms.EmailField(required=False,
|
||||
label='E-mail address',
|
||||
help_text='The e-mail address is optional, but it is the only way to recover a lost '
|
||||
'password.')
|
||||
first_name = forms.CharField(max_length=30, required=False,
|
||||
label='First name')
|
||||
last_name = forms.CharField(max_length=150, required=False,
|
||||
label='Last name')
|
||||
|
||||
form_action = reverse_lazy('register')
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.helper = FormHelper()
|
||||
self.helper.label_class = 'col-3'
|
||||
self.helper.field_class = 'col-9'
|
||||
self.helper.form_class = 'form-horizontal'
|
||||
self.helper.form_method = 'post'
|
||||
self.helper.form_action = self.form_action
|
||||
self.helper.add_input(Submit('submit', 'register'))
|
||||
|
||||
class Meta(UserCreationForm.Meta):
|
||||
fields = ['username', 'email', 'first_name', 'last_name']
|
108
app/YtManagerApp/views/forms/first_time.py
Normal file
108
app/YtManagerApp/views/forms/first_time.py
Normal file
@ -0,0 +1,108 @@
|
||||
import logging
|
||||
|
||||
from crispy_forms.helper import FormHelper
|
||||
from crispy_forms.layout import Layout, HTML, Submit, Column
|
||||
from django import forms
|
||||
from django.contrib.auth import authenticate, login
|
||||
from django.contrib.auth.models import User
|
||||
from YtManagerApp.views.forms.auth import ExtendedUserCreationForm
|
||||
from django.urls import reverse_lazy
|
||||
from YtManagerApp.management.appconfig import global_prefs
|
||||
|
||||
logger = logging.getLogger("FirstTimeWizard")
|
||||
|
||||
|
||||
class WelcomeForm(forms.Form):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.helper = FormHelper()
|
||||
self.helper.layout = Layout(
|
||||
Submit('submit', value='Continue')
|
||||
)
|
||||
|
||||
|
||||
class ApiKeyForm(forms.Form):
|
||||
api_key = forms.CharField(label="YouTube API Key:")
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.helper = FormHelper()
|
||||
self.helper.layout = Layout(
|
||||
'api_key',
|
||||
Column(
|
||||
Submit('submit', value='Continue'),
|
||||
HTML('<a href="{% url \'first_time_2\' %}" class="btn">Skip</a>')
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class UserCreationForm(ExtendedUserCreationForm):
|
||||
form_action = reverse_lazy('first_time_2')
|
||||
|
||||
|
||||
class PickAdminUserForm(forms.Form):
|
||||
admin_user = forms.ModelChoiceField(
|
||||
User.objects.order_by('username'),
|
||||
label='User to promote to admin',
|
||||
required=True)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.helper = FormHelper()
|
||||
self.helper.layout = Layout(
|
||||
'admin_user',
|
||||
Column(
|
||||
Submit('submit', value='Continue'),
|
||||
HTML('<a href="{% url \'first_time_2\' %}®ister=1" class="btn">Register a new admin user</a>')
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class ServerConfigForm(forms.Form):
|
||||
|
||||
allow_registrations = forms.BooleanField(
|
||||
label="Allow user registrations",
|
||||
help_text="Disabling this option will prevent anyone from registering to the site.",
|
||||
initial=True,
|
||||
required=False
|
||||
)
|
||||
|
||||
sync_schedule = forms.CharField(
|
||||
label="Synchronization schedule",
|
||||
help_text="How often should the application look for new videos.",
|
||||
initial="5 * * * *",
|
||||
required=True
|
||||
)
|
||||
|
||||
auto_download = forms.BooleanField(
|
||||
label="Download videos automatically",
|
||||
required=False
|
||||
)
|
||||
|
||||
download_location = forms.CharField(
|
||||
label="Download location",
|
||||
help_text="Location on the server where videos are downloaded.",
|
||||
required=True
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.helper = FormHelper()
|
||||
self.helper.layout = Layout(
|
||||
HTML('<h3>Server settings</h3>'),
|
||||
'sync_schedule',
|
||||
'allow_registrations',
|
||||
HTML('<h3>User settings</h3>'),
|
||||
'auto_download',
|
||||
'download_location',
|
||||
Submit('submit', value='Continue'),
|
||||
)
|
||||
|
||||
|
||||
class DoneForm(forms.Form):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.helper = FormHelper()
|
||||
self.helper.layout = Layout(
|
||||
Submit('submit', value='Finish')
|
||||
)
|
Reference in New Issue
Block a user