def save_config(connection, path, config_name): """ Saves config file with new content. Returns empty string for valid flask response and error message otherwise. """ new_content = request.values.get('content', '') root_passwd = request.values.get('root_passwd', '') if root_passwd and creds_validator('root', root_passwd) and new_content: try: f = connection.get_file(os.path.join(path, config_name), 'w') except Exception as e: logger.exception(e) return 'Error while opening file %s.<br>%s' % (config_name, e) else: f.write(new_content) f.close() logger.info('%s was successfully saved.' % config_name) elif not new_content: msg = 'Attempting for writing of empty content to %s.' % config_name logger.error(msg) return msg else: return 'Invalid root password.' return ''
def login(): form = LoginForm(request.form) if request.method == 'POST' and form.validate(): username = form.username.data password = form.password.data # check credentials if creds_validator(username, password): session['username'] = username flash('Login successful') return redirect(request.form['next_url']) else: form.password.errors.append("Invalid username or password") else: flash('Invalid credentials') return render_template('login.html', title='Sign In', form=form)
def login(): form = LoginForm(request.form) if request.method == 'POST' and form.validate(): username = form.username.data password = form.password.data # check credentials if creds_validator(username, password): session['username'] = username flash('Login successful') return redirect(request.form['next_url']) else: form.password.errors.append("Invalid username or password") else: flash('Invalid credentials') return render_template('login.html', title = 'Sign In', form = form)