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

        try:
            current_user.save()
            flash(f'Account update.', 'success')
            return redirect(url_for('account'))
        except:
            flash(f'username and/or email is taken.', 'danger')

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

    image_file = url_for('static',
                         filename='images/profile_pictures/' +
                         current_user.image_file,
                         _external=True)

    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
        current_user.university = form.university.data
        current_user.major = form.major.data
        current_user.interest1 = form.interest1.data
        current_user.interest2 = form.interest2.data
        db.session.commit()
        flash('账户更新成功!', 'success')
        return redirect(url_for('account'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
        form.university.data = current_user.university
        form.major.data = current_user.major
        form.interest1.data = current_user.interest1
        form.interest2.data = current_user.interest2
    image_file = url_for('static', filename='profile_pics/' + current_user.image_file)
    return render_template('account.html', title='账户信息',
                           image_file=image_file, form=form)
Example #3
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
        enroll = Enroll(user_id=int(current_user.id),
                        class_number=form.class_number.data)
        db.session.add(enroll)
        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
    else:
        flash('Invalid form submission! Please check inputs.', 'danger')

    enrolls = Enroll.query.filter_by(user_id=int(current_user.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,
                           enrolls=enrolls)
Example #4
0
def account():
    global pid
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            delete_picture(current_user.image_file)
            current_user.image_file = picture_file
        current_user.username = form.username.data
        current_user.email = form.email.data
        current_user.zipcode = form.zipcode.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.zipcode.data = current_user.zipcode
        pid = current_user.id
        print("Current User ID: ", current_user.id)
    children = find_child(current_user.id)
    image_file = url_for('static', filename='img/' + current_user.image_file)
    return render_template(
        "public/account.html",
        title="Account",
        image_file=image_file,
        children=children,
        form=form,
    )
Example #5
0
def update():
    
    form = UpdateAccountForm()
    
    if request.method == 'POST':
        #we're going to populate this field with the action that must
        #happened whe the form is submitted
        #current_user = User.objects(id=session.get('USER'))
        id = session["USER"]
       
        user = find_id(id)
       
        if user['age'] != "" and user['bio'] != "":
            return redirect(url_for('profile'))
        else:
            if form.validate_on_submit():

                age_update(form,id)
                bio_update(form,id)
                gender_update(form,id)
                sexualPreference_update(form,id)
                registered_update(id)
                interest_update(form,id)
               
            return redirect(url_for('profile'))
    else:
        return render_template('public/update_profile.html',form=form)
Example #6
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')

        # current_user.password = hashed_password
        current_user.email = form.email.data
        current_user.cep  = form.cep.data
        current_user.place  = form.place.data
        current_user.address = form.residence_address.data
        current_user.neighborhood = form.neighborhood.data
        current_user.city = form.city.data
        current_user.state = form.state.data
        current_user.phone_1 = form.phone_1.data
        current_user.phone_2 = form.phone_2.data
        db.session.commit()
        flash('Sua conta foi atualizada com sucesso!', category='success')
        return redirect(url_for('account'))
    elif request.method == 'GET':
        # print('Não valido')
        form.email.data = current_user.email
        form.cep.data = current_user.cep
        form.place.data = current_user.place
        form.residence_address.data = current_user.address
        form.neighborhood.data = current_user.neighborhood
        form.city.data = current_user.city
        form.state.data = str(current_user.state)
        form.phone_1.data = current_user.phone_1
        form.phone_2.data = current_user.phone_2
        # form.specialty.data = str(current_user.specialties[0].specialty)
    return render_template("account.html", title="Atualizar informações - TeleEspecialista", form=form)
Example #7
0
def account():
    form = UpdateAccountForm()
    image_file = url_for('static',
                         filename='profile_pics/' + current_user.image_file)
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.email = form.email.data
        current_user.age = form.age.data
        current_user.state = form.state.data
        current_user.personality = form.personality.data
        current_user.education = form.education.data
        current_user.height = form.height.data
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file
        db.session.commit()
        flash('Your setting 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.age.data = current_user.age
        form.state.data = current_user.state
        form.personality.data = current_user.personality
        form.education.data = current_user.education
        form.height.data = current_user.height

    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():
        if form.picture.data:
            picture_file = save_picture(form.picture.data, 'profile_pics')
            current_user.image_file = picture_file
        current_user.username = form.username.data
        current_user.email = form.email.data
        current_user.about_me = form.about_me.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.about_me.data = current_user.about_me
    image_file = url_for('static',
                         filename='profile_pics/' + current_user.image_file)

    page = request.args.get('page', 1, type=int)
    per_page = app.config['POSTS_PER_PAGE']
    user = User.query.filter_by(username=current_user.username).first_or_404()
    posts = Recipe.query.filter_by(author=current_user)\
        .order_by(Recipe.timestamp.desc())\
        .paginate(page=page, per_page=per_page)
    return render_template('account.html',
                           title='Account',
                           image_file=image_file,
                           form=form,
                           posts=posts,
                           user=user)
Example #9
0
def account():
    form = UpdateAccountForm()
    if current_user.is_admin and not request.args.get("user") == None:
        userid = request.args.get("user")
        user = User.query.get(int(userid))
    else:
        user = current_user
    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()
        return redirect(url_for('account'))
    elif request.method == 'GET':
        form.username.data = user.username
        form.email.data = user.email
    if not user.image_file is None:
        image_file = url_for('static',
                             filename='profile_pics/' + user.image_file)
    else:
        image_file = None
    return render_template('account.html',
                           title='Account',
                           image_file=image_file,
                           form=form,
                           user=user)
Example #10
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            old_picture_fn = current_user.image_file
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file
            # remove old profile picture
            if old_picture_fn != "default.png":
                old_picture_path = os.path.join(app.root_path,
                                                'static/users/profile_pics',
                                                old_picture_fn)
                os.remove(old_picture_path)
        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='users/profile_pics/' +
                         current_user.image_file)
    return render_template('account.html', form=form, image_file=image_file)
Example #11
0
def account():
    form = UpdateAccountForm()  # Form från forms.py
    if form.validate_on_submit():  # OM SubmitField klickas, kör nedan
        current_user.email = form.email.data  # Skriver över current_user.email med det som användaren skrivit in i UpdateAccountForm()
        db.session.commit()
        flash('Din email har uppdaterats', 'success')
        return redirect(url_for('account'))
    elif request.method == 'GET':
        form.email.data = current_user.email
    return render_template('account.html', title='Account', form=form)
Example #12
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        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.email.data = current_user.email
    return render_template('account.html', title='Account', form=form)
Example #13
0
def account():
	form = UpdateAccountForm()
	if form.validate_on_submit():
		if bcrypt.check_password_hash(current_user.password, form.old_password.data):
			new_hashed_password = bcrypt.generate_password_hash(form.new_password.data).decode('utf-8')
			current_user.password = new_hashed_password
			db.session.commit()
			flash('Your password has succecfully been updated', 'success')
			return redirect(url_for('home'))
		else:
			flash('Wrong password, try again', 'danger')
	return render_template('account.html', title='Account', form=form)
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        current_user.email = form.email.data
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        current_user.password = hashed_password
        db.session.commit()
        flash(f'Your account has been updated.', 'success')
        return redirect(url_for('account', title='Account'))
    elif request.method == 'GET':
        form.email.data = current_user.email
    return render_template('account.html', title='Account', form=form)
Example #15
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        picture_file = save_picture(form.picture.data)
        current_user.image_file = picture_file
        current_user.username = form.username.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
    image_file = url_for('static', filename='profile_pics/' + current_user.image_file)
    return render_template('account.html', image_file=image_file, form=form)
Example #16
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        current_user.first_name = form.first_name.data
        current_user.last_name = form.last_name.data
        current_user.email = form.email.data
        db.session.commit()
        return redirect(url_for('account'))
    elif request.method == 'GET':
        form.first_name.data = current_user.first_name
        form.last_name.data = current_user.last_name
        form.email.data = current_user.email
    return render_template('account.html', title='Account', form=form)
Example #17
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if bcrypt.check_password_hash(current_user.password, form.old_password.data):
            new_hashed_password = bcrypt.generate_password_hash(form.new_password.data).decode('utf-8')
            current_user.password = new_hashed_password
            db.session.commit()
            flash('Ditt lösenord har uppdaterats', 'success')
            return redirect(url_for('home'))
        else:
            flash('Fel lösenord angivet, försök igen', 'danger')
            return redirect(url_for('account'))
    return render_template('account.html', title='Konto', form=form)
Example #18
0
def account():
    form = UpdateAccountForm(obj=current_user)
    if request.method == 'POST' and 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'))
    image_file = url_for('static', filename='media/' + current_user.image_file)
    return render_template('account.html', image_file=image_file, form=form)
Example #19
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.user_key = form.user_key.data
        current_user.user_secret = form.user_secret.data
        db.session.commit()
        flash('Account Updated')
        return redirect(url_for('account'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.user_key.data = current_user.user_key

    return render_template('exemplum-account.html', title='Account', form=form)
Example #20
0
def account():
    form = UpdateAccountForm()
    #user = User (username=form.username.data, email_address=form.email_address.data)
    address = AccountAddress.query.filter_by(user_id=current_user.id).first()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file
        address = AccountAddress.query.filter_by(
            user_id=current_user.id).first()
        current_user.username = form.username.data
        current_user.email_address = form.email_address.data
        #address = AccountAddress(country=form.country.data, city = form.city.data, street = form.street.data,
        #postcode = form.postcode.data, user_id=current_user.id)

        if address is True:
            address.country = form.country.data
            address.city = form.city.data
            address.street = form.street.data
            address.postcode = form.postcode.data
        else:
            latest_address = AccountAddress(country=form.country.data,
                                            city=form.city.data,
                                            street=form.street.data,
                                            postcode=form.postcode.data,
                                            user_id=current_user.id)
            db.session.add(latest_address)
        db.session.commit()
        flash('Your account has been updated!', 'success')
        return redirect(url_for('account'))
    elif request.method == 'GET':
        address = AccountAddress.query.filter_by(
            user_id=current_user.id).first()
        form.username.data = current_user.username
        form.email_address.data = current_user.email_address
        if address:
            form.country.data = address.country
            form.city.data = address.city
            form.street.data = address.street
            form.postcode.data = address.postcode
        else:
            flash(f'no address here', 'danger')

    image_file = url_for('static',
                         filename='css/profile_pics/' +
                         current_user.image_file)
    return render_template('account.html',
                           title='Account',
                           image_file=image_file,
                           form=form)
Example #21
0
def update_info():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            delete_picture(current_user.image_file)
            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('update_info'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
    return render_template('account.html', title='Account', 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('You 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", form=form)
Example #23
0
def admin_account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.profile_pic = picture_file
        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash('Account info 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 = 'imgs/profile_pics/' + current_user.profile_pic)
    return render_template('admin/admin_account.html', title = current_user.username, profile_pic = image_file, form = form)
Example #24
0
def edit_profile():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.about = form.about.data
        db.session.commit()
        flash('Информация обновлена!', 'success')
        return redirect(url_for('my_profile'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.about.data = current_user.about
    return render_template('profile.html',
                           title='Account',
                           image_file=current_user.avatar(125),
                           image_file_small=current_user.avatar(32),
                           form=form)
Example #25
0
def user(username):

    page = request.args.get("page", 1, type=int)
    user = User.query.filter_by(username=username).first_or_404()
    total_posts = db.session.query(Post).filter_by(
        user_id=current_user.id).count()
    posts = Post.query.filter_by(author=user).order_by(
        Post.created_datetime.desc()).paginate(page=page, per_page=5)

    form = UpdateAccountForm()

    if form.validate_on_submit():

        current_user.username = form.username.data
        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.email = form.email.data

        db.session.commit()
        flash("Your Account Has Been Successfully Updated!", "success")

        return redirect(
            url_for("user",
                    username=username,
                    title="Account of {} {} {}".format(current_user.firstname,
                                                       current_user.middlename,
                                                       current_user.lastname)))

    elif request.method == "GET":

        form.username.data = current_user.username
        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.email.data = current_user.email

    return render_template("account.html",
                           user=user,
                           posts=posts,
                           total_posts=total_posts,
                           form=form,
                           title="Account of {} {} {}".format(
                               current_user.firstname, current_user.middlename,
                               current_user.lastname))
Example #26
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
    user = User.query.filter_by(username=current_user.username).first()
    user_token = user.token.decode('utf-8')
    return render_template('account.html',
                           title='Account',
                           form=form,
                           user_token=user_token)
def account():
    update_form = UpdateAccountForm()
    if update_form.validate_on_submit():
        current_user.username = update_form.username.data
        current_user.email = update_form.email.data
        db.session.commit()
        flash('Your account has been updated', category='success')
        # return here to avoid something
        return redirect(url_for('account'))
    elif request.method == "GET":
        update_form.username.data = current_user.username
        update_form.email.data = current_user.email
    image_file = url_for('static', filename=current_user.image_file)
    return render_template('account.html',
                           title='Account',
                           image_file=image_file,
                           form=update_form)
Example #28
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 #29
0
def account():
    form = UpdateAccountForm(obj=current_user)
    if request.method == 'POST' and not form.validate_on_submit():
        flash('Error while profile updating')
        return redirect(url_for('account'))
    if request.method == "POST" and 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('Profile updated successfully', 'success')
        return redirect(url_for('account'))

    image_file = url_for('static', filename='media/' + current_user.image_file)
    return render_template("account.html", image_file=image_file, form=form)
Example #30
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=f'profile_pics/{current_user.image_file}')
    return render_template('account.html',
                           title='Account',
                           image_file=image_file,
                           form=form)