def account_settings_page(): user = User.query.get(session['user']['id']) form = SettingsForm(name=user.name) return render_template("account_settings.html", user=user, form=form, user_privs=dump_user_privileges(user))
def make_admin_admin_form_object(user): user_form_obj = {} user_privs = dump_user_privileges(user) for key in privs.iterkeys(): user_form_obj["%d_%s" % (user.id, key.lower())] = key in user_privs return user_form_obj
def make_admin_admin_form_object(user): """Returns information about the user for use with an AdminAdminForm.""" user_form_obj = {} user_privs = dump_user_privileges(user) for key in privs.iterkeys(): user_form_obj["%d_%s" % (user.id, key.lower())] = key in user_privs return user_form_obj
def admin_console(): user = User.query.get(session['user']['id']) form_object = dict( ( (k.lower(),v) for k,v in app.config.iteritems()) ) configuration_form = ConfigurationForm(request.form, **form_object) admin_admin_forms = create_admin_admin_form() user_ids_to_names = dict( (u.id, u.name) for u in User.query.all() ) return render_template("admin.html", admin_admin_forms=admin_admin_forms, user_ids_to_names=user_ids_to_names, configuration_form=configuration_form, user=user, user_privs=dump_user_privileges(user))
def account_settings_update(): user = User.query.get(session['user']['id']) form = SettingsForm(request.form) if form.validate(): user.name = form.name.data if form.current_password.data != "" and form.new_password.data != "": if check_password_hash(user.password, form.current_password.data): user.password = generate_password_hash(form.new_password.data) else: return render_template("account_settings.html", user=user, form=form, user_privs=dump_user_privileges(user)) db.session.commit() return redirect(url_for('account_settings_page'))
def admin_console(): """Shows the admin console. admin.html expects a list of forms for the admin_admin functions, a dict of user ids and names, a configuration form, the current user, and the privileges a user has. """ user = User.query.get(session['user']['id']) form_object = dict(((k.lower(), v) for k, v in app.config.iteritems())) configuration_form = ConfigurationForm(request.form, **form_object) admin_admin_forms = create_admin_admin_form() user_ids_to_names = dict((u.id, u.name) for u in User.query.all()) return render_template("admin.html", admin_admin_forms=admin_admin_forms, user_ids_to_names=user_ids_to_names, configuration_form=configuration_form, user=user, user_privs=dump_user_privileges(user))
def admin_console(): """Shows the admin console. admin.html expects a list of forms for the admin_admin functions, a dict of user ids and names, a configuration form, the current user, and the privileges a user has. """ user = User.query.get(session['user']['id']) form_object = dict( ( (k.lower(),v) for k,v in app.config.iteritems()) ) configuration_form = ConfigurationForm(request.form, **form_object) admin_admin_forms = create_admin_admin_form() user_ids_to_names = dict( (u.id, u.name) for u in User.query.all() ) return render_template("admin.html", admin_admin_forms=admin_admin_forms, user_ids_to_names=user_ids_to_names, configuration_form=configuration_form, user=user, user_privs=dump_user_privileges(user))
def account_settings_update(): user = User.query.get(session["user"]["id"]) form = SettingsForm(request.form) if form.validate(): user.name = form.name.data if form.current_password.data != "" and form.new_password.data != "": if check_password_hash(user.password, form.current_password.data): user.password = generate_password_hash(form.new_password.data) else: return render_template("account_settings.html", user=user, form=form, user_privs=dump_user_privileges(user)) db.session.commit() return redirect(url_for("account_settings_page"))
def account_settings_page(): user = User.query.get(session["user"]["id"]) form = SettingsForm(name=user.name) return render_template("account_settings.html", user=user, form=form, user_privs=dump_user_privileges(user))
def player(): """Display the player page. Sends the user's queue and the global queue along and displays the player page.""" users_tracks = get_user_queue(session['user']['id']) global_queue = get_global_queue() config = {'lastfm_api_key': app.config['LASTFM_API_KEY'], 'lastfm_api_secret': app.config['LASTFM_API_SECRET']} user = User.query.get(session['user']['id']) # Do some logic to figure out if we need to show the admin console (i.e. the hostname or port for the MPD server are blank) if app.config['MPD_SERVER_HOSTNAME'] == "" or app.config['MPD_SERVER_PORT'] == "": if user_has_privilege(user, "ADMIN_INTERFACE") and user_has_privilege(user, "ADMIN_CONFIG"): return redirect(url_for("admin_console")) return render_template("player.html", user=user, user_play_queue=users_tracks, global_play_queue=global_queue, config=config, voting_enabled=needs_voting[app.config['SELECTION_SCHEME']], user_privs=dump_user_privileges(user))
def test_dump_user_privileges(self): assert dump_user_privileges(self.user) == [] give_user_privilege(self.user, "ADMIN_INTERFACE") assert "ADMIN_INTERFACE" in dump_user_privileges(self.user)