Exemple #1
0
def profile():
    u = g.user
    mc = g.user.mark_count()
    bc = g.user.bookmark_count()
    fc = g.user.feed_count()
    lcm = g.user.mark_last_created()
    form = UserProfileForm(obj=u)
    if form.validate_on_submit():
        form.populate_obj(u)
        if form.password.data:
            pm = bMan()
            u.password = pm.encode(form.password.data)
        else:
            del u.password
        db.session.add(u)
        db.session.commit()
        flash('User %s updated' % (form.username.data), category='info')
        return redirect(url_for('profile'))
    return render_template(
        'account/profile.html',
        form=form,
        title='Profile',
        mc=mc,
        bc=bc,
        fc=fc,
        lcm=lcm,
    )
Exemple #2
0
def edit():
    pcfg = {"title": gettext("Edit my profile")}

    user = User.query.filter(User.id == current_user.id).first()
    if not user:
        flash(gettext("User not found"), "error")
        return redirect(url_for("bp_main.home"))

    form = UserProfileForm(request.form, obj=user)
    form.timezone.choices = [[str(i), str(i)] for i in pytz.all_timezones]

    if form.validate_on_submit():
        user.timezone = form.timezone.data
        user.locale = form.locale.data
        user.display_name = form.display_name.data

        db.session.commit()

        # log
        add_user_log(user.id, user.id, "user", "info", "Edited user profile")

        flash(gettext("Profile updated"), "success")

        return redirect(url_for("bp_users.profile", name=user.name))

    return render_template("users/edit.jinja2",
                           pcfg=pcfg,
                           form=form,
                           user=user)
Exemple #3
0
def profile():
    u = g.user
    mc = g.user.mark_count()
    bc = g.user.bookmark_count()
    fc = g.user.feed_count()
    lcm = g.user.mark_last_created()
    form = UserProfileForm(obj=u)
    if form.validate_on_submit():
        form.populate_obj(u)
        if form.password.data:
            pm = bMan()
            u.password = pm.encode(form.password.data)
        else:
            del u.password
        db.session.add(u)
        db.session.commit()
        flash('User %s updated' % (form.username.data), category='info')
        return redirect(url_for('profile'))
    return render_template('account/profile.html',
                           form=form,
                           title='Profile',
                           mc=mc,
                           bc=bc,
                           fc=fc,
                           lcm=lcm,
                           )
Exemple #4
0
def editProfile(id):
    user = User.query.get(id)
    form = UserProfileForm()
    if form.validate_on_submit():
        f = form.photo.data
        filename = secure_filename(f.filename)
        user.name = form.name.data
        user.surname = form.surname.data
        user.gender = form.gender.data
        user.weight = form.weight.data
        user.height = form.height.data
        user.location = form.location.data
        user.email = form.email.data
        user.bio = form.about_me.data
        user.pic = filename
        f.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        db.session.add(user)
        db.session.commit()
        flash('Updates were saved', 'message')
        return redirect(url_for('home'))
    form.name.data = user.name
    form.surname.data = user.surname
    form.gender.data = user.gender
    form.weight.data = user.weight
    form.height.data = user.height
    form.location.data = user.location
    form.email.data = user.email
    form.about_me.data = user.bio
    form.photo.data = user.pic
    return render_template('editProfile.html', user=user, form=form)
Exemple #5
0
def profile():
    u = g.user
    bc = g.user.bookmark_count()
    lc = g.user.bookmark_last_created()
    form = UserProfileForm(obj=u)
    if form.validate_on_submit():
        form.populate_obj(u)
        if form.password.data:
            pm = bMan()
            u.password = pm.encode(form.password.data)
        else:
            del u.password
        db.session.add(u)
        db.session.commit()
        flash("User %s updated" % (form.username.data), category="info")
        return redirect(url_for("login"))
    return render_template("profile.html", form=form, title="Profile", bc=bc, lc=lc)
Exemple #6
0
def edit():
    pcfg = {"title": "Edit my profile"}

    user = User.query.filter(User.id == current_user.id).first()
    if not user:
        flash("User not found", "error")
        return redirect(url_for("bp_main.home"))

    form = UserProfileForm(request.form, obj=user)
    form.timezone.choices = [[str(i), str(i)] for i in pytz.all_timezones]

    if form.validate_on_submit():
        user.callsign = form.callsign.data.upper()
        user.lastname = form.lastname.data
        user.firstname = form.firstname.data
        user.timezone = form.timezone.data
        user.locator = form.locator.data.upper()

        user.lotw_name = form.lotw_name.data
        user.lotw_password = form.lotw_password.data

        user.eqsl_name = form.eqsl_name.data
        user.eqsl_password = form.eqsl_password.data

        user.hamqth_name = form.hamqth_name.data
        user.hamqth_password = form.hamqth_password.data

        user.swl = form.swl.data
        user.zone = form.zone.data

        db.session.commit()
        return redirect(url_for("bp_users.profile"))

    logbooks = (db.session.query(Logbook.id, Logbook.name, func.count(
        Log.id)).join(Log).filter(Logbook.user_id == current_user.id).group_by(
            Logbook.id).all())
    return render_template("users/edit.jinja2",
                           pcfg=pcfg,
                           form=form,
                           user=user,
                           logbooks=logbooks)
