コード例 #1
0
ファイル: misc_views.py プロジェクト: LexPanov/2ch
def user_profile_page():
    form = UserProfileForm(request.form)
    if form.validate_on_submit():
        form.populate_obj(current_user)
        db.session.commit()
        return redirect(url_for('main.home_page'))
    return render_template('pages/user_profile_page.html', form=form)
コード例 #2
0
def user_profile_page():
    # Initialize form
    form = UserProfileForm(obj=current_user)
    blogposts = BlogPost.query.order_by(BlogPost.created.desc()).filter(
        BlogPost.user_id == current_user.id).all()
    comments = Comment.query.order_by(Comment.created.desc()).all()
    u_comments = Comment.query.order_by(Comment.created.desc()).filter(
        Comment.user_id == current_user.id).all()
    # Process valid POST
    if request.method == 'POST' and form.validate():
        # Copy form fields to user_profile fields
        form.populate_obj(current_user)

        # Save user_profile
        db.session.commit()

        # Redirect to home page
        return redirect(url_for('main.home_page'))

    # Process GET or invalid POST
    return render_template('pages/user_profile_page.html',
                           form=form,
                           blogposts=blogposts,
                           comments=comments,
                           u_comments=u_comments)
コード例 #3
0
def user_profile_page():
    # Initialize form
    form = UserProfileForm(request.form, obj=current_user)

    # Process valid POST
    if request.method == 'POST' and form.validate():
        # Copy form fields to user_profile fields
        form.populate_obj(current_user)

        # Save user_profile
        db.session.commit()

        # Redirect to home page
        return redirect(url_for('main.home_page'))

    # Process GET or invalid POST
    return render_template('main/user_profile_page.html', form=form)
コード例 #4
0
ファイル: users_view.py プロジェクト: awainer/MUSSA
def user_profile_page():
    form = UserProfileForm()

    # Process valid POST
    if request.method == 'POST' and form.validate():
        # Copy form fields to user_profile fields
        form.populate_obj(current_user)

        # Save user_profile
        db.session.commit()

        # Redirect to home page
        return redirect(url_for('main.home_page'))

    # Process GET or invalid POST
    form.first_name.data = current_user.first_name
    form.last_name.data = current_user.last_name

    return render_template('pages/user_profile_page.html', form=form)
コード例 #5
0
ファイル: controller1.py プロジェクト: twintechlabs/flaskdash
def manage_user_roles():
    user_id = request.args.get('user_id')
    role_id = request.args.get('role_id')

    if user_id and role_id:
        user_id = int(user_id)
        role_id = int(role_id)
        db.session.query(UsersRoles).filter_by(user_id=user_id).filter_by(
            role_id=role_id).delete()
        db.session.commit()
    # Initialize form
    user_roles = list()
    if user_id is not None:
        user_id = int(user_id)
        user = User.query.filter_by(id=user_id).first()
        user_roles = user.roles

    form = UserProfileForm(request.form, obj=user)

    roles = db.session.query(Role).all()
    if request.method == 'POST':

        form.populate_obj(user)
        if str(request.form['role']):
            role = Role.query.filter(
                Role.name == str(request.form['role'])).first()
            user.roles.append(role)
            db.session.commit()
            flash(
                'You successfully added a role to user ' + user.name() + ' !',
                'success')
        else:
            #user.roles = []
            # print(f' Not appending role ')
            flash('You failed to add a role to user ' + user.name() + ' !',
                  'failure')
            pass

    return render_template('views/admin/manage_user_roles.html',
                           user=user,
                           roles=roles,
                           user_roles=user_roles,
                           form=form)
コード例 #6
0
def create_user_page():
    user_id = request.args.get('user_id')
    # Initialize form
    user = User()
    if user_id is not None:
        user = User.query.filter_by(id=user_id).first()
    form = UserProfileForm(request.form, obj=user)

    if request.method == 'POST':
        form.populate_obj(user)
        role = Role.query.filter(Role.name == "admin").first()
        if user.id is None:
            user = User(email=request.form['email'],
                        first_name=request.form['first_name'],
                        last_name=request.form['last_name'],
                        password=current_app.user_manager.hash_password(
                            request.form['password']),
                        active=True,
                        email_confirmed_at=datetime.datetime.utcnow())
            if str(request.form['role']) == "admin":
                user.roles.append(role)
            else:
                user.roles = []
            db.session.add(user)
            db.session.commit()
        else:
            user.email = request.form['email']
            user.first_name = request.form['first_name']
            user.last_name = request.form['last_name']
            if request.form['password'] is not None and request.form[
                    'password'] is not "":
                user.password = current_app.user_manager.hash_password(
                    request.form['password'])
            if str(request.form['role']) == "admin":
                user.roles.append(role)
            else:
                user.roles = []
            db.session.commit()
        flash('You successfully updated your user!', 'success')
        return redirect(url_for('main.user_admin_page'))
    return render_template('pages/admin/create_user.html',
                           user=user,
                           form=form)
コード例 #7
0
def user_profile_page():
    if current_app.config.get('USER_LDAP', False):
        abort(400)

    # Initialize form
    form = UserProfileForm(request.form, obj=current_user)

    # Process valid POST
    if request.method == 'POST' and form.validate():
        # Copy form fields to user_profile fields
        form.populate_obj(current_user)

        # Save user_profile
        db.session.commit()

        # Redirect to home page
        return redirect(url_for('main.user_profile_page'))

    # Process GET or invalid POST
    return render_template('pages/user_profile_page.html',
                           current_user=current_user,
                           form=form)