Example #1
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('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 = 'profile_pics/' + current_user.image_file)
	return render_template('account.html',title='Account', image_file = image_file, form = form)
Example #2
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()
        return redirect(url_for('account'))
    image_file = url_for('static',
                         filename="profile_pics/" + current_user.image_file)
    return render_template('account.html',
                           title="Student Account",
                           image_file=image_file,
                           form=form)
Example #3
0
def account():
    current_user = auth1.current_user
    if (auth1.current_user):
        form = UpdateAccountForm()
        email = (auth1.get_account_info(
            current_user['idToken']).get('users')[0]).get('email')
        uid = (auth1.get_account_info(
            current_user['idToken']).get('users')[0]).get('localId')
        username = (auth1.get_account_info(
            current_user['idToken']).get('users')[0]).get('displayName')
        username_update = form.username.data
        email_update = form.email.data
        if request.method == 'POST':
            auth.update_user(uid,
                             display_name=username_update,
                             email=email_update)
            flash('Your account deltails has been changed', 'success')
            return redirect(url_for('account'))
        elif request.method == 'GET':
            form.email.data = email
            form.username.data = username
    else:
        return redirect(url_for('hello'))
    return render_template('account.html',
                           title='Account',
                           form=form,
                           current_user=current_user,
                           email=email,
                           username=username)
Example #4
0
def account():
    form = UpdateAccountForm()
    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)