Exemple #7
0
def profile(user_id):
    """Update profile for current user."""

    # IMPLEMENT THIS
    if not g.user:
        flash("Access unauthorized.", "danger")
        return redirect("/")

    user = User.query.get_or_404(user_id)
    form = UserProfileForm(obj=user)

    if form.validate_on_submit():
        user = User.authenticate(user.username, form.password.data)
        if user:
            user = User.updateprofile(user, form)
            if user:
                flash("Profile Udpated.", "success")
                return redirect(f"/users/{g.user.id}")
        flash("Incorrect Password, profile not udpated!", "danger")
        return redirect("/")
    return render_template("/users/profile.html", form=form, user=user)
Exemple #8
0
def profile():
    """Update profile for current user."""

    # IMPLEMENT THIS password is used to check if the user is supposed to be there.  if they know the password, they can edit the user profile page.
    form = UserProfileForm(obj=g.user)
    if form.validate_on_submit():
        user = User.authenticate(g.user.username, form.password.data)
        if user:
            user.username = form.username.data,
            user.email = form.email.data,
            user.image_url = form.image_url.data or User.image_url.default.arg,
            user.header_image_url = form.header_image_url.data,
            user.bio = form.bio.data,
            user.location = form.location.data
            db.session.commit()
        else:
            flash("Wrong password!  Changes not allowed!")
            return render_template('users/edit.html', form=form)

    else:
        return render_template('users/edit.html', form=form)

    return redirect("/users/detail")
Exemple #9
0
def profile():
    """Update profile for current user."""
    form = UserProfileForm(obj=g.user)
    if request.method == 'GET':
        return render_template('users/edit.html',
                               form=form)
    else:
        if form.validate_on_submit():
            if User.authenticate(g.user.username, form.password.data):
                user = User.query.get_or_404(g.user.id)
                pwd = user.password
                form.populate_obj(user)
                user.password = pwd
                db.session.add(user)
                db.session.commit()
                return redirect(url_for('users_show', user_id=user.id))
            flash(u'Invalid Password', category='danger')
            return render_template('users/edit.html',
                                   form=form)
        else:
            flash(u'Validation Problem', category='danger')
            return render_template('users/edit.html',
                                   form=form)
Exemple #10
0
def profile():
    # user profile form
    form = UserProfileForm()

    # if valid input
    if form.validate_on_submit():

        # check for new profile image date, remove old
        if form.image.data:
            old = session["profilePicPath"]
            savedImage = saveImage(form.image.data, 'static/profile_pics')
            if old != 'default.png':
                os.remove(
                    os.path.join(app.root_path, 'static/profile_pics', old))
        else:
            # contruct query for fetching user profile
            query = 'SELECT * FROM Person WHERE username = "******";'.format(
                session["username"])
            data = queryFetch(query)
            savedImage = data["profilePicPath"]

        # extract data from user profile form
        firstName = form.firstName.data
        lastName = form.lastName.data
        biography = form.biography.data

        # try to update user
        try:
            # query database and update user info
            query = 'UPDATE Person SET firstName = "{}", lastName = "{}", bio = "{}", profilePicPath = "{}" WHERE Person.username = "******";'.format(
                firstName, lastName, biography, savedImage,
                session["username"])
            queryFetch(query)
        except Exception as err:
            print(err)
            flash("Information not updated!, databse error occured.", 'danger')
            return redirect(url_for('profile'))

        # update session info with new data
        session["firstName"] = firstName
        session["lastName"] = lastName
        session["biography"] = biography
        session["profilePicPath"] = savedImage

        flash(
            "Profile updated successfully for user {}".format(
                session["username"]), 'success')
        return redirect(url_for('profile'))

    elif request.method == "GET":
        # populate form with user session data
        form.firstName.data = session["firstName"]
        form.lastName.data = session["lastName"]
        form.biography.data = session["biography"]

    # get all user posts and return
    query = 'SELECT * FROM Photo WHERE photoPoster = "{}";'.format(
        session["username"])
    data = queryFetchAll(query)

    # create form for user requests management
    formFollow = UserFollowForm()

    return render_template('profile.html',
                           title='Profile',
                           form=form,
                           userPosts=data,
                           requests=getRequests(session["username"]),
                           formFollow=formFollow)