def edit_ssh_config_handler(config_id): config = SshConfig.query.filter_by(id=config_id).first() if config.author_id != current_user.id: flash(u'Don\'t have permission to access this link', 'error') return redirect(url_for('account.index_handler')) form = SshConfigForm(id=config.id, name=config.name, desc=config.desc, groups=config.groups, port=config.port, username=config.username, private_key=config.private_key) if request.method == 'POST' and form.validate(): if form.name.data != config.name: config.name = form.name.data if form.desc.data != config.desc: config.desc = form.desc.data config.set_groups(form.groups.data) if form.port.data != config.port: config.port = form.port.data if form.username.data != config.username: config.username = form.username.data if form.password.data != config.password: config.password = form.password.data if form.private_key.data != config.private_key: config.private_key = form.private_key.data db.session.commit() flash(u'Edit ssh configuration successfully', 'success') return redirect(url_for('account.list_ssh_config_handler')) else: return render_template('account/ssh_config.html', form=form, action='edit')
def create_ssh_config_handler(): form = SshConfigForm() if request.method == 'POST' and form.validate(): ssh_config = SshConfig(form.username.data, form.desc.data, current_user.id, form.groups.data, form.port.data, form.username.data, form.password.data, form.private_key.data) db.session.add(ssh_config) db.session.commit() flash(u'Creating ssh configuration successfully', 'success') return redirect(url_for('dashboard.list_ssh_config_handler')) else: return render_template('dashboard/ssh_config.html', form=form, action='create')
def create_ssh_config_handler(): form = SshConfigForm() if request.method == 'POST' and form.validate(): ssh_config = SshConfig(form.name.data, form.desc.data, current_user.id, form.groups.data, form.port.data, form.username.data, form.password.data, form.private_key.data) db.session.add(ssh_config) db.session.commit() flash(u'Creating ssh configuration successfully', 'success') return redirect(url_for('account.list_ssh_config_handler')) else: return render_template('account/ssh_config.html', form=form, action='create')