def index(self): form = EditGlauthForm() settings = Settings.query.get(1) if form.validate_on_submit(): # Store edited data in db and write to config settings.debug = form.debug.data settings.ldap_enabled = form.ldap_enabled.data settings.ldap_listen = form.ldap_listen.data settings.ldaps_enabled = form.ldaps_enabled.data settings.ldaps_listen = form.ldaps_listen.data settings.ldaps_cert = form.ldaps_cert.data settings.ldaps_key = form.ldaps_key.data settings.basedn = form.basedn.data db.session.commit() create_glauth_config() flash('Glauth settings have been changed, please restart glauth server.') if request.method == 'GET': # Populate form with stored config form.debug.data = settings.debug form.ldap_enabled.data = settings.ldap_enabled form.ldap_listen.data = settings.ldap_listen form.ldaps_enabled.data = settings.ldaps_enabled form.ldaps_listen.data = settings.ldaps_listen form.ldaps_cert.data = settings.ldaps_cert form.ldaps_key.data = settings.ldaps_key form.basedn.data = settings.basedn return self.render('admin/glauth.html', form=form)
def on_model_change(self, form, model, is_created): # is_created = True if new model/user # model = User object # form = Form object (form.<columnname>.data) # Write new glauth config File create_glauth_config() pass
def on_model_change(self, form, model, is_created): # is_created = True if new model/user # model = User object # form = Form object (form.<columnname>.data) # If new users was created without password if is_created: if form.send_invite_link.data and ((not form.mail.data) or form.mail.data == ''): raise ValidationError( 'A valid Email Address is required for sending invite links.' ) if not form.password.data or form.password.data == '': # Generate random password password = ''.join( choices(ascii_uppercase + ascii_lowercase + digits, k=8)) model.set_password(password) # If Send Activation Link Option Enabled if form.send_invite_link.data and (form.mail.data != ('' or None)): model.is_active = False # errors with threaded emails wont get caught... send_account_invite(model) flash('Email with activation link was send to {}'.format( model.mail)) else: flash('Autogenerated password for new user {}: {}'.format( model.username, password)) else: model.set_password(form.password.data) else: # If Password Field attribute exists if hasattr(form, 'password'): # If Attribute Value is not '' if form.password.data != '': # Create password hash from password model.set_password(form.password.data) # If Reset PW Optione is enabled if hasattr(form, 'send_pw_reset_link'): if form.send_pw_reset_link.data and ((not form.mail.data) or form.mail.data == ''): raise ValidationError( 'A valid Email Address is required for sending password reset links.' ) if form.send_pw_reset_link.data: # Disable Account model.is_active = False send_password_reset_email(model) flash('Reset Password Link was send to {}'.format( model.mail)) # Write new glauth config File try: create_glauth_config() except Exception: pass
def index(self): form = EditGlauthForm() settings = Settings.query.get(1) nameformat = "cn" groupformat = "ou" if settings.nameformat and (settings.nameformat != ""): nameformat = settings.nameformat if settings.groupformat and (settings.groupformat != ""): groupformat = settings.groupformat dnformat = '{}=<username>,{}=<primarygroup>,{}'.format( nameformat, groupformat, settings.basedn) if form.validate_on_submit(): # Store edited data in db and write to config settings.debug = form.debug.data settings.ldap_enabled = form.ldap_enabled.data settings.ldap_listen = form.ldap_listen.data settings.ldaps_enabled = form.ldaps_enabled.data settings.ldaps_listen = form.ldaps_listen.data settings.ldaps_cert = form.ldaps_cert.data settings.ldaps_key = form.ldaps_key.data settings.basedn = form.basedn.data settings.nameformat = form.nameformat.data settings.groupformat = form.groupformat.data settings.sshkeyattr = form.sshkeyattr.data db.session.commit() try: create_glauth_config() flash( 'Glauth settings have been changed, please restart glauth server.' ) except Exception as exc: flash('Glauth settings NOT updated, an error occured: ' + str(exc)) if request.method == 'GET': # Populate form with stored config form.debug.data = settings.debug form.ldap_enabled.data = settings.ldap_enabled form.ldap_listen.data = settings.ldap_listen form.ldaps_enabled.data = settings.ldaps_enabled form.ldaps_listen.data = settings.ldaps_listen form.ldaps_cert.data = settings.ldaps_cert form.ldaps_key.data = settings.ldaps_key form.basedn.data = settings.basedn form.nameformat.data = settings.nameformat form.groupformat.data = settings.groupformat form.sshkeyattr.data = settings.sshkeyattr return self.render('admin/glauth.html', form=form, dnformat=dnformat)
def after_model_delete(self, model): # Write new glauth config File create_glauth_config() pass
def after_model_delete(self, model): # Write new glauth config File try: create_glauth_config() except Exception: pass