Example #1
0
def user_edit(userid):
    if current_user.id != int(userid):
        flash('You can only edit your own profile')
        return redirect(url_for('user.user', userid=current_user.id))

    form = EditProfileForm()

    if form.validate_on_submit():
        current_user.first_name = form.first_name.data
        current_user.last_name = form.last_name.data
        current_user.blurb = form.blurb.data
        current_user.skill_pm = form.skill_pm.data
        current_user.skill_pr = form.skill_pr.data
        current_user.skill_gd = form.skill_gd.data
        current_user.skill_cm = form.skill_cm.data
        current_user.skill_bs = form.skill_bs.data

        db.session.commit()
        flash('Your changes have been saved')
        return redirect(url_for('user.user', userid=current_user.id))

    elif request.method == 'GET':
        form.first_name.data = current_user.first_name
        form.last_name.data = current_user.last_name
        form.blurb.data = current_user.blurb
        form.skill_pm.data = current_user.skill_pm
        form.skill_pr.data = current_user.skill_pr
        form.skill_gd.data = current_user.skill_gd
        form.skill_cm.data = current_user.skill_cm
        form.skill_bs.data = current_user.skill_bs

    return render_template('user/edit.html', title='Edit Profile', form=form)
Example #2
0
def edit_profile(username):
    """Profile edit page"""
    check_permissions(username)
    form = EditProfileForm(current_user.username, current_user.email)
    form.username.render_kw = {'disabled': 'disabled'}
    form.admin.render_kw = {'disabled': 'disabled'}
    form.reviewer.render_kw = {'disabled': 'disabled'}
    if form.validate_on_submit():
        current_user.name = form.name.data
        current_user.organisation = form.organisation.data
        current_user.email = form.email.data
        db.session.commit()
        flash('Your changes have been saved.')
        return redirect(
            url_for('user.edit_profile', username=current_user.username))
    elif request.method == 'GET':
        form.name.data = current_user.name
        form.organisation.data = current_user.organisation
        form.username.data = current_user.username
        form.email.data = current_user.email
        form.admin.data = current_user.admin
        form.reviewer.data = current_user.reviewer
    return render_template('users/edit_profile.html',
                           title='Edit Profile',
                           form=form)
Example #3
0
 def test_edit_profile(self, user):
     form = EditProfileForm(user.username)
     form.username.data = 'cool'
     form.bio.data = 'cool'
     form.profile_img.data = 'cool'
     print(form)
     assert form.validate() is True
Example #4
0
def user_edit(username):
    """Allows admin to edit user information"""
    check_permissions()
    user = User.query.filter_by(username=username).first_or_404()
    form = EditProfileForm(user.username, user.email)
    if form.validate_on_submit():
        user.name = form.name.data
        user.organisation = form.organisation.data
        user.username = form.username.data
        user.email = form.email.data
        user.admin = form.admin.data
        user.reviewer = form.reviewer.data
        db.session.commit()
        flash('Updated successfully')
        return redirect(url_for('admin.user_management'))
    elif request.method == 'GET':
        form.name.data = user.name
        form.organisation.data = user.organisation
        form.username.data = user.username
        form.email.data = user.email
        form.admin.data = user.admin
        form.reviewer.data = user.reviewer
    return render_template('admin/edit_profile.html',
                           title='Edit Profile',
                           form=form,
                           username=username)
