Beispiel #1
0
def profile(user_id):
    """Update profile for current user."""

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

    # user = User.query.get_or_404(user_id)  # don't need to re-query
    form = EditProfileForm(obj=g.user)

    # POST
    if form.validate_on_submit():
        # check user password before continuing
        user = User.authenticate(g.user.username, form.password.data)

        if user:
            # process data and add to DB
            g.user.username = form.data.get('username')
            g.user.email = form.data.get('email')
            g.user.image_url = form.data.get('image_url')
            g.user.bio = form.data.get('bio')
            db.session.add(g.user)
            db.session.commit()
            return redirect(f'/users/{g.user.id}')
        elif not form.validate_on_submit():
            # didn't work
            form.username.errors = [""]  #
            return render_template('users/edit.html', form=form, user=g.user)

    # GET
    return render_template('users/edit.html', form=form, user=g.user)
Beispiel #2
0
def edit_profile():
    #form = EditProfileForm(g.user.nickname)
    form = EditProfileForm()
    avatar_form = EditAvatarForm()
    cover_form = EditCoverForm()
    # ----- If form is used
    print 'EP', form.validate_on_submit()
    if form.validate_on_submit():
        g.user.name = form.name.data
        g.user.show_email = form.show_email.data
        g.user.bio = form.bio.data
        g.user.sex = form.sex.data
        g.user.slogan = form.slogan.data
        g.user.status = form.status.data
        g.user.location = form.location.data
        db.session.add(g.user)
        db.session.commit()
        flash('Your changes have been saved.', 'success')
        return redirect(url_for('edit_profile'))
    else:
        form.name.data = g.user.name
        form.show_email.data = g.user.show_email
        form.bio.data = g.user.bio
        form.sex.data = g.user.sex
        form.slogan.data = g.user.slogan
        form.status.data = g.user.status
        form.location.data = g.user.location
    return render_template(
        "site/%s/edit_profile.html" % (cordon.config['TEMPLATE']),
        user = g.user,
        form = form,
        avatar_form = avatar_form,
        cover_form = cover_form,
        )
