def set_password(): """ Set a new password """ orig_password = request.form.get('original-password') new_password = request.form.get('new-password') if not orig_password or not new_password: return render_template( 'settings.html', error={'password': '******'}) if not User.valid_password(new_password): return render_template('settings.html', error={'password': '******'}) if not current_user.verify_password(orig_password): return render_template('settings.html', error={'password': '******'}) current_user.password = User.hash_password(new_password) user_needs_refresh.send(current_app._get_current_object()) flash('Updated password') return render_template('settings.html')
def set_avatar(): """ Set a user avatar """ file = request.files['file'] if not file or not Image.allowed_file(file.filename): return render_template('settings.html', error={'avatar': 'Invalid image'}) current_user.set_avatar(file) user_needs_refresh.send(current_app._get_current_object()) return render_template('settings.html')
def set_username(): """ Set a user's username """ new_username = request.form['username'] if not new_username: return render_template('settings.html', error={'username': '******'}) if User.username_taken(new_username): return render_template('settings.html', error={'password': '******'}) current_user.username = new_username db.session.commit() user_needs_refresh.send(current_app._get_current_object()) flash('Updated username to {}'.format(new_username)) return render_template('settings.html')