Exemple #1
0
def account():
    form = UpdAccountForm()

    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file

        current_user.username = form.username.data
        current_user.email = form.email.data

        db.session.commit()
        flash('Your account has been updated !', 'success')

        return redirect(url_for('users.account'))

    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email

    image_file = url_for('static',
                         filename='profile_pics/' + current_user.image_file)

    return render_template('account.html',
                           title='Account',
                           form=form,
                           image_file=image_file)
Exemple #2
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            old_pic = current_user.image_file
            pic_file = save_picture(form.picture.data)
            current_user.image_file = pic_file
            if old_pic != 'default.jpg':
                os.remove(
                    os.path.join(app.root_path, 'static/profile_pics',
                                 old_pic))
        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash('Your account has been updated', 'success')
        return redirect(url_for('users.account'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
    image_file = url_for('static',
                         filename='profile_pics/' + current_user.image_file)
    return render_template('account.html',
                           title='Account',
                           image_file=image_file,
                           form=form)
Exemple #3
0
def dashboard():
    if current_user.has_role('primeserver'):
        form = UpdateAccountPrimeServerForm()
    else:
        form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file
        current_user.username = form.username.data
        current_user.email = form.email.data.lower()
        current_user.bio = form.bio.data
        current_user.favsong = form.favsong.data
        if current_user.has_role('primeserver'):
            current_user.ign = form.ign.data
            current_user.noteskin = form.noteskin.data
            current_user.scrollspeed = round(0.5 * round(float(form.scrollspeed.data) / 0.5), 1)
            current_user.modifiers = current_user.modifiers | mods_to_int([], form.judgement.data)
            current_user.psupdate = "True" if not form.psupdate.data else "False"
        db.session.commit()
        flash('Account details updated!', 'success')
        return redirect(url_for('users.dashboard'))
    elif request.method == "GET":
        form.username.data = current_user.username
        form.email.data = current_user.email
        form.bio.data = current_user.bio
        form.favsong.data = current_user.favsong
        if current_user.has_role('primeserver'):
            form.ign.data = current_user.ign
            form.noteskin.data = current_user.noteskin
            form.scrollspeed.data = current_user.scrollspeed
            form.judgement.data = int_to_judge(current_user.modifiers)
            form.psupdate.data = current_user.psupdate == "False"
    image_file = url_for('static', filename='profile_pics/' + current_user.image_file)
    return render_template("dashboard.html", title="Dashboard", image_file=image_file, form=form, current_user=current_user)
def users_profile():
    form = UpdateAccountForm()

    if 'submit' in request.form:
        if form.validate_on_submit():
            if form.picture.data:
                current_user.picture = save_picture(form.picture.data)

            current_user.username = form.username.data
            current_user.email = form.email.data

            db.session.commit()
            flash('Your account has been updated!', 'success')
            return redirect(url_for('users_blueprint.users_profile'))

    if 'cancel' in request.form:
        return redirect(url_for('users_blueprint.users_profile'))

    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email

    return render_template('users_profile.html',
                           title='Your Profile',
                           form=form)
Exemple #5
0
def home(username, post_page, hired_page, history_page):
    form = EditIMG()
    user = User.query.filter_by(username=username).first()
    job_posted = Job.query.filter(Job.userId == user.id).order_by(
        Job.timeStamp.desc()).paginate(per_page=2, page=int(post_page))
    current_age = user.get_age()
    image_file = url_for('static', filename='profile_pics/' + user.image_file)
    if form.validate_on_submit and request.method == 'POST':
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            user.image_file = picture_file
            db.session.commit()
            flash('Changed Profile Picture.', category='success')
        else:
            flash('Failed', category='danger')
        return redirect(
            url_for('users.home',
                    username=current_user.username,
                    post_page=1,
                    hired_page=1,
                    history_page=1))
    else:
        return render_template('home.html',
                               title='Profile',
                               form=form,
                               image_file=image_file,
                               age=current_age,
                               job_posted=job_posted,
                               user=user,
                               current_post_page=post_page,
                               current_hired_page=hired_page,
                               current_history_page=history_page)
Exemple #6
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file
        current_user.username = form.username.data
        current_user.email = form.email.data
        current_user.address = form.address.data
        current_user.country = form.country.data
        current_user.phone_number = form.phone_number.data
        current_user.about_me = form.about_me.data
        db.session.commit()
        flash('Your account has been updated.', 'success')
        return redirect(url_for('users.account'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
        form.address.data = current_user.address
        form.country.data = current_user.country
        form.phone_number.data = current_user.phone_number
        form.about_me.data = current_user.about_me
    image_file = url_for('static',
                         filename='profile_pics/' + current_user.image_file)
    return render_template('account3.html', form=form, image_file=image_file)
Exemple #7
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():

        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file

        current_user.username = form.username.data  # This is a SQLAlchemy perk it allows us to take the current_user data which we get thanks to flask_login, and then overwrites it with the form data the user submits!
        current_user.email = form.email.data  # So over here we're overwriting the current_user email with the email the user submits in the form!
        db.session.commit()  # Commit changes in database.db
        flash(
            'Your account has been updated!', 'success'
        )  # Display success message! For anyone wondering 'success' is just a bootstrap class, it gives a green-ish hue.
        return redirect(
            url_for('users.account')
        )  # Redirect to account, without this line of code, the broswer on the redirect below would send multiple post requests causing some problems
    elif request.method == 'GET':
        form.username.data = current_user.username  # This populates the username field upon a 'GET' request
        form.email.data = current_user.email  # This populates the email field upon a 'GET' request
    image_file = url_for('static',
                         filename='profile_images/' + current_user.image_file)
    return render_template('account.html',
                           title='Account',
                           image_file=image_file,
                           form=form)
Exemple #8
0
def account():
    form = UpdateAccount()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file
        if form.coverphoto.data:
            picture_file = save_picture(form.coverphoto.data)
            current_user.cover_photo = picture_file
        if form.video.data:
            video_file = save_video(form.video.data)
            current_user.video_file = video_file

        current_user.username = form.username.data
        current_user.email = form.email.data
        current_user.location = form.location.data
        current_user.facebook = form.facebook.data
        current_user.linkedin = form.linkedin.data
        current_user.official = form.official_number.data
        current_user.mobile = form.mobile_number.data
        current_user.position = form.position.data
        db.session.commit()
        flash('your account has been updated!', 'success')
        return redirect(url_for('users.account'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
    image_file = url_for('static',
                         filename='images/' + current_user.image_file)
    cover_photo = url_for('static',
                          filename='images/' + current_user.cover_photo)
    video_file = url_for('static',
                         filename='videos/' + current_user.video_file)
    return render_template('account.html',
                           title='Account',
                           image_file=image_file,
                           video_file=video_file,
                           form=form,
                           cover_photo=cover_photo)
Exemple #9
0
def account():
    form=UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:               #check if any picture has been uploaded while updating details.
            picture_file=save_picture(form.picture.data)
            current_user.image_file = picture_file
        current_user.username=form.username.data
        current_user.email=form.email.data
        db.session.commit()
        flash('Your account has been updated!','Success')
        return redirect(url_for('users.account'))
    elif request.method == 'GET':                       #To display the email and username of user in the accounts page Textboxes
        form.username.data =current_user.username
        form.email.data =current_user.email
    image_file=url_for('static', filename='profile_pics/'+ current_user.image_file)
    return render_template('account.html',title='Account', image_file=image_file, form=form)
Exemple #10
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            pic_file = save_picture(form.picture.data)
            current_user.img = pic_file

        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash(f"Account info updated", "success")
        return redirect(url_for("users.account"))
    elif request.method == "GET":
        form.username.data = current_user.username
        form.email.data = current_user.email
    img = url_for("static", filename="profile_pics/" + current_user.img)
    return render_template("account.html", title="Account", img=img, form=form)
Exemple #11
0
def edit_profile():
    form = EditProfileForm(current_user.username)
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file
        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('users.edit_profile'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.about_me.data = current_user.about_me
    return render_template('edit_profile.html',
                           title='Edit Profile',
                           form=form)
Exemple #12
0
def account():
    form = UpdateUserForm()
    avatar = url_for('static',
                     filename=f'profile_pics/{current_user.image_file}')
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file
        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash(f'Account credentials were successfully updated', "success")
        return redirect(url_for('users.account'))
    elif request.method == "GET":
        form.username.data = current_user.username
        form.email.data = current_user.email
    return render_template('account.html', avatar=avatar, form=form)
Exemple #13
0
def update_user(user_id):
    user = User.query.get_or_404(user_id)
    form = UpdateUserForm()
    form.id.data = user.id  # we need to push user id into the form to validate user uniqueness
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            user.image_file = picture_file
        user.username = form.username.data
        user.email = form.email.data
        db.session.commit()
        flash(f'The account of user {user.username} has been updated!', 'success')
        return redirect(url_for('users.update_user', user_id=user.id))
    elif request.method == 'GET':
        form.username.data = user.username
        form.email.data = user.email
    image_file = url_for('static', filename='profile_pics/' + user.image_file)
    return render_template('update_user.html', title='User', image_file=image_file, form=form, user=user)
Exemple #14
0
def myblog():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.profile_image_file = picture_file
        if form.cover.data:
            cover_file = save_cover(form.cover.data)
            current_user.blog[0].cover_image_file = cover_file

        current_user.user_name = form.user_name.data
        current_user.email = form.email.data

        current_user.blog[0].blog_name = form.blog_name.data
        current_user.blog[0].phrase = form.phrase.data
        current_user.blog[0].about = form.about.data

        db.session.commit()
        flash('Blog updated.', 'success')
        return redirect(url_for('users.myblog'))
    elif request.method == 'GET':
        form.user_name.data = current_user.user_name
        form.email.data = current_user.email

        form.blog_name.data = current_user.blog[0].blog_name
        form.phrase.data = current_user.blog[0].phrase
        form.about.data = current_user.blog[0].about
    else:
        flash('update failed, check the fields', 'danger')
    image_file = url_for('static',
                         filename='profile_pics/' +
                         current_user.profile_image_file)
    image_cover = url_for('static',
                          filename='cover_pics/' +
                          current_user.blog[0].cover_image_file)

    page = request.args.get('page', 1, type=int)
    posts = Post.query.filter_by(author=current_user).order_by(
        Post.created_date.desc()).paginate(page=page, per_page=5)
    return render_template('profile.html',
                           image_file=image_file,
                           image_cover=image_cover,
                           form=form,
                           posts=posts)
Exemple #15
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file

        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash(f'Account Details Updated!!', category='success')
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
    image_file = url_for('static',
                         filename='profile_pics/' + current_user.image_file)
    return render_template('account.html',
                           title='Account',
                           image_file=image_file,
                           form=form)
Exemple #16
0
def account():
    form = UpdateAccountForm()  #Uses import made above
    if form.validate_on_submit(
    ):  #for validation of input data to existing data
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file
        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash('Your account details has been updated', 'success')
        return redirect(url_for('users.account'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
    image_file = url_for('static',
                         filename='profile_pics/' + current_user.image_file)
    return render_template('account.html',
                           title='Account',
                           image_file=image_file,
                           form=form)
Exemple #17
0
def account():
    form = UpdateAccountForm()
    form.upline.choices = [(upline.id, upline.username)
                           for upline in User.query.all()]
    form.referrer.choices = [(referrer.id, referrer.username)
                             for referrer in User.query.all()]
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file
        current_user.username = form.username.data
        current_user.email = form.email.data
        current_user.fullname = form.fullname.data
        current_user.title = form.title.data
        current_user.ic_number = form.ic_number.data
        current_user.phone_number = form.phone_number.data
        current_user.birthday = form.birthday.data
        current_user.location = form.location.data
        current_user.upline_id = form.upline.data
        current_user.referrer_id = form.referrer.data
        db.session.commit()
        flash('Your account has been updated!', 'success')
        return redirect(url_for('users.account'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
        form.fullname.data = current_user.fullname
        form.title.data = current_user.title
        form.ic_number.data = current_user.ic_number
        form.phone_number.data = current_user.phone_number
        form.birthday.data = current_user.birthday
        form.location.data = current_user.location
        form.upline.data = current_user.upline_id
        form.referrer.data = current_user.referrer_id
    image_file = url_for('static',
                         filename='profile_pics/' + current_user.image_file)
    return render_template('account.html',
                           title='Account',
                           image_file=image_file,
                           form=form)
Exemple #18
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file
        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash('Your account has been updated!', 'success')
        return redirect(url_for('users.account'))
        #By redirecting, we don't get the browser message saying
        #(are you sure you want to refresh? It will cause bla bla bla)
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
    image_file = url_for('static',
                         filename='images/' + current_user.image_file)
    return render_template('account.html',
                           title='Account',
                           image_file=image_file,
                           form=form)
Exemple #19
0
def profile_update():
    form = ProfileUpdate()
    if form.validate_on_submit():
        if form.profilePicture.data:
            pictureFile = save_picture(form.profilePicture.data)
            current_user.ProfilePicture = pictureFile
        current_user.FirstName = form.firstName.data.capitalize()
        current_user.LastName = form.lastName.data.capitalize()
        current_user.Email = form.email.data
        db.session.commit()
        flash('Successfully updated!', 'success')
        return redirect(url_for('users.profile'))
    elif request.method == 'GET':
        form.firstName.data = current_user.FirstName
        form.lastName.data = current_user.LastName
        form.email.data = current_user.Email
        form.profilePicture.data = current_user.ProfilePicture

    return render_template('profile-update.html',
                           form=form,
                           title='Profile Update',
                           active='profile')
Exemple #20
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        # If there is a profile pic passed save it
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file
        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash('Your account has been updated!', 'success')
        return redirect(url_for('users.account'))
    elif request.method == 'GET':
        # Load with initial values if GET request
        form.username.data = current_user.username
        form.email.data = current_user.email
         # Get latest post of user
        latestPosts = Post.query.filter_by(author=current_user).order_by(Post.date_posted.desc()).limit(6).all()

    image_file = url_for('static', filename='profile_pics/' + current_user.image_file)
    return render_template('account.html', title='Account',
                           image_file=image_file, form=form, user=current_user,latestPosts=latestPosts)
Exemple #21
0
def account():
    # print('in account')
    form=UpdateAccountForm()
    # print(current_user.image_file,'this is the name')
    if(form.validate_on_submit()):
        # print(form.picture.data)
        if(form.picture.data ):
            current_profile_image=current_user.image_file
            picture_file=save_picture(form.picture.data,current_profile_image)
            current_user.image_file=picture_file

        # print('in account')
        current_user.username=form.username.data
        current_user.email=form.email.data
        print(current_user.username,form.username.data)
        db.session.commit()
        flash(f'Your Account has been updated','success')
        return redirect(url_for('account'))
    elif(request.method == 'GET'):
        form.username.data=current_user.username
        form.email.data=current_user.email
    image_file=url_for('static',filename='image/Profile_Default/'+current_user.image_file)
    return render_template("account.html",title='Account',image_file=image_file,form=form)
Exemple #22
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file
        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash("Your account has been updated!!", "success")
        # Because of POST GET request resending and stuff
        return redirect(url_for("users.account"))

    elif request.method == "GET":
        form.username.data = current_user.username
        form.email.data = current_user.email
    image_file = url_for('static',
                         filename='profile_pics/{}'.format(
                             current_user.image_file))
    return render_template('account.html',
                           title='Account',
                           image_file=image_file,
                           form=form)
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file
        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash('Your account has been updated!', 'success')
        return redirect(
            url_for('users.account')
        )  # this line forces the browser to send another get request preventing the 'do you want to submit your data again?' issue
    elif request.method == 'GET':
        # if it's a GET request the pre-populate the fields with the current variables
        form.username.data = current_user.username
        form.email.data = current_user.email
    image_file = url_for('static',
                         filename='profile_pics/' + current_user.image_file)
    return render_template('account.html',
                           title="Account",
                           image_file=image_file,
                           form=form)
Exemple #24
0
def user_posts(username):
    page = request.args.get('page', 1, type=int)
    user = User.query.filter_by(username=username).first_or_404()
    posts = Post.query.filter_by(author=user).order_by(
        Post.date_posted.desc()).paginate(page=page, per_page=10)
    form = UpdateProfileForm()
    if form.validate_on_submit():
        if form.profile_pic.data:
            picture_file = save_picture(form.profile_pic.data)
            current_user.image_file = picture_file
        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash('Your account has been successfully updated !', 'success')
        return redirect(
            url_for('users.user_posts', username=current_user.username))
    elif request.method == 'GET' and current_user.is_authenticated:
        form.username.data = current_user.username
        form.email.data = current_user.email
    return render_template('user_posts.html',
                           posts=posts,
                           user=user,
                           form=form)
Exemple #25
0
def dashboard():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file
        current_user.username = form.username.data
        current_user.email = form.email.data
        current_user.bio = form.bio.data
        current_user.favsong = form.favsong.data
        db.session.commit()
        flash('Account details updated!', 'success')
        return redirect(url_for('users.dashboard'))
    elif request.method == "GET":
        form.username.data = current_user.username
        form.email.data = current_user.email
        form.bio.data = current_user.bio
        form.favsong.data = current_user.favsong
    image_file = url_for('static',
                         filename='profile_pics/' + current_user.image_file)
    return render_template("dashboard.html",
                           title="Dashboard",
                           image_file=image_file,
                           form=form)