Beispiel #3
0
def profile():
    """Update profile for current user."""

    if not g.user:
        flash("Access unauthorized.", "danger text-center")
        return redirect("/")

    user = User.query.get_or_404(g.user.id)
    form = EditProfileForm(obj=user)

    if form.validate_on_submit():
        user = User.authenticate(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

            db.session.commit()
            
            flash(f"Sucessfully updated!", 'success  text-center')
            return redirect(f"/users/{user.id}")

        flash("Invalid credentials.", 'danger text-center')        

        return redirect("/")
    
    return render_template('users/edit.html', form=form)
def edit_profile_page():
    if 'user_id' not in session :
        return redirect('/')

    edit_form = EditProfileForm(request.form)
    day_form = OneDayForm(request.form)
    deleteme = DeleteMeForm(request.form)

    sql = "SELECT * FROM user WHERE username = %s"
    mycursor.execute(sql, (session['user_id'], ))
    user = mycursor.fetchone()

    if edit_form.validate_on_submit() and edit_form.submit1.data == True:
        update_profile(edit_form, mycursor, mydb)
        return redirect(url_for('edit_profile_page'))
        
    if deleteme.validate_on_submit() and deleteme.submit3.data == True:
        if deleteme.delacc.data == "Delete Account":
            delete_account(mycursor, mydb)
            session.pop('user_id')
            return redirect(url_for('home_page'))

        else:
            return redirect(url_for('edit_profile_page'))


    if day_form.submit2.data == True:
        update_day(day_form, mycursor, mydb)

        check_times(mycursor, mydb)
        return redirect(url_for('edit_profile_page'))

    

    return render_template("edit_profile.html", edit_form=edit_form, day_form=day_form, user=user, deleteme=deleteme)
Beispiel #5
0
def profile():
    """Update profile for current user."""

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

    form = EditProfileForm(username=g.user.username,
                           email=g.user.email,
                           image_url=g.user.image_url,
                           password=g.user.password,
                           bio=g.user.bio,
                           location=g.user.location)

    if form.validate_on_submit():
        user = User.authenticate(form.username.data, form.password.data)

        user.username = form.username.data
        user.email = form.email.data
        user.image_url = form.image_url.data
        user.bio = form.bio.data
        user.location = form.location.data

        # The consequence of having
        #### user.password = form.password.data ####
        # is setting a new plain text non-hashed password into the database
        # the password is now 123456 in plain text
        # Python is looking for $b2$12$...(start of encrypted salt key)
        # and can't find salt key, hence the error "invalid Salt"

        db.session.commit()
        return redirect(f'/users/{g.user.id}')

    return render_template('/users/edit.html', form=form)
Beispiel #6
0
def edit_profile():
    form = EditProfileForm()
    if form.validate_on_submit():
        conn = try_connect()
        cursor = conn.cursor()
        cursor.execute(
            'UPDATE uuser SET target_weight = %s, current_weight = %s, calories = %s, height = %s, age = %s WHERE '
            'uuser_id = %s',
            (form.target_weight.data, form.current_weight.data, form.calories.data, form.height.data, form.age.data,
             current_user.id))
        conn.commit()
        cursor.close()
        conn.close()
        flash('Your changes have been saved.')
        return redirect(url_for('profile', uuser_id=current_user.id))
    elif request.method == 'GET':
        conn = try_connect()
        cursor = conn.cursor()
        cursor.execute('SELECT target_weight, current_weight, calories, height, age '
                       'FROM uuser  '
                       'WHERE uuser_id = %s',
                       (current_user.id,))
        records = cursor.fetchone()
        form.target_weight.data = records[0]
        form.current_weight.data = records[1]
        form.calories.data = records[2]
        form.height.data = records[3]
        form.age.data = records[4]
    return render_template('edit_profile.html', title='Edit Profile', form=form)
Beispiel #7
0
def edit_profile():
    """Update profile for current user."""

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

    form = EditProfileForm(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
            user.header_image_url = form.header_image_url.data
            user.bio = form.bio.data or User.bio.default.arg
            user.location = form.location.data
            user.show_location = form.show_location.data
            user.time_zone = form.time_zone.data

            db.session.commit()
            return redirect(f'/users/{user.id}')
        else:
            flash("Wrong password. Access unauthorized.", "danger")
            return redirect('/')

    else:
        return render_template("/users/edit.html",
                               form=form,
                               user_id=g.user.id)
Beispiel #8
0
def profile():
    """Update profile for current user."""

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

    form = EditProfileForm()
    if form.validate_on_submit():
        user = User.authenticate(form.username.data,
                                 form.password.data)
        if user:
            g.user.username = form.username.data
            g.user.email = form.email.data
            g.user.image_url = form.image_url.data
            g.user.header_image_url = form.header_image_url.data
            g.user.bio = form.bio.data
            g.user.location = form.location.data

            db.session.commit()
            return redirect(f'/users/{user.id}')
        else:
            flash("Access denied/Wrong password.", "danger")
            return redirect("/")
    return render_template('users/edit.html', form=form)
Beispiel #9
0
def edit_profile():
    user = get_current_user()
    form = EditProfileForm()
    if form.validate_on_submit():
        try:
            with pg_db.atomic():
                edit_q = User.update(
                    username=form.username.data,
                    about_me=form.about_me.data
                ).where(
                    User.username == user.username
                )
                edit_q.execute()

            # We should update our session object with a new username
            session['username'] = form.username.data
            user = get_current_user()
            flash('Your data has been changed')
            return redirect(url_for('profile', username=user.username))

        except IntegrityError:
            flash('That username or email is already used by someone else')
    else:
        form.username.data = user.username
        form.about_me.data = user.about_me
    return render_template('edit_profile.html', form=form, title='Edit your profile')
Beispiel #10
0
def edit_profile():
    form = EditProfileForm()
    if form.validate_on_submit():
        current_user.first_name = form.first_name.data
        current_user.last_name = form.last_name.data
        current_user.location = form.location.data
        current_user.national_id = form.national_id.data
        current_user.phone_number = form.phone_number.data
        current_user.marital_status = form.marital_status.data
        current_user.gender = form.gender.data
        current_user.d_o_b = form.d_o_b.data

        db.session.add(current_user)
        flash('Your profile has been updated.')
        return redirect(url_for('.user', username=current_user.username))
    form.first_name.data = current_user.first_name
    form.last_name.data = current_user.last_name
    form.location.data = current_user.location
    form.national_id.data = current_user.national_id
    form.phone_number.data = current_user.phone_number
    form.marital_status.data = current_user.marital_status
    form.gender.data = current_user.gender
    form.d_o_b.data = current_user.d_o_b

    return render_template('edit_profile.html', form=form, user=user)
Beispiel #11
0
def profile():
    """Update profile for current user."""

    # IMPLEMENT THIS

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

    form = EditProfileForm(obj=g.user)

    if form.validate_on_submit():
        # import pdb; pdb.set_trace()
        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
            user.header_image_url = form.header_image_url.data
            user.bio = form.bio.data
            user.location = form.location.data
            db.session.add(user)
            db.session.commit()
            return redirect(f"/users/{g.user.id}")

        flash("Invalid credentials.", 'danger')

    return render_template("users/edit.html", form=form)
Beispiel #12
0
def profile():
    """Update profile for current user."""

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

    form = EditProfileForm(obj=g.user)

    if form.validate_on_submit():

        password = form.password.data
        user = User.authenticate(g.user.username, password)
        if user:
            user.username = form.username.data
            user.image_url = form.image_url.data
            user.header_image_url = form.header_image_url.data
            user.bio = form.bio.data
            db.session.add(user)
            db.session.commit()
            return redirect(f'/users/{user.id}')
        else:
            flash("Incorrect password entered to edit profile.", "danger")
            return redirect("/")
    else:
        return render_template('users/edit.html', form=form)
Beispiel #13
0
def edit_profile():
    user = User.query.get(current_user.id)
    form = EditProfileForm(request.form, phone=user.phone, email=user.email)
    passform = ChangePasswordForm(request.form)
    if request.method == 'POST':
        #if the user clicked button to update profile
        if request.form['submit'] == 'Update' and form.validate_on_submit():
            phone = form.phone.data
            email = form.email.data
            user.phone = phone
            user.email = email
            db.session.commit()
            return redirect('home')
        #if user clicked change password
        if request.form[
                'submit'] == 'Change Password' and passform.validate_on_submit(
                ):
            #generate hash
            newpass = generate_password_hash(passform.password.data)
            user.password_hash = newpass
            db.session.commit()
            return redirect('edit_profile')
    return render_template('edit_profile.html',
                           form=form,
                           passform=passform,
                           user=user)
Beispiel #14
0
def profile():
    """Update profile for current user."""

    if not g.user:
        flash("Please sign in to view this page.", "danger")
        return redirect("/login")

    form = EditProfileForm(obj=g.user)
    if form.validate_on_submit():
        password = form.password.data
        if User.authenticate(g.user.username, password):
            # Update user
            g.user.username = form.username.data
            g.user.email = form.email.data
            if form.image_url.data:
                g.user.image_url = form.image_url.data
            if form.header_image_url.data:
                g.user.header_image_url = form.header_image_url.data
            if form.bio.data:
                g.user.bio = form.bio.data

            db.session.add(g.user)
            db.session.commit()

            return redirect(f"/users/{g.user.id}")
        else:
            flash("Incorrect password", "danger")

    return render_template("/users/edit.html", form=form, user=g.user)
def edit():
	form = EditProfileForm()

	if form.validate_on_submit():
		current_user.firstname = form.firstname.data
		current_user.lastname = form.lastname.data
		current_user.address = form.address.data
		current_user.city = form.city.data
		current_user.state = form.state.data
		current_user.zipcode = form.zipcode.data
		current_user.country = form.country.data
		current_user.about_me = form.about_me.data
		current_user.user_disabled = form.user_disabled.data

		model.session.add(current_user)
		model.session.commit()

		flash('Your changes have been saved!')
		return redirect(url_for('edit'))
		#renders the fields with data from database
	else:
		form.firstname.data= current_user.firstname
		form.lastname.data= current_user.lastname 
		form.address.data= current_user.address 
		form.city.data= current_user.city 
		form.state.data= current_user.state
		form.zipcode.data= current_user.zipcode
		form.country.data= current_user.country
		form.about_me.data= current_user.about_me
		form.user_disabled.data= current_user.user_disabled

	return render_template("edit_profile.html",
							form=form)
Beispiel #16
0
def edit():
    form = EditProfileForm()
    if form.validate_on_submit():
        g.user.emailReminders = form.emailReminders.data
        g.user.pmReminders = form.pmReminders.data
        if not form.email.data:
            g.user.email = None
            g.user.emailConfirmed = None
            db.session.add(g.user)
            db.session.commit()
            flash('Profile Successfully Updated.', 'info')
            return redirect(url_for('edit'))
        if form.email.data == g.user.email and g.user.emailConfirmed:
            db.session.add(g.user)
            db.session.commit()
            flash('Profile Successfully Updated.', 'info')
            return redirect(url_for('edit'))
        provisionalEmail = form.email.data
        if g.user.email is None or g.user.emailConfirmed == False:
            g.user.email = provisionalEmail
            g.user.emailConfirmed = False
            db.session.add(g.user)
            db.session.commit()
        message.send_email('Confirm Your Account', [provisionalEmail], 'confirmation',
            user=g.user, token=g.user.generate_confirmation_token(email=provisionalEmail))
        flash('A confirmation message has been sent to you. Please check your spam or junk folder.', 'warning')
        return redirect(url_for('edit'))

    form.email.data = g.user.email
    form.emailReminders.data = g.user.emailReminders
    form.pmReminders.data = g.user.pmReminders

    return render_template('editprofile.html',
                           form=form,
                           user=g.user)
Beispiel #17
0
def profile():
    """Update profile for current user."""

    if CURR_USER_KEY not in session:
        flash("Access unauthorized.", "danger")
        return redirect("/")

    form = EditProfileForm(obj=g.user)

    if form.validate_on_submit():

        if User.authenticate(g.user.username, form.password.data):

            g.user.username = form.username.data,
            g.user.email = form.email.data,
            g.user.image_url = form.image_url.data or User.image_url.default.arg,
            g.user.header_image_url = form.header_image_url.data,
            g.user.bio = form.bio.data

            db.session.commit()
            return redirect(f'/users/{g.user.id}')
        else:
            flash("Wrong Password!", "danger")
            return redirect("/")
    else:
        return render_template('/users/edit.html', form=form)
Beispiel #18
0
def profile():
    """Update profile for current user."""

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

    user = User.query.get(session[CURR_USER_KEY])

    form = EditProfileForm(obj=user)

    if form.validate_on_submit():
        if User.authenticate(form.username.data, form.password.data):
            user.username = form.username.data
            user.email = form.email.data
            user.image_url = form.image_url.data
            user.header_image_url = form.header_image_url.data
            user.bio = form.bio.data
            user.location = form.location.data

            db.session.commit()
            return redirect(f"/users/{user.id}")

        flash("Wrong password, please try agin.", "danger")

    return render_template('users/edit.html', form=form, user_id=user.id)
Beispiel #19
0
def edit():
    form = EditProfileForm()
    if form.validate_on_submit():
        pic_file = request.files[form.profile_pic.name]
        if pic_file and allowed_file(pic_file.filename):
            filename = secure_filename(pic_file.filename)
            folder = os.path.join(current_app.config['UPLOAD_FOLDER'],
                                  PROFILE_PIC_UPLOAD_SUBFOLDER)
            if not os.path.exists(folder):
                os.makedirs(folder)
            pic_file.save(os.path.join(folder, filename))
            current_user.profile_pic_url = url_for('.profile_pic',
                                                   filename=filename)

        current_user.name = form.name.data
        current_user.email = form.email.data
        db.session.add(current_user)
        db.session.commit()
        flash("Account information saved successfully", "success")
        return redirect(url_for('.show'))

    if request.method == 'GET':
        form.name.data = current_user.name
        form.email.data = current_user.email

    return render_template('account/edit.html', form=form)
Beispiel #20
0
def edit_profile():
    user = current_user
    form = EditProfileForm()
    
    if form.validate_on_submit():
        user.name = form.name.data
        user.farm_address = form.farm_address.data
        user.zip_code = form.zip_code.data
        user.city = form.city.data
        user.state = form.state.data
        user.country = form.country.data
        user.phone = form.phone.data
        user.description = form.description.data
        print("Profile Updated")
        return redirect(url_for('dashboard'))
    else:
        form.name.data = user.name
        form.farm_address.data = user.farm_address
        form.zip_code.data = user.zip_code
        form.city.data = user.city
        form.state.data = user.state
        form.country.data = user.country
        form.phone.data = user.phone
        form.description.data = user.description

    return render_template('edit_profile_consumer.html', form=form)
Beispiel #21
0
def edit_profile():
    form = EditProfileForm()
    if form.validate_on_submit():
        print "VALIDATE"
        current_user.name = form.name.data
        current_user.location = form.location.data
        current_user.about_me = form.about_me.data
        filename = secure_filename(form.picture.data.filename)
        delete_picture = form.remove_picture.data
        print filename
        if delete_picture:
            if current_user.image is not None:
                os.remove(
                    os.path.join(current_app.config['UPLOADED_PHOTOS_DEST'],
                                 current_user.image))
            current_user.image = None
            current_user.social_image = None

        if current_user.image is not None and filename:
            os.remove(
                os.path.join(current_app.config['UPLOADED_PHOTOS_DEST'],
                             current_user.image))

        print filename
        if filename:
            photos.save(request.files['picture'])
            current_user.image = filename

        db.session.add(current_user)
        return redirect(url_for('.user', username=current_user.username))
    form.name.data = current_user.name
    form.location.data = current_user.location
    form.about_me.data = current_user.about_me
    return render_template('edit-profile.html', form=form)
Beispiel #22
0
def edit():
    form = EditProfileForm()

    if form.validate_on_submit():
        current_user.firstname = form.firstname.data
        current_user.lastname = form.lastname.data
        current_user.address = form.address.data
        current_user.city = form.city.data
        current_user.state = form.state.data
        current_user.zipcode = form.zipcode.data
        current_user.country = form.country.data
        current_user.about_me = form.about_me.data
        current_user.user_disabled = form.user_disabled.data

        model.session.add(current_user)
        model.session.commit()

        flash('Your changes have been saved!')
        return redirect(url_for('edit'))
        #renders the fields with data from database
    else:
        form.firstname.data = current_user.firstname
        form.lastname.data = current_user.lastname
        form.address.data = current_user.address
        form.city.data = current_user.city
        form.state.data = current_user.state
        form.zipcode.data = current_user.zipcode
        form.country.data = current_user.country
        form.about_me.data = current_user.about_me
        form.user_disabled.data = current_user.user_disabled

    return render_template("edit_profile.html", form=form)
Beispiel #23
0
def edit():
    form = EditProfileForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=current_user.email).first()
        user.first_name = form.first_name.data
        user.last_name = form.last_name.data
        user.email = form.email.data
        user.city = form.city.data
        user.state = form.state.data
        user.zip_code = form.zip_code.data
        if form.password.data is not None:
            user.update_password(form.password.data)
        try:
            commit(db.session)
        except:
            send_error_email()
            flash('There has been an error')
            return render_template('profile/edit.html', form=form)
        return redirect(url_for('profile.index'))

    form.first_name.data = current_user.first_name
    form.last_name.data = current_user.last_name
    form.email.data = current_user.email
    form.city.data = current_user.city
    form.state.data = current_user.state
    form.zip_code.data = current_user.zip_code

    return render_template('profile/edit.html', form=form)
def edit_profile():
    form = EditProfileForm()
    c = Config()
    if form.validate_on_submit():
        current_user.bio = form.bio.data
        current_user.address = form.address.data
        current_user.phone_number = form.phone_number.data
        current_user.website = form.website.data
        current_user.public_email = form.email.data
        current_user.f1 = form.featured1.data
        if form.image.data:
            filename = form.image.data.filename
            get_queue().enqueue(process_image, 
                                type='image',
                                filename=filename,
                                data =form.image.data.read(),
                                user_id=current_user.id)
        if form.pdf.data:
            filename = form.pdf.data.filename
            get_queue().enqueue(process_image, 
                                type='pdf',
                                filename=filename,
                                data =form.pdf.data.read(),
                                user_id=current_user.id)
        db.session.commit()
        return redirect(url_for('vendor.view_profile'))
    form.bio.data = current_user.bio
    form.address.data = current_user.address
    form.phone_number.data = current_user.phone_number
    form.website.data = current_user.website
    form.email.data = current_user.public_email
    form.featured1.data = current_user.f1
    return render_template('vendor/edit_profile.html', form=form)
Beispiel #25
0
def edit_profile():
    form = EditProfileForm()
    c = Config()
    if form.validate_on_submit():
        current_user.bio = form.bio.data
        current_user.address = form.address.data
        current_user.phone_number = form.phone_number.data
        current_user.website = form.website.data
        current_user.public_email = form.email.data
        current_user.f1 = form.featured1.data
        if form.image.data:
            filename = form.image.data.filename
            get_queue().enqueue(process_image, 
                                type='image',
                                filename=filename,
                                data =form.image.data.read(),
                                user_id=current_user.id)
        if form.pdf.data:
            filename = form.pdf.data.filename
            get_queue().enqueue(process_image, 
                                type='pdf',
                                filename=filename,
                                data =form.pdf.data.read(),
                                user_id=current_user.id)
        db.session.commit()
        return redirect(url_for('vendor.view_profile'))
    form.bio.data = current_user.bio
    form.address.data = current_user.address
    form.phone_number.data = current_user.phone_number
    form.website.data = current_user.website
    form.email.data = current_user.public_email
    form.featured1.data = current_user.f1
    return render_template('vendor/edit_profile.html', form=form)
Beispiel #26
0
def edit_profile():
    form = EditProfileForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file
        current_user.firstname = form.firstname.data
        current_user.lastname = form.lastname.data
        current_user.dob = form.dob.data
        current_user.address = form.address.data
        current_user.state = form.state.data
        current_user.country = form.country.data
        current_user.pincode = form.pincode.data
        current_user.phoneno = form.phoneno.data
        current_user.department = form.department.data
        db.session.commit()
        flash('Your account has been updated!', 'success')
        return redirect(url_for('edit_profile'))
    elif request.method == 'GET':
        form.firstname.data = current_user.firstname
        form.lastname.data = current_user.lastname
        form.dob.data = current_user.dob
        form.address.data = current_user.address
        form.state.data = current_user.state
        form.country.data = current_user.country
        form.pincode.data = current_user.pincode
        form.phoneno.data = current_user.phoneno
        form.department.data = current_user.department
    image_file = url_for('static', filename='img/' + current_user.image_file)
    return render_template('edit-profile.html',
                           image_file=image_file,
                           form=form)
Beispiel #27
0
def profile_edit():
    form = EditProfileForm(obj=current_user)
    if form.validate_on_submit():
        current_user.name = form.name.data
        current_user.email = form.email.data
        current_user.phone = form.phone.data
        if form.new_password.data and form.current_password.data:
            if current_user.verify_password(form.current_password.data):
                current_user.password = form.new_password.data
                db.session.add(current_user)
                db.session.commit()
                flash('Your profile has been updated')
            else:
                flash('Invalid current password; password not updated')
        else:
            db.session.add(current_user)
            db.session.commit()
            flash('Your profile has been updated')
        return redirect(url_for('.index'))
    form.name.data = current_user.name
    form.email.data = current_user.email
    form.phone.data = current_user.phone
    return render_template('student/profile-edit.html',
                           student=current_user,
                           form=form)
Beispiel #28
0
def profile(user_id):
    """Update profile for current user."""

    if not g.user:
        flash("Access unauthorized.", "danger")
        return redirect("/")
    
    user = User.query.get_or_404(user_id)
    form = EditProfileForm(obj=user)
    

    if form.validate_on_submit():

        username = form.username.data
        email = form.email.data
        image_url = form.image_url.data
        header_image_url = form.header_image_url.data
        bio = form.bio.data

        db.session.commit()

        return redirect('/')

    else:
        return render_template('users/edit.html', form=form, user=user)
def edit_profile():
    form = EditProfileForm()
    userIdStr = str(current_user.get_id())
    avatarLocation = 'static/avatars/' + userIdStr + '.jpeg'
    avatarFromUser = '******' + userIdStr + '.jpeg'
    if form.validate_on_submit():
        uploaded_file = request.files['file']
        if uploaded_file.filename != '':
            file_ext = os.path.splitext(uploaded_file.filename)[1]
            if file_ext not in app.config['UPLOAD_EXTENSIONS']:
                abort(400)
            else:
                uploaded_file.save(avatarLocation)
        current_user.about_me = form.about_me.data
        db.session.commit()
        return redirect(
            url_for('user',
                    username=current_user.username,
                    avatarLocation=avatarLocation,
                    avatarFromUser=avatarFromUser))

    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)
