예제 #1
0
def settings():
    form = SettingsForm(request.form,
                        username=current_user.username,
                        email=current_user.mail,
                        show_def_name=current_user.get_setting(code='show_def_name'),
                        show_def_desc=current_user.get_setting(code='show_def_desc'),
                        show_def_tags=current_user.get_setting(code='show_def_tags'),
                        show_def_logo=current_user.get_setting(code='show_def_logo'),
                        use_icy=current_user.get_setting(code='use_icy'))

    if request.method == "POST" and form.validate():
        if current_user.check_password(password=form.old_password.data):
            if form.new_password.data:
                current_user.password = User.make_password(form.new_password.data)
            current_user.mail = form.email.data
            current_user.set_setting(code='show_def_name', value=form.show_def_name.data)
            current_user.set_setting(code='show_def_desc', value=form.show_def_desc.data)
            current_user.set_setting(code='show_def_tags', value=form.show_def_tags.data)
            current_user.set_setting(code='show_def_logo', value=form.show_def_logo.data)
            current_user.set_setting(code='use_icy', value=form.use_icy.data)
            rfk.database.session.commit()
            flash(gettext('Settings successfully updated.'), 'success')
            return redirect(url_for('settings'))
        else:
            form.old_password.errors.append(gettext('Wrong password.'))

    return render_template('settings.html', form=form, TITLE='Settings',
                           imgur={'client': rfk.CONFIG.get('site', 'imgur-client')})
예제 #2
0
파일: __init__.py 프로젝트: keios/PyRfK
def settings():
    form = SettingsForm(
        request.form,
        username=current_user.username,
        email=current_user.mail,
        show_def_name=current_user.get_setting(code='show_def_name'),
        show_def_desc=current_user.get_setting(code='show_def_desc'),
        show_def_tags=current_user.get_setting(code='show_def_tags'),
        show_def_logo=current_user.get_setting(code='show_def_logo'),
        use_icy=current_user.get_setting(code='use_icy'))

    if request.method == "POST" and form.validate():
        if current_user.check_password(password=form.old_password.data):
            if form.new_password.data:
                current_user.password = User.make_password(
                    form.new_password.data)
            current_user.mail = form.email.data
            current_user.set_setting(code='show_def_name',
                                     value=form.show_def_name.data)
            current_user.set_setting(code='show_def_desc',
                                     value=form.show_def_desc.data)
            current_user.set_setting(code='show_def_tags',
                                     value=form.show_def_tags.data)
            current_user.set_setting(code='show_def_logo',
                                     value=form.show_def_logo.data)
            current_user.set_setting(code='use_icy', value=form.use_icy.data)
            rfk.database.session.commit()
            flash('Settings successfully updated.', 'success')
            return redirect(url_for('settings'))
        else:
            form.old_password.errors.append('Wrong password.')

    ball = rfk.helper.iso_country_to_countryball(current_user.country)
    return render_template(
        'settings.html',
        form=form,
        TITLE='Settings',
        ball=ball,
        imgur={'client': rfk.CONFIG.get('site', 'imgur-client')})