Exemple #1
0
def profile():
    form = UpdateProfileForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=current_user.username).first()
        user.address = form.address.data
        user.city = form.city.data
        print(user.city)
        db.session.add(user)
        db.session.commit()
        flash('Congratulations, you update your profile!')
        return redirect(url_for('index'))
    return render_template('profile.html', title='Profile', form=form)
Exemple #2
0
def update_profile():
    form = UpdateProfileForm()
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.email = form.email.data
        if form.new_password.data:
            current_user.password = bcrypt.generate_password_hash(
                form.new_password.data).decode("utf-8")
        if form.upload.data:
            current_user.image_url = save_image(form.upload.data)
        db.session.commit()
        return redirect(url_for("show_profile",
                                username=current_user.username))
    return render_template("users/update.html", form=form)
Exemple #3
0
def update(user_id):
    # loc = request.accept_languages.best_match(app.config['LANGUAGES'])
    loc = 'es'
    if loc == 'es':
        return redirect(url_for('profile_es', user_id=current_user.id))
    title = current_user.first_name + "Update Profile"
    form = UpdateProfileForm()
    if form.validate_on_submit():
        current_user.first_name = form.first_name.data
        current_user.email = form.email.data
        current_user.dob = form.dob.data
        db.session.commit()
        return redirect(url_for('profile', user_id=current_user.id))
    return render_template('update.html', title=title, form=form)
Exemple #4
0
def updateprofile():
    if current_user.is_authenticated:
        form = UpdateProfileForm()

        if form.validate_on_submit():
            user = current_user
            user.set_display_name(form.display_name.data)
            user.set_bio(form.bio.data)
            user.set_dob(form.dob.data)
            db.session.commit()
            flash('Profile Updated!')
            return redirect(url_for('myprofile'))
        return render_template('updateprofile.html',
                               title='My Profile',
                               form=form)
    return redirect(url_for('index'))
Exemple #5
0
def profile(username):
    form = UpdateProfileForm()
    image_file = url_for('static',
                         filename='images/profile/' + current_user.image)
    return render_template('profile.html',
                           title='profile',
                           image_file=image_file,
                           form=form)
Exemple #6
0
def profile():
    form = UpdateProfileForm()
    if request.method == 'POST' and form.validate_on_submit():
        current_user.firstname = form.fname.data
        current_user.lastname = form.lname.data
        current_user.email = form.email.data
        db.session.commit()
        flash("Account successfully updated","success")
        return redirect(url_for('user.profile'))

    elif request.method == 'GET':
        form.fname.data =  current_user.firstname
        form.lname.data =  current_user.lastname
        form.uname.data =  current_user.username
        form.email.data =  current_user.email

    default_profile_img = url_for('static', filename='images/default_profile.jpg')
    return render_template("user_bp/profile.html",
     image_file = default_profile_img, form=form)
Exemple #7
0
def profile():
    form = UpdateProfileForm()
    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(f'Your profile has been updated!', 'success')
        return redirect(url_for('profile'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
    image_file = url_for('static',
                         filename=f'profile_pics/{current_user.image_file}')
    return render_template('profile.html',
                           title='Profile',
                           image_file=image_file,
                           form=form)
Exemple #8
0
def profile():
    form = UpdateProfileForm()
    if form.validate_on_submit():
        current_user.temp = form.temp.data
        current_user.screen = form.screen.data
        current_user.room = form.room.data
        current_user.hours = form.hours.data
        current_user.work_minutes = form.work_minutes.data
        current_user.pause_minutes = form.pause_minutes.data
        db.session.commit()
        flash('Your preferences has been updated!', 'success')
        return redirect(url_for('profile'))
    elif request.method == 'GET':
        form.temp.data = current_user.temp
        form.screen.data = current_user.screen
        form.room.data = current_user.room
        form.hours.data = current_user.hours
        form.work_minutes.data = current_user.work_minutes
        form.pause_minutes.data = current_user.pause_minutes
    return render_template('profile.html', title="Profile", form=form)
Exemple #9
0
def profile():
    """
    function to display and update user profile
    """
    posts = Post.query.filter_by(user_id=current_user.id)

    form = UpdateProfileForm()
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.email = form.email.data

        db.session.commit()
        flash('Your changes have been saved.', 'success')
        return redirect(url_for('.profile'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email

    return render_template('profile.html',
                           title='Edit Profile',
                           form=form,
                           posts=posts)
Exemple #10
0
def update_profile(request):
    user = request.user
    form = UpdateProfileForm(instance=user)

    if request.method == 'POST':
        form = UpdateProfileForm(request.POST, request.FILES, instance=user)
        if form.is_valid():
            form.save()


    context = {'form': form}
    return render(request, 'app/update_profileview.html', context)
Exemple #11
0
def admin_manage_user(user_id):
	user_to_manage = Users.query.filter_by(id=user_id).first()
	
	form = UpdateProfileForm()
	
	
	if form.validate_on_submit():
		if form.password.data == form.password_validate.data:
			update_user_profile = UpdateUserProfile(form.first_name.data, form.last_name.data, form.email.data, form.password.data, 
														form.password_validate.data, form.about_me.data, user_to_manage)
														
			update_user_profile.update()
			
			flash("User updated succesfully!")
			return redirect(url_for("admin_manage_users"))
			
		else:
			flash("Error: The passwords do not match.")	
		
		
	
	# Set form default values from the user's current information
	
	form.first_name.default = user_to_manage.first_name
	form.last_name.default = user_to_manage.last_name
	form.email.default = user_to_manage.email 
	form.about_me.default = user_to_manage.about
	
	# Set form default values form the user's current information
	
	
	form.about_me.label = "About" # Set this label to something more appropriate for admins
	
	form.process()
	
	
	
	return render_template("admin/manage_user.html", user=user_to_manage, form=form)
Exemple #12
0
def edit_profile():
    form = UpdateProfileForm()
    form.username.data = current_user.username
    form.email.data = current_user.email
    return render_template("users/update.html", form=form)