Example #5
0
def edit(username):  # noqa: C901
    user = User.query.filter_by(username=username).first_or_404()

    if not user.is_editable_by_user():
        return deny_access(no_perm_url)

    form = EditProfileForm()

    if current_user.is_admin():
        form.role.choices = gen_role_choices()
    else:
        del form.role

    if form.validate_on_submit():
        user.about = form.about.data

        if (form.password.data):
            user.set_password(form.password.data)

            if current_user.username == user.username:
                user.must_change_password = False
            elif current_user.is_admin():
                # user must reset password after it has been changed by an admin
                user.must_change_password = True

        role_okay = True

        if current_user.is_admin():
            old_role = user.role
            new_role = form.role.data

            if username == current_user.username and current_user.is_admin(
            ) and new_role != Role.Admin.value:
                flash("You can't revoke your own admin role.", "danger")
                role_okay = False
            elif user.id == 1 and new_role != Role.Admin.value:
                flash("The original admin can't be removed.", "danger")
                role_okay = False
            else:
                user.role = new_role

        if role_okay:
            db.session.commit()
            flash("Your changes have been saved.", "success")

            return redirect(user.view_url())
        else:
            form.role.data = old_role
    elif request.method == "GET":
        form.about.data = user.about

        if current_user.is_admin():
            form.role.data = user.role

    return render_template("user/edit.html",
                           form=form,
                           user=user,
                           title=page_title(f"Edit User '{user.username}'"))
Example #6
0
def edit_profile():
    form = EditProfileForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        user.update()
        flash('Your changes have been saved!')
        return redirect(url_for('user.edit_profile', user=user))
    return render_template('user/edit.html', title='Edit', form=form)
