Example #1
0
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)
Example #2
0
File: user.py Project: bzero/JARR
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)
Example #3
0
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)
Example #4
0
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)