Beispiel #30
0
def profile():
    """Update profile for current user."""

    # Check to see if user is logged in.
    if not g.user:
        flash("Access unauthorized. You must be logged in to view this page.", "danger")
        return redirect("/")

    user = User.query.get_or_404(g.user.id)
    form = EditProfileForm(obj=user)

    if form.validate_on_submit():
        if User.authenticate(user.username, form.password.data):
            user.username = form.username.data
            user.email = form.email.data
            user.image_url = form.image_url.data
            user.header_image_url = form.header_image_url.data
            user.bio = form.bio.data
            user.location = form.location.data

            db.session.commit()

            # ******** Need to fix this so only valid information will allow a db.commit ********
            # try:
            #     db.session.commit()

            flash("Success! User has been updated.", "success")
            return redirect(f"/users/{user.id}")
        flash("The password you entered is incorrect, please try again.", "danger")
        return redirect("/")

    return render_template("/users/edit.html", form=form, user=user)
Beispiel #31
0
def edit_profile():
    form = EditProfileForm()
    if form.validate_on_submit():
        current_user.name = form.name.data
        db.session.add(current_user)
        flash('Your profile has been updated.')
        return redirect(url_for('.user', username=current_user.username))
    form.name.data = current_user.name
    return render_template('apartment/edit_profile.html', form=form)
