Beispiel #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('Your 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
    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)
Beispiel #2
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        current_user.name = form.name.data
        current_user.password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        current_user.weight = form.weight.data
        current_user.city = form.city.data
        current_user.interest = form.interest.data
        current_user.languages = form.languages.data
        current_user.birthday = form.birthday.data
        db.session.commit()
        #'Your account has been updated!', 'success'
        return redirect(url_for('account'))
    elif request.method == 'GET':
        form.name.data = current_user.name
        form.password.data = current_user.password
        current_user.weight = form.weight.data
        current_user.city = form.city.data
        current_user.birthday = form.birthday.data
    #image_file = url_for('static', filename='profile_pics/' + current_user.image_file) # I couldnt use it
    return render_template('account.html', title='Account',form=form)
def update_account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            update_picture = db.execute(
                "UPDATE user SET image_file = :image_file WHERE user_id = :user_id",
                user_id=int(session.get("user_id")),
                image_file=picture_file)
        # Update information in "user" table
        update_user = db.execute(
            "UPDATE user SET firstName = :firstname, lastName = :lastname, email = :email WHERE user_id = :user_id",
            user_id=int(session.get("user_id")),
            firstname=form.firstname.data,
            lastname=form.lastname.data,
            email=form.email.data)
        # flash message
        flash('Account info updated successfully!', 'success')
    else:
        flash("Sorry, we're unable to update your information.", 'danger')
    return redirect("/account_settings")
Beispiel #4
0
def profile():
    formpage = UpdateAccountForm()
    if formpage.validate_on_submit():
        if formpage.picture.data:  # save profile picture
            picture_file = save_picture(formpage.picture.data)
            current_user.image_file = picture_file
        current_user.name = formpage.name.data
        current_user.email = formpage.email.data
        current_user.phone = formpage.phone.data
        db.session.commit()
        flash('Your account has been updated!', 'success')
        return redirect(url_for('profile'))
    elif request.method == 'GET':
        formpage.name.data = current_user.name
        formpage.email.data = current_user.email
        formpage.phone.data = current_user.phone
    image_file = url_for('static',
                         filename='profile_pics/' + current_user.image_file)
    return render_template('profile.html',
                           title='Profile',
                           image_file=image_file,
                           formpage=formpage)
Beispiel #5
0
def account_info():
	form = UpdateAccountForm()
	if form.validate_on_submit():
		if form.profile_pic.data:
			profile_pic_file = save_picture(form.profile_pic.data, 125, 'profile_pics')
			current_user.profile_pic = profile_pic_file
			mongodb_query.profile_pic_update(current_user.username, current_user.profile_pic)
		# kostyl iz-za mongodb
		current_user.name = form.name.data
		current_user.surname = form.surname.data
		current_user.phone_number = form.phone_number.data
		if mongodb_query.user_update(current_user.username, current_user.name, current_user.surname, current_user.phone_number):
			flash('Your data has been updated!', 'success')
			return redirect(url_for('account_info'))
		else:
			flash('Something went wrong!', 'warning')
			return redirect(url_for('account_info'))
	elif request.method == 'GET':
		form.name.data = current_user.name
		form.surname.data = current_user.surname
		form.phone_number.data = current_user.phone_number
	avatar_img = url_for('static', filename='content/profile_pics/' + current_user.profile_pic)
	return render_template('account_info.html', title='Account info', avatar_img=avatar_img, form=form)
Beispiel #6
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = upload_picture(form.picture.data)
            current_user.image_file = picture_file
        current_user.email = form.email.data
        db.session.commit()
        flash('Your account has been updated', 'success')
        return redirect(
            url_for('account')
        )  # so the get request will superceed another post request????
    elif request.method == 'GET':
        #form.username.data = current_user.username - taken out of form requirements
        form.email.data = current_user.email
    # https://www.youtube.com/watch?v=803Ei2Sq-Zs&list=PL-osiE80TeTs4UjLw5MM6OjgkjFeUxCYH&index=7
    image_file = S3_LOCATION + current_user.image_file

    return render_template(
        'admin/account.html',
        title='Account',
        image_file=image_file,
        form=form)  # form=form now form appears on account page
Beispiel #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
        current_user.email = form.email.data

        db.execute("UPDATE users SET username=:username WHERE id=:id", {
            "id": current_user.id,
            "username": current_user.username
        })
        db.execute("UPDATE users SET email=:email WHERE id=:id", {
            "id": current_user.id,
            "email": current_user.email
        })
        db.execute("UPDATE users SET image_file=:image_file WHERE id=:id", {
            "id": current_user.id,
            "image_file": current_user.image_file
        })

        db.commit()

        flash('Your account has been updated!', category='success')
        return redirect(url_for('account'), code=302, Response=None)
    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)
Beispiel #8
0
def account():
    id = request.args['id']
    db = DB()
    get_user = db.GetByID(id)

    form = UpdateAccountForm()
    if form.validate_on_submit():
        db.UpdateAll(id, form.username.data, form.email.data, form.first_name.data,
             form.last_name.data, form.dob.data, form.address.data, form.city.data, form.state.data, form.phone_no.data)
        flash('Account Updated Successfully', 'success')
        return redirect(url_for('account', id=id))

    elif request.method == 'GET':
        form.username.data = get_user[1]
        form.email.data = get_user[3]
        form.first_name.data = get_user[4]
        form.last_name.data = get_user[5]
        form.dob.data = get_user[6]
        form.address.data = get_user[7]
        form.city.data = get_user[8]
        form.state.data = get_user[9]
        form.phone_no.data = get_user[10]

    return render_template('account.html', title='Account', data=get_user, form=form)