def profile(): """ Edit the profile of the currently logged user. """ user_contr = UserController(g.user.id) user = user_contr.get(id=g.user.id) form = ProfileForm() if request.method == 'POST': if form.validate(): user_contr.update({'id': g.user.id}, { 'nickname': form.nickname.data, 'email': form.email.data, 'password': form.password.data, 'refresh_rate': form.refresh_rate.data }) flash( gettext('User %(nick)s successfully updated', nick=user.nickname), 'success') return redirect(url_for('user.profile')) else: return render_template('profile.html', user=user, form=form) if request.method == 'GET': form = ProfileForm(obj=user) return render_template('profile.html', user=user, form=form)
def profile(): user = User.query.filter(User.id == current_user.id).first() form = ProfileForm() form.set_languages_choice() if request.method == 'POST': if form.validate(): # update user form.populate_obj(user) if form.password.data and \ form.password.data == form.password_conf.data: user.set_password(form.password.data) db.session.commit() flash('User successfully updated', 'success') return redirect(url_for('user_bp.profile')) else: return render_template('profile.html', user=user, form=form) if request.method == 'GET': form = ProfileForm(obj=user) form.set_languages_choice() return render_template('profile.html', user=user, form=form)
def profile_update(user_id): ucontr = None if admin_permission.can(): ucontr = UserController() elif Permission(UserNeed(user_id)).can(): ucontr = UserController(user_id) else: flash(gettext('You do not have rights on this user'), 'danger') raise Forbidden(gettext('You do not have rights on this user')) user = ucontr.get(id=user_id) profile_form, pass_form = ProfileForm(obj=user), PasswordModForm() if profile_form.validate(): values = {'login': profile_form.login.data, 'email': profile_form.email.data} if admin_permission.can(): values['is_active'] = profile_form.is_active.data values['is_admin'] = profile_form.is_admin.data values['is_api'] = profile_form.is_api.data ucontr.update({'id': user_id}, values) flash(gettext('User %(login)s successfully updated', login=user.login), 'success') return redirect(url_for('user.profile', user_id=user.id)) return render_template('profile.html', user=user, admin_permission=admin_permission, form=profile_form, pass_form=pass_form)
def profile_update(user_id): ucontr = None if admin_permission.can(): ucontr = UserController() elif Permission(UserNeed(user_id)).can(): ucontr = UserController(user_id) else: flash(gettext('You do not have rights on this user'), 'danger') raise Forbidden(gettext('You do not have rights on this user')) user = ucontr.get(id=user_id) profile_form, pass_form = ProfileForm(obj=user), PasswordModForm() if profile_form.validate(): values = { 'login': profile_form.login.data, 'email': profile_form.email.data } if admin_permission.can(): values['is_active'] = profile_form.is_active.data values['is_admin'] = profile_form.is_admin.data values['is_api'] = profile_form.is_api.data ucontr.update({'id': user_id}, values) flash(gettext('User %(login)s successfully updated', login=user.login), 'success') return redirect(url_for('user.profile', user_id=user.id)) return render_template('profile.html', user=user, admin_permission=admin_permission, form=profile_form, pass_form=pass_form)
def profile(): """ Edit the profile of the currently logged user. """ user_contr = UserController(current_user.id) user = user_contr.get(id=current_user.id) form = ProfileForm() if request.method == 'POST': if form.validate(): try: user_contr.update({'id': current_user.id}, {'nickname': form.nickname.data, 'email': form.email.data, 'password': form.password.data, 'automatic_crawling': form.automatic_crawling.data, 'is_public_profile': form.is_public_profile.data, 'bio': form.bio.data, 'webpage': form.webpage.data, 'twitter': form.twitter.data}) except Exception as error: flash(gettext('Problem while updating your profile: ' '%(error)s', error=error), 'danger') else: flash(gettext('User %(nick)s successfully updated', nick=user.nickname), 'success') return redirect(url_for('user.profile')) else: return render_template('profile.html', user=user, form=form) if request.method == 'GET': form = ProfileForm(obj=user) return render_template('profile.html', user=user, form=form)
def profile(): user = User.query.filter(User.id == current_user.id).first() form = ProfileForm() # form.set_languages_choice() if request.method == 'POST': if form.validate(): # update user if form.password.data and \ form.password.data == form.password_conf.data: user.set_password(form.password.data) form.populate_obj(user) db.session.commit() flash('User successfully updated', 'success') return redirect(url_for('user_bp.profile')) else: flash('User update failed', 'danger') return render_template( 'profile.html', user=user, form=form, humanitarian_id_auth_uri=conf.HUMANITARIAN_ID_AUTH_URI, humanitarian_id_app_uri=conf.HUMANITARIAN_ID_APP_URI) if request.method == 'GET': form = ProfileForm(obj=user) return render_template( 'profile.html', user=user, form=form, humanitarian_id_auth_uri=conf.HUMANITARIAN_ID_AUTH_URI, humanitarian_id_app_uri=conf.HUMANITARIAN_ID_APP_URI)
def profile(): """ Edit the profile of the currently logged user. """ user_contr = UserController(g.user.id) user = user_contr.get(id=g.user.id) form = ProfileForm() if request.method == "POST": if form.validate(): user_contr.update( {"id": g.user.id}, { "nickname": form.nickname.data, "email": form.email.data, "password": form.password.data, "refresh_rate": form.refresh_rate.data, }, ) flash(gettext("User %(nick)s successfully updated", nick=user.nickname), "success") return redirect(url_for("user.profile")) else: return render_template("profile.html", user=user, form=form) if request.method == "GET": form = ProfileForm(obj=user) return render_template("profile.html", user=user, form=form)
def profile(): user = User.query.filter(User.id==current_user.id).first() form = ProfileForm() # form.set_languages_choice() if request.method == 'POST': if form.validate(): # update user if form.password.data and \ form.password.data == form.password_conf.data: user.set_password(form.password.data) form.populate_obj(user) db.session.commit() flash('User successfully updated', 'success') return redirect(url_for('user_bp.profile')) else: flash('User update failed', 'danger') return render_template( 'profile.html', user=user, form=form, humanitarian_id_auth_uri=conf.HUMANITARIAN_ID_AUTH_URI, humanitarian_id_app_uri=conf.HUMANITARIAN_ID_APP_URI) if request.method == 'GET': form = ProfileForm(obj=user) return render_template( 'profile.html', user=user, form=form, humanitarian_id_auth_uri=conf.HUMANITARIAN_ID_AUTH_URI, humanitarian_id_app_uri=conf.HUMANITARIAN_ID_APP_URI)
def process_form(): form = ProfileForm() if not form.validate(): return render_template('edit_user.html', form=form) user = User.query.filter(User.id == current_user.id).first() form.populate_obj(user) if form.password.data: user.pwdhash = generate_password_hash(form.password.data) db.session.commit() flash('User {} successfully updated.'. format(form.login.data), 'success') return redirect(url_for('admin_bp.form_user', user_id=user.id))
def profile(): """ Edit the profile of the currently logged user. """ user_contr = UserController(current_user.id) user = user_contr.get(id=current_user.id) form = ProfileForm() if request.method == "POST": if form.validate(): try: user_contr.update( {"id": current_user.id}, { "nickname": form.nickname.data, "password": form.password.data, "automatic_crawling": form.automatic_crawling.data, "is_public_profile": form.is_public_profile.data, "bio": form.bio.data, "webpage": form.webpage.data, "twitter": form.twitter.data, }, ) except Exception as error: flash( gettext( "Problem while updating your profile: " "%(error)s", error=error ), "danger", ) else: flash( gettext("User %(nick)s successfully updated", nick=user.nickname), "success", ) return redirect(url_for("user.profile")) else: return render_template("profile.html", user=user, form=form) if request.method == "GET": form = ProfileForm(obj=user) return render_template("profile.html", user=user, form=form)