Example #7
0
def edit_profile():
    form = EditProfileForm(current_user.username)
    if form.validate_on_submit():
        current_user.set_about(form.username.data, form.about_me.data)
        flash('Your changes have been saved.')
        return redirect(url_for('user.edit_profile'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.about_me.data = current_user.about_me
    return render_template('user/edit_profile.html',
                           title='Edit Profile',
                           form=form)
Example #8
0
def edit_profile():
    form = EditProfileForm()
    if form.validate_on_submit():
        current_user.name = form.name.data
        current_user.username = form.username.data
        current_user.bio = form.bio.data
        db.session.commit()
        flash('资料更新成功。', 'success')
        return redirect(url_for('.index', username=current_user.username))
    form.name.data = current_user.name
    form.username.data = current_user.username
    form.bio.data = current_user.bio
    return render_template('user/settings/edit_profile.html', form=form)
Example #9
0
def edit_profile():
    form = EditProfileForm()
    if form.validate_on_submit():
        current_user.name = form.name.data
        current_user.location = form.location.data
        current_user.about_me = form.about_me.data
        db.session.add(current_user)
        flash('用户配置更新成功',category='success')
        return redirect(url_for('user.get_user',id=current_user.id))
    form.name.data = current_user.name
    form.location.data = current_user.location
    form.about_me.data = current_user.about_me
    return render_template('user/edit_profile.html',form=form)
Example #10
0
def edit_profile():
    form = EditProfileForm(current_user.username)

    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.about_me = form.about_me.data
        db.session.commit()
        flash('Your changes have been saved.')
        return redirect(url_for('user.user', username=current_user.username))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.about_me.data = current_user.about_me
    return render_template('user/edit_profile.html',  form=form)
Example #11
0
def dashboard(page):
    if page == "settings":
        form = EditProfileForm()
        if form.validate_on_submit():
            current_user.displayname = form.displayname.data
            current_user.location = form.location.data
            current_user.bio = form.bio.data
            db.session.commit()
            flash('Your settings have been saved.')
            return redirect(url_for('user.dashboard', page='settings'))
        elif request.method == 'GET':
            form.displayname.data = current_user.displayname
            form.location.data = current_user.location
            form.bio.data = current_user.bio
        return render_template('user/dashboard.html', page=page, form=form)
    return render_template('user/dashboard.html', page=page)
Example #12
0
def edit_profile():
    form = EditProfileForm()
    if form.validate_on_submit():
        current_user.name = form.name.data
        current_user.location = form.location.data
        current_user.about_me = form.about_me.data
        db.session.add(current_user)
        flash('用户配置信息更新成功!', category='success')
        return redirect(url_for('user.users', username=current_user.username))
    # 编辑的时候要显示用户的旧信息;
    # current_user.name 获取旧数据
    # form.name.data指定表单中填写的内容
    form.name.data = current_user.name
    form.location.data = current_user.location
    form.about_me.data = current_user.about_me
    return render_template('user/edit_profile.html', form=form)
Example #13
0
def edit(username):
    if current_user.has_admin_role() or current_user.username == username:

        if current_user.has_admin_role():
            form = EditProfileFormAdmin()
        else:
            form = EditProfileForm()

        user = User.query.filter_by(username=username).first_or_404()

        if form.validate_on_submit():
            user.about = form.about.data

            if(form.password.data):
                user.set_password(form.password.data)

                if current_user.username == user.username:
                    user.must_change_password = False
                elif current_user.has_admin_role():
                    # user must reset password after it has been changed by an admin
                    user.must_change_password = True

            db.session.commit()
            flash("Your changes have been saved.")

            return redirect(url_for("user.profile", username=username))
        elif request.method == "GET":
            form.about.data = user.about

        return render_template("user/edit.html", form=form, user=user, title=page_title("Edit profile"))
    else:
        flash("You dont have the neccessary role to perform this action.")
        return redirect(url_for("index"))
Example #14
0
def edit_profile():
    form = EditProfileForm(current_user.user_name)
    if form.validate_on_submit():
        current_user.user_name = form.username.data
        current_user.first_name = form.first_name.data
        current_user.last_name = form.last_name.data
        current_user.phone = form.phone.data
        db.session.commit()
        flash('Your changes have been saved.')
        return redirect(url_for('user_u.edit_profile'))
    elif request.method == 'GET':
        form.username.data = current_user.user_name
        form.first_name.data = current_user.first_name
        form.last_name.data = current_user.last_name
        form.phone.data = current_user.phone
    return render_template('user/edit_profile.html',
                           title='Edit Profile',
                           form=form)
Example #15
0
def profile():
    form = EditProfileForm()
    if form.validate_on_submit():
        current_user.first_name = form.first_name.data
        current_user.last_name = form.last_name.data
        current_user.locale = form.locale.data
        db.session.commit()
        session['locale'] = form.locale.data
        flash(_('Your changes have been saved.'))
        # return redirect(url_for('public.home'))
        return render_template('profile.html', title=_('Profile'), form=form)
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.first_name.data = current_user.first_name
        form.last_name.data = current_user.last_name
        form.locale.data = current_user.locale
    else:
        flash_errors(form)
    return render_template('profile.html', title=_('Profile'), form=form)
Example #16
0
def edit(username):
    # TODO: make a custom decorator for this?
    if current_user.has_admin_role() or current_user.username == username:
        form = EditProfileForm()

        if current_user.has_admin_role():
            form.roles.choices = gen_role_choices()
        else:
            del form.roles

        user = User.query.filter_by(username=username).first_or_404()

        if form.validate_on_submit():
            user.about = form.about.data

            if (form.password.data):
                user.set_password(form.password.data)

                if current_user.username == user.username:
                    user.must_change_password = False
                elif current_user.has_admin_role():
                    # user must reset password after it has been changed by an admin
                    user.must_change_password = True

            if current_user.has_admin_role():
                new_user_roles = Role.query.filter(Role.id.in_(
                    form.roles.data)).all()

                admin_role = Role.query.get(1)

                if username == current_user.username and current_user.has_admin_role(
                ) and admin_role not in new_user_roles:
                    new_user_roles.append(admin_role)
                    flash("You can't revoke your own admin role.", "danger")

                if user.id == 1 and admin_role not in new_user_roles:
                    new_user_roles.append(admin_role)
                    flash("The original admin can't be removed.", "danger")

                user.roles = new_user_roles

            db.session.commit()
            flash("Your changes have been saved.", "success")

            return redirect(url_for("user.profile", username=username))
        elif request.method == "GET":
            form.about.data = user.about

            if current_user.has_admin_role():
                user_roles = []
                for role in user.roles:
                    user_roles.append(str(role.id))

                form.roles.data = user_roles

        return render_template("user/edit.html",
                               form=form,
                               user=user,
                               title=page_title("Edit User '%s'" %
                                                user.username))
    else:
        flash("You dont have the neccessary role to perform this action.",
              "danger")
        return redirect(url_for(no_perm_url))