Beispiel #32
0
def edit_profile():
    form = EditProfileForm()
    if form.validate_on_submit():
        current_user.name = form.name.data
        db.session.add(current_user)
        flash('Your profile has been updated.')
        return redirect(url_for('.user', username=current_user.username))
    form.name.data = current_user.name
    return render_template('apartment/edit_profile.html', form=form)
Beispiel #33
0
def editprofile():

    form = EditProfileForm(obj=current_user)

    # form.populate_obj(user)

    if form.validate_on_submit():
        return render_template('editprofile.html', title="Username", user=current_user, form=form)

    return render_template('editprofile.html', title="Username", user=current_user, form=form)
def edit_profile():
    form = EditProfileForm()
    if request.method == 'GET':
        form.about_me.data = current_user.about_me
    if form.validate_on_submit():
        current_user.about_me = form.about_me.data
        db.session.commit()
        return redirect(url_for('profile'), username=current_user.username
                        )  # has to give profile, and username
    return render_template('edit_profile.html', form=form)
Beispiel #35
0
def edit_profile():
    form = EditProfileForm()
    if 'loggedin' in session:
        if form.validate_on_submit():
            session['username'] = form.username.data
            session['email'] = form.email.data
            session['first_name'] = form.first_Name.data
            session['last_name'] = form.last_Name.data
            session['phone'] = form.phone.data
            session['gender'] = form.category.data
            flash('Your changes have been saved.')
            cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
            cursor.execute(
                'UPDATE trading_Profile SET username = %s , email = %s, first_Name = %s ,last_Name = %s'
                ', phone = %s, gender = %s'
                'WHERE trading_ID = %s', (
                    session['username'],
                    session['email'],
                    session['first_name'],
                    session['last_name'],
                    session['phone'],
                    session['gender'],
                    session['id'],
                ))

            cursor.execute('SELECT * FROM trading_Profile WHERE username = %s',
                           (session['id'], ))
            cursor2 = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
            cursor2.execute(
                'SELECT * FROM trading_Profile ORDER BY  amount_Money desc')
            data = cursor2.fetchall()
            account = cursor.fetchone()
            mysql.connection.commit()
            return render_template('Home_page.html',
                                   msg=account,
                                   len=len(data),
                                   data=data)
        elif request.method == 'GET':
            form.username.data = session['username']
            form.email.data = session['email']
            form.category.data = session['gender']
            if form.first_Name.data == 'Null':
                form.first_Name.data = ''
            else:
                form.first_Name.data = session['first_name']
            if form.last_Name.data == 'Null':
                form.last_Name.data = ''
            else:
                form.last_Name.data = session['last_name']
            if form.phone.data == 'Null':
                form.phone.data = ''
            else:
                form.phone.data = session['phone']
        return render_template('Profile.html', title='Edit Profile', form=form)
