def process_config_page_posted_form(self, forms, form_name): # Return if system is in production mode. if c.mc.production_mode: return # Check if something was posted. if get_var('action') != "update": # Nothing posted. return # Get custom form if needed. show_errors_in_form = self.process_form_dict[form_name][2] # Validate the posted form, if required. fill_form = None if not (self.process_form_dict[form_name][1] & NO_FILL): # No such form, bail out. if not forms.forms.has_key(form_name): return # Fill the form with the posted variables. fill_form = forms.forms[form_name] fill_form.fill(request.params) # Convert exceptions (if any) to strings using the map. fill_form.localize_validation_exceptions(self.validation_exceptions_messages) # The form is not valid, bail out. if not fill_form.valid(): return try: # Dispatch form update. method = getattr(self, self.process_form_dict[form_name][0]) method(fill_form) # Update the configuration. save_master_config(c.mc) # Re-load services status after the change. tmp_mc = load_master_config() for name, service in c.services.items(): service.update_from_conf(tmp_mc) if fill_form: fill_form.confirmations = ['Changes have been saved.'] # Hide form if flag set. if self.process_form_dict[form_name][1] & HIDE_FORM and fill_form: fill_form.show = 0 except ErrorMsg, e: msg = str(e) if show_errors_in_form: s = c.template_store[show_errors_in_form] s.error = msg elif fill_form: fill_form.notices += [msg]
def login(self): # The user is already logged in; redirect to the status page. if web_session.has_key('logged') and web_session['logged']: return redirect(url_for('status')) # Initialize web session. self._init_session() # Load master config. master_config = load_master_config() # FIXME: isinstance(...) could be removed if property has a null=False parameter... check that with Laurent. pwd = None if isinstance(master_config.admin_pwd, basestring) and len(master_config.admin_pwd) > 0: # Admin password is set. # Get the provided password, if any. pwd = request.POST.get('cfg_password', None) if pwd: if pwd == master_config.admin_pwd: # User has provided the right password. self._login() # Redirect to the status page. return redirect(url_for('status')) else: # Show a bad password message. ui_error(message=GT("login.bad_password")) else: # Admin password is not set yet; show a warning message. ui_error(message=GT("locals.admin_password_not_set")) # Push variables to template. c.pwd = pwd c.GT = GT return render('/login/login.mako')
def process_config_page_posted_form(self, forms, form_name): # Return if system is in production mode. if c.mc.production_mode: return # Check if something was posted. if get_var('action') != "update": # Nothing posted. return # Get custom form if needed. show_errors_in_form = self.process_form_dict[form_name][2] # Validate the posted form, if required. fill_form = None if not (self.process_form_dict[form_name][1] & NO_FILL): # No such form, bail out. if not forms.forms.has_key(form_name): return # Fill the form with the posted variables. fill_form = forms.forms[form_name] fill_form.fill(request.params) # Convert exceptions (if any) to strings using the map. fill_form.localize_validation_exceptions( self.validation_exceptions_messages) # The form is not valid, bail out. if not fill_form.valid(): return try: # Dispatch form update. method = getattr(self, self.process_form_dict[form_name][0]) method(fill_form) # Update the configuration. save_master_config(c.mc) # Re-load services status after the change. tmp_mc = load_master_config() for name, service in c.services.items(): service.update_from_conf(tmp_mc) if fill_form: fill_form.confirmations = ['Changes have been saved.'] # Hide form if flag set. if self.process_form_dict[form_name][1] & HIDE_FORM and fill_form: fill_form.show = 0 except ErrorMsg, e: msg = str(e) if show_errors_in_form: s = c.template_store[show_errors_in_form] s.error = msg elif fill_form: fill_form.notices += [msg]