Example #5
0
def cuenta():
    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('Su cuenta ha sido actualizada', 'success')
        return redirect(url_for('cuenta'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
    posts = Post.query.filter_by(author=current_user).order_by(Post.date_posted.desc()).all()
    image_file = url_for('static', filename='/profile_pics/' + current_user.image_file)
    return render_template('cuenta.html', title='Mi Cuenta', image_file=image_file, form=form, posts=posts)
Example #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
        db.session.commit()
        flash('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='profile_pics/' + current_user.image_file)
    return render_template('account.html', title='Account',
                           image_file=image_file, form=form)
Example #7
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        current_user.family_name = form.family_name.data
        current_user.email = form.email.data
        db.session.commit()
        flash('Your account has bin updated', 'succes')
        return redirect(url_for('account'))
    elif request.method == 'GET':
        form.family_name.data = current_user.family_name
        form.email.data = current_user.email

    image_file = url_for('static', filename='img/' + current_user.image_file)
    return render_template('account.html',
                           title='Account',
                           image_file=image_file,
                           form=form)
Example #8
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.email = form.email.data
        if form.avatar.data:
            f_name = save_avatar(form.avatar.data)
            current_user.avatar = f_name
        db.session.commit()

        flash('Account details 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

    avatar = url_for('static', filename=f'profile_images/{current_user.avatar}')
    return render_template('account.html', title='Account', avatar=avatar, form=form)
Example #9
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        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("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)
Example #10
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('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)

    @app.route("/post/new",methods=['GET','POST'])
    @login_required
    def new_post():
        form=PostForm()
        if form.validate_on_submit():
            post=Post(title=form.title.data,content=form.content.data,author-current_user)
            db.session.add(post)
            db.session.commit()
            flash("Your post has been created!", 'success')
            return redirect(url_for('home'))
        return render_template('create_post.html',title="New Post",form=form,legend="New Post")

    @app.route("/post/<int:post_id>")
    def post(post_id):
        post=Post.query.get_or_404(post_id)
        return render_template('post.html',title=post.title, post=post)

    @app.route("/post/<int:post_id>/update",methods=["GET","POST"])
    @login_required
    def update_post(post_id):
        post=Post.query.get_or_404(post_id)
        if post.author1=current_user:
            abort(403)
        form=PostForm()
        if form.validate_on_submit():
            post.title=form.title.data
            post.
Example #11
0
def account():
    form = UpdateAccountForm()
    #on update button
    if form.validate_on_submit():
        if form.picture.data: #if are there any new 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
        #update data on db
        db.session.commit()
        flash('Your account has been updated!','success')
        return redirect(url_for('account'))
    elif request.method == 'GET':
        #fill form with existing data
        form.username.data = current_user.username
        form.email.data = current_user.email
    image_file = url_for('static', filename='profile_pics/'+current_user.image_file) #profile_pics is a dir
    return render_template('account.html', title='Account', image_file=image_file, form=form)
Example #12
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()
        logout()
        flash('Your account info is updated successfully! Now You can Log In',
              'success')
        return redirect(url_for('login'))
    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)
Example #13
0
def account():
    image_file = url_for('static',
                         filename=f'profile_pics/{current_user.image_file}')
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            current_user.image_file = save_picture(form.picture.data)
        current_user.username = form.username.data
        current_user.email = form.email.data
        db.__session.commit()
        flash('Your account have been updated successfully', 'success')
        return redirect(url_for('account'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
    return render_template('account.html',
                           title='Your account',
                           form=form,
                           picture=image_file)
Example #14
0
def account():
    form = UpdateAccountForm()
    posts_count = len(Post.query.filter_by(user_id=current_user.id).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
        db.session.commit()
        flash('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='profile_pics/' + current_user.image_file)
    connections = current_user.connections
    return render_template('account.html', title='Account',
                           image_file=image_file, form=form, posts_count=posts_count, connections = connections)
Example #15
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        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('account'))
    elif request.method == 'GET':
        #loads with form filled with current_user data on a GET request
        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)
Example #16
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            pic_name = update_picture(form.picture.data)
            current_user.image = pic_name
        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash('Your accounthas been updated !', 'success')
        return redirect(url_for('account'))

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

    image_file = url_for('static', filename="profile_pics/" + current_user.image)
    return render_template('account.html', title='accunt', form=form,
                           image_file=image_file)
Example #17
0
def account():
    '''this is a function to enable the users update the account information

    Args:
        form: load the UpdateAccountForm here
        form.username.data: username input from the form
        form.email.data: email input from the form
        picture_file: save the uploaded picture file
        current_user.image: user profile image in the record
        current_user.name: username in the record
        current_user.email: user email in the record
        request.method
    Return:
        render 'account.html' page
        resave the user data from the input form
        commit the change via db.

    '''
    form = UpdateAccountForm()
    #check if the input of the form is valid
    if form.validate_on_submit():
        #rewrite the record of the userdata(image_file,username,and email) with the new input
        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
        #commit the change via db.
        db.session.commit()
        #give a feedback and go back to the account page.
        flash('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='profile_pics/' + current_user.image_file)
    #render 'account.html' page
    return render_template('account.html',
                           title='Account',
                           image_file=image_file,
                           form=form)
Example #18
0
def user(user_id):
    user = User.query.get_or_404(user_id)
    form = UpdateAccountForm()
    form.username.data = user.username
    form.email.data = user.email
    image_file = url_for('static', filename='profile_pics/' + user.image_file)
    return render_template('account.html',
                           title='Account',
                           image_file=image_file,
                           form=form,
                           user=user)
Example #19
0
def account():
    #set the image file we want to pass to the template
    image_file = url_for('static',filename='profile_imgs/' + current_user.image_file)
    #instance of the UpdateAccountForm that exist in forms.py and parsing through render_template as a variable
    form = UpdateAccountForm()
    if form.validate_on_submit():
        '''if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file= picture_file'''
        #fetching username and email from db
        current_user.username = form.username.data
        current_user.email = form.email.data
        #commit to database
        db.session.commit()
        flash('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
    return render_template('account.html', title='Account',image_file=image_file,form=form)
Example #20
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_path = os.path.join(app.root_path, 'static/profile_pics', current_user.image_file)
            os.remove(picture_path)
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file
            current_user.face_reco_id = 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('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)
Example #21
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        current_user.FirstName = form.FirstName.data
        current_user.MiddleName = form.MiddleName.data
        current_user.LastName = form.LastName.data
        current_user.DOB = form.DOB.data
        current_user.UserEmail = form.UserEmail.data
        current_user.PhoneNo = form.PhoneNo.data
        db.session.commit()
        flash('Your account has been updated!', 'success')
        return redirect(url_for('account'))
    elif request.method == 'GET':
        form.FirstName.data = current_user.FirstName
        form.MiddleName.data = current_user.MiddleName
        form.LastName.data = current_user.LastName
        form.DOB.data = current_user.DOB
        form.UserEmail.data = current_user.UserEmail
        form.PhoneNo.data = current_user.PhoneNo
    return render_template('account.html', title='Account', form=form)
Example #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 successfuly 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="images/" + current_user.image_file)  #20:13
    return render_template("account.html",
                           title="Account",
                           image_file=image_file,
                           form=form)
Example #23
0
def account():
    form = UpdateAccountForm()

    if form.validate_on_submit():
        if form.image.data:
            current_user.image = save_image(form.image.data)
        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash('Your account has been updated')
        return redirect(url_for('account'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email

    file_image = url_for('static', filename=f'pictures/{current_user.image}')

    return render_template('account.html',
                           title='Acount',
                           form=form,
                           file_image=file_image)
Example #24
0
def account():
    #nous devons importer dabord updateaccount pour faire cette demarche fromflasklogin....
    form = UpdateAccountForm()
    if form.validate_on_submit():   # si notre form est valide alors on peut faire des changements
        if form.picture.data:   # pour sil ya une photo upload
        #
            picture_file = save_picture(form.picture.data) # save our picture 
            current_user.image_file = picture_file
        current_user.username = form.username.data   # le nouvel user sera envoyer a nos base de donnnees
        current_user.email = form.email.data
        db.session.commit()  # ici nous confirmons notre changement
        flash('Your account has been updated!', 'success')
        return redirect(url_for('account'))   # apres cela sa nous remets sur notre page account et on peut revoir sa
    elif request.method == 'GET':  # Get alors on peut populate sur nos data directement dans la Db comme le chn es drct
        #Get nous prenonsles informations depuis notre base de donnnees 
        form.username.data = current_user.username
        form.email.data = current_user.email
    image_file = url_for('static', filename='profile_pics/' + current_user.image_file) #image of our account 
    #where users will put the imagefile 
    return render_template('account.html', title='Account',
                           image_file=image_file, form=form)
Example #25
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:  #form.picture will just return the input type that it is expecting. it doesn't show if there actually is any data in there. So, we need to do 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("account"))
    elif request.method == "GET":  # Until the request is POST (button click), there will be the information displayed
        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)
Example #26
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
            db.session.commit()

        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('account'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
    profile_pic = url_for('static',
                          filename=f"profile_pics/{current_user.image_file}")
    return render_template('account.html',
                           title='Profile',
                           image_file=profile_pic,
                           form=form)
Example #27
0
def account():
    page = request.args.get('page', 1, type=int)
    posts = Post.query.order_by(Post.date_posted.desc()).paginate(page=page,
                                                                  per_page=3)
    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!', category='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='profile_pics/' + current_user.image_file)
    return render_template('account.html', title = 'Account', image_file = image_file,\
         form = form, posts = posts, user = current_user)
Example #28
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(
                form.picture.data
            )  # pictured data from form is passed into the save function
            current_user.image_file = picture_file  #the file name is returned and equated to current user image
        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash(f"Your Account has been Updated Successfully", '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='profile_pics/' + current_user.image_file)
    return render_template('account.html',
                           title='Account',
                           image_file=image_file,
                           form=form)
Example #29
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            if current_user.image_file != "default.jpg":
                delete_old_picture(current_user.image_file)
            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('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)
Example #30
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.image.data:
            picture = save_image(form.image.data)
            current_user.profile_picture = picture
        current_user.username = form.username.data
        current_user.email = form.email.data
        current_user.bio = form.bio.data
        db.session.commit()
        flash("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
        form.bio.data = current_user.bio
    profile_pic = url_for(
        "static", filename=f"profile_pics/{current_user.profile_picture}")
    return render_template("account.html",
                           title="Account",
                           profile_pic=profile_pic,
                           form=form)
Example #31
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        # Validation & setting the picture-path
        if form.picture.data:
            pic_file = save_picture(form.picture.data)
            current_user.image_file = pic_file
        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash('Your Account has been updated!', 'info')
        # Due to post-get-redirect pattern
        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='profile_pix/' + current_user.image_file)
    return render_template('account.html',
                           title='Account',
                           image_file=image_file,
                           form=form)