Beispiel #36
0
def edit_profile():
    form4 = EditProfileForm()
    if form4.validate_on_submit():
        print("AYYYYO")
        user = models.User.select().where(
            models.User.username == current_user.username).get()
        user.username = form4.username.data
        user.city = form4.city.data
        user.save()
        return redirect(url_for('stream'))
    else:
        return redirect(url_for('stream'))
Beispiel #37
0
def edit_profile():
    form = EditProfileForm()
    if form.validate_on_submit():
        current_user.name = form.name.data
        current_user.location = form.location.data
        current_user.about_me = form.about_me.data
        DB.update_user_profile(current_user)
        return redirect(url_for('.user', username=current_user.username))
    form.name.data = current_user.name
    form.location.data = current_user.location
    form.about_me.data = current_user.about_me
    return render_template('edit_profile.html', form=form)
Beispiel #38
0
def edit_profile():
    form = EditProfileForm()
    if form.validate_on_submit():
        current_user.about_me = form.about_me.data
        db.session.commit()
        flash('Twoje zmiany zostały zapisane.')
        return redirect(url_for('edit_profile'))
    elif request.method == 'GET':
        form.about_me.data = current_user.about_me
    return render_template('edit_profile.html',
                           title='Edytuj profil',
                           form=form)
def edit_profile():
    user = User.query.get(session['user_id'])
    form = EditProfileForm(obj=user)
    form.populate_obj(user)
    if form.validate_on_submit():
        print user
        db.session.add(user)
        print "session add user"
        db.session.commit()
        print "session commit user"
        return redirect(url_for('profile'))
    return render_template('edit_profile.html', form=form)
