Adding password confirm fields
Change-Id: Ie0d92b3825dbae3adebcfc4aa4e992e994774ec6
This commit is contained in:
parent
e44afd0595
commit
8fa36d8807
|
@ -21,6 +21,7 @@ import re
|
|||
from muranodashboard.panel import api
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
CONFIRM_ERR_DICT = {'required': _('Please confirm your password')}
|
||||
|
||||
|
||||
class PasswordField(forms.CharField):
|
||||
|
@ -38,7 +39,7 @@ class PasswordField(forms.CharField):
|
|||
validators=[self.validate_password],
|
||||
label=label,
|
||||
error_messages={'invalid': self.validate_password.message},
|
||||
widget=forms.PasswordInput(render_value=False), *args, **kwargs)
|
||||
widget=forms.PasswordInput(render_value=False))
|
||||
|
||||
|
||||
class WizardFormServiceType(forms.Form):
|
||||
|
@ -63,6 +64,26 @@ class WizardFormConfiguration(forms.Form):
|
|||
pass
|
||||
|
||||
|
||||
class ServiceConfigurationForm(forms.Form):
|
||||
def clean(self):
|
||||
form_data = self.cleaned_data
|
||||
admin_pwd1 = form_data.get('adm_password')
|
||||
admin_pwd2 = form_data.get('adm_password2')
|
||||
|
||||
if admin_pwd1 != admin_pwd2:
|
||||
raise forms.ValidationError(
|
||||
_('Administrator passwords don\'t match'))
|
||||
|
||||
recovery_pwd1 = form_data.get('recovery_password')
|
||||
if recovery_pwd1:
|
||||
recovery_pwd2 = form_data.get('recovery_password2')
|
||||
if recovery_pwd1 != recovery_pwd2:
|
||||
raise forms.ValidationError(
|
||||
_('Recovery passwords don\'t match'))
|
||||
|
||||
return self.cleaned_data
|
||||
|
||||
|
||||
class CommonPropertiesExtension(object):
|
||||
def __init__(self):
|
||||
self.fields.insert(
|
||||
|
@ -74,7 +95,8 @@ class CommonPropertiesExtension(object):
|
|||
instance.widget.attrs['placeholder'] = 'Optional'
|
||||
|
||||
|
||||
class WizardFormADConfiguration(forms.Form, CommonPropertiesExtension):
|
||||
class WizardFormADConfiguration(ServiceConfigurationForm,
|
||||
CommonPropertiesExtension):
|
||||
domain_name_re = re.compile(
|
||||
r'^[a-zA-Z0-9][a-zA-Z0-9.-]*[a-zA-Z0-9]$')
|
||||
validate_domain_name = RegexValidator(domain_name_re,
|
||||
|
@ -96,15 +118,20 @@ class WizardFormADConfiguration(forms.Form, CommonPropertiesExtension):
|
|||
initial=1)
|
||||
|
||||
adm_password = PasswordField(_('Administrator password'))
|
||||
adm_password2 = \
|
||||
PasswordField(_('Confirm password'), error_messages=CONFIRM_ERR_DICT)
|
||||
|
||||
recovery_password = PasswordField(_('Recovery password'))
|
||||
recovery_password2 = \
|
||||
PasswordField(_('Confirm password'), error_messages=CONFIRM_ERR_DICT)
|
||||
|
||||
def __init__(self, request, *args, **kwargs):
|
||||
super(WizardFormADConfiguration, self).__init__(*args, **kwargs)
|
||||
CommonPropertiesExtension.__init__(self)
|
||||
|
||||
|
||||
class WizardFormIISConfiguration(forms.Form, CommonPropertiesExtension):
|
||||
class WizardFormIISConfiguration(ServiceConfigurationForm,
|
||||
CommonPropertiesExtension):
|
||||
name_re = re.compile(r'^[-\w]+$')
|
||||
validate_name = RegexValidator(name_re,
|
||||
_(u'Just letters, numbers, underscores \
|
||||
|
@ -118,6 +145,8 @@ class WizardFormIISConfiguration(forms.Form, CommonPropertiesExtension):
|
|||
error_messages={'invalid': validate_name.message})
|
||||
|
||||
adm_password = PasswordField(_('Administrator password'))
|
||||
adm_password2 = \
|
||||
PasswordField(_('Confirm password'), error_messages=CONFIRM_ERR_DICT)
|
||||
|
||||
iis_domain = forms.ChoiceField(
|
||||
label=_('Domain'),
|
||||
|
@ -138,7 +167,7 @@ class WizardFormIISConfiguration(forms.Form, CommonPropertiesExtension):
|
|||
CommonPropertiesExtension.__init__(self)
|
||||
|
||||
|
||||
class WebFarmExtension(forms.Form):
|
||||
class WebFarmExtension(ServiceConfigurationForm):
|
||||
instance_count = forms.IntegerField(
|
||||
label=_('Instance Count'),
|
||||
min_value=1,
|
||||
|
|
|
@ -17,7 +17,6 @@ from muranoclient.common.exceptions import \
|
|||
CommunicationError, HTTPInternalServerError
|
||||
import re
|
||||
|
||||
from django.views import generic
|
||||
from django.core.urlresolvers import reverse, reverse_lazy
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.contrib.formtools.wizard.views import SessionWizardView
|
||||
|
@ -44,7 +43,7 @@ from forms import WizardFormAspNetFarmConfiguration
|
|||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Wizard(ModalFormMixin, SessionWizardView, generic.FormView):
|
||||
class Wizard(ModalFormMixin, SessionWizardView):
|
||||
template_name = 'services_tabs.html'
|
||||
|
||||
def done(self, form_list, **kwargs):
|
||||
|
@ -52,23 +51,28 @@ class Wizard(ModalFormMixin, SessionWizardView, generic.FormView):
|
|||
environment_id = re.search('murano/(\S+)', link).group(0)[7:-9]
|
||||
|
||||
url = "/project/murano/%s/services" % environment_id
|
||||
step0_data = form_list[0].cleaned_data
|
||||
step1_data = form_list[1].cleaned_data
|
||||
|
||||
service_type = step0_data.get('service', '')
|
||||
|
||||
service_type = form_list[0].data.get('0-service', '')
|
||||
parameters = {'service_type': service_type}
|
||||
data = form_list[1].data
|
||||
|
||||
parameters['units'] = []
|
||||
parameters['unitNamingPattern'] = data.get(
|
||||
'1-unit_name_template', None)
|
||||
parameters['unitNamingPattern'] = step1_data.get(
|
||||
'unit_name_template', None)
|
||||
|
||||
if service_type == 'Active Directory':
|
||||
parameters['configuration'] = 'standalone'
|
||||
parameters['name'] = str(data.get('1-dc_name', 'noname'))
|
||||
parameters['name'] = str(step1_data.get('1-dc_name', 'noname'))
|
||||
parameters['domain'] = parameters['name'] # Fix Me in orchestrator
|
||||
parameters['adminPassword'] = str(data.get('1-adm_password', ''))
|
||||
recovery_password = str(data.get('1-recovery_password', ''))
|
||||
parameters['adminPassword'] = \
|
||||
str(step1_data.get('adm_password', ''))
|
||||
recovery_password = str(step1_data.get('recovery_password', ''))
|
||||
parameters['units'].append({'isMaster': True,
|
||||
'recoveryPassword': recovery_password,
|
||||
'location': 'west-dc'})
|
||||
dc_count = int(data.get('1-dc_count', 1))
|
||||
dc_count = int(step1_data.get('dc_count', 1))
|
||||
for dc in range(dc_count - 1):
|
||||
parameters['units'].append({
|
||||
'isMaster': False,
|
||||
|
@ -77,15 +81,15 @@ class Wizard(ModalFormMixin, SessionWizardView, generic.FormView):
|
|||
|
||||
elif service_type in ['IIS', 'ASP.NET Application',
|
||||
'IIS Farm', 'ASP.NET Farm']:
|
||||
password = data.get('1-adm_password', '')
|
||||
parameters['name'] = str(data.get('1-iis_name', 'noname'))
|
||||
password = step1_data.get('adm_password', '')
|
||||
parameters['name'] = str(step1_data.get('iis_name', 'noname'))
|
||||
parameters['credentials'] = {'username': 'Administrator',
|
||||
'password': password}
|
||||
parameters['domain'] = str(data.get('1-iis_domain', ''))
|
||||
password = form_list[1].data.get('1-adm_password', '')
|
||||
domain = form_list[1].data.get('1-iis_domain', '')
|
||||
parameters['name'] = str(form_list[1].data.get('1-iis_name',
|
||||
'noname'))
|
||||
|
||||
parameters['domain'] = str(step1_data.get('iis_domain', ''))
|
||||
password = step1_data.get('adm_password', '')
|
||||
domain = step1_data.get('iis_domain', '')
|
||||
parameters['name'] = str(step1_data.get('iis_name', 'noname'))
|
||||
parameters['domain'] = parameters['name']
|
||||
parameters['adminPassword'] = password
|
||||
parameters['domain'] = str(domain)
|
||||
|
@ -93,11 +97,12 @@ class Wizard(ModalFormMixin, SessionWizardView, generic.FormView):
|
|||
if service_type == 'ASP.NET Application' \
|
||||
or service_type == 'ASP.NET Farm':
|
||||
parameters['repository'] = \
|
||||
form_list[1].data.get('1-repository', '')
|
||||
step1_data.get('repository', '')
|
||||
instance_count = 1
|
||||
if service_type == 'IIS Farm' or service_type == 'ASP.NET Farm':
|
||||
instance_count = int(data.get('1-instance_count', 1))
|
||||
parameters['loadBalancerPort'] = int(data.get('1-lb_port', 80))
|
||||
instance_count = int(step1_data.get('instance_count', 1))
|
||||
parameters['loadBalancerPort'] =\
|
||||
int(step1_data.get('lb_port', 80))
|
||||
|
||||
for unit in range(instance_count):
|
||||
parameters['units'].append({})
|
||||
|
@ -134,10 +139,6 @@ class Wizard(ModalFormMixin, SessionWizardView, generic.FormView):
|
|||
def get_form_kwargs(self, step=None):
|
||||
return {'request': self.request} if step == u'1' else {}
|
||||
|
||||
def get_form_step_data(self, form):
|
||||
LOG.debug(form.data)
|
||||
return form.data
|
||||
|
||||
def get_context_data(self, form, **kwargs):
|
||||
context = super(Wizard, self).get_context_data(form=form, **kwargs)
|
||||
if self.steps.index > 0:
|
||||
|
|
Loading…
Reference in New Issue