Пример #1
0
def admins_edit(name=None):
	action = 'delete' if request.args.get('action', request.form.get('action')) == 'delete' else 'edit'
	if 'username' not in session: return goto_login(fname(), fparms())
	if not name:
		return redirect(url_for('admins'))
	if request.method == 'POST':
		if action == 'edit':
			password = request.form.get('new_password')
			if password:
				webadm.set(name, password)
				flash('User <i>%s</i> updated.' % Markup.escape(name), 'success')
			else:
				flash('Password must not be empty.', 'error')
				return redirect(url_for('admins_edit', name=name))
		elif action == 'delete':
			if len(webadm.list()) == 1:
				flash('You can\'t delete the last user.', 'error')
				return redirect(url_for('admins'))
			webadm.remove(name)
			flash('User <i>%s</i> deleted.' % Markup.escape(name), 'success')
		return redirect(url_for('admins'))
	return render_template('admins_edit.html', navigation=get_navi('admins'), admin=name, action=action)
Пример #2
0
def admins():
	"Admins"
	if request.method == 'POST':
		return redirect(url_for('admins_edit', name=request.form.get('newname')))
	admin_list = webadm.list()
	return render_template('admins.html', navigation=get_navi(fname()), admin_list=admin_list)