Beispiel #40
0
def edit_profile():
    form = EditProfileForm()
    if form.validate_on_submit():
        current_user.name = form.name.data
        current_user.location = form.location.data
        current_user.about_me = form.about_me.data
        db.session.add(current_user)
        flash("Your profile has been updated .")
        return redirect(url_for('main.user', username=current_user.username))
    form.name.data = current_user.name
    form.location.data = current_user.location
    form.about_me.data = current_user.about_me
    return render_template('edit_profile.html', form=form)
Beispiel #41
0
def editUserInfo():
    form = EditProfileForm()
    user=current_user
    if form.validate_on_submit():
        current_user.name = form.name.data
        current_user.location = form.location.data
        current_user.about_me = form.about_me.data
        current_user.contactMe = form.mycontact.data
        current_user.avatar = form.avatar.data
        db.session.add(current_user)
        db.session.commit()
        flash(u'修改个人信息成功')
    return render_template('info/editUserInfo.html', form=form, user=user)
Beispiel #42
0
def edit_profile():
    form = EditProfileForm(g.user.nickname)
    flash(g.user.nickname)

    if form.validate_on_submit():
        print 'inside validate_on_submit'
        g.user.about_me = form.about_me.data
        g.user.nickname = form.nickname.data
        db.session.add(g.user)
        db.session.commit()
        flash("About me save !")
        return redirect(url_for('index'))

    return render_template('edit_profile.html', form=form)
Beispiel #43
0
def editprofile():
    form = EditProfileForm(current_user.name)
    if form.validate_on_submit():
        current_user.name = form.name.data
        current_user.email = form.email.data
        current_user.phone = form.phone.data
        db_session.add(current_user)
        db_session.commit()
        flash('Your changes have been saved.')
        return redirect(url_for('editprofile'))
    elif request.method != "POST":
        form.name.data = current_user.name
        form.email.data = current_user.email
        form.phone.data = current_user.phone
    return render_template('editprofile.html', form=form)
Beispiel #44
0
def edit_profile():
	form = EditProfileForm(g.user.username)
	if form.validate_on_submit():
		g.user.username = form.username.data
		g.user.about = form.about.data
		db.session.add(g.user)
		db.session.commit()
		flash('Your changes have been saved.')
		return redirect(url_for('user', username = g.user.username))
	else:
		form.username.data = g.user.username
		form.about.data = g.user.about
	return render_template('edit_profile.html', 
		title = 'Edit Profile',
		form = form)
Beispiel #45
0
def edit_profile():
	form = EditProfileForm()
	if(form.validate_on_submit()):
		g.user.email = form.email.data
		g.user.fname = form.fname.data
		g.user.lname = form.lname.data
		g.user.school = form.school.data
		g.user.sex = form.sex.data
		db.session.add(g.user)
		db.session.commit()
		flash('Your changes have been saved')
		return redirect(url_for('edit_profile'))
	else:
		form.email.data = g.user.email
		form.fname.data = g.user.fname
		form.lname.data = g.user.lname
		form.school.data = g.user.school
		form.sex.data = g.user.sex
	return render_template('edit_profile.html', form=form)
Beispiel #46
0
def profile_edit():
    form = EditProfileForm(obj=current_user)
    if form.validate_on_submit():
        current_user.email = form.email.data
        if form.new_password.data and form.current_password:
            if current_user.verify_password(form.current_password.data):
                current_user.password = form.new_password.data
                db.session.add(current_user)
                db.session.commit()
                flash('Your profile has been updated')
            else:
                flash('Invalid current password; password not updated')
        else:
            db.session.add(current_user)
            db.session.commit()
            flash('Your profile email has been updated')
        return redirect(url_for('.index'))
    form.email.data = current_user.email
    return render_template('admin/profile-edit.html', student=current_user,
                           form=form)