Example #1
0
def user_with_product():
    new_user = User.create("*****@*****.**", "pass")
    store = Store(name="Test Store", user=new_user)
    product = Product(name='Test Product',
                      description='a product',
                      store=store)
    db.session.add(product)
    db.session.commit()
    yield new_user
def create_store(name="Example Store", num_products=0):
    store = Store(name=name)
    for index in range(num_products):
        product = Product(name="Product {}".format(index),
                          description="example",
                          store=store)
        db.session.add(product)
    db.session.add(store)
    db.session.commit()
    return store
Example #3
0
def sample_book():
    new_user = User.create('*****@*****.**', 'examplepass')
    db.session.add(new_user)
    store = Store(name='Store Name', user=new_user)
    # db.session.add(store)
    book = Product(name="Sherlock Homes",
                   store=store,
                   description="A house hunting detective")
    db.session.add(book)
    db.session.commit()
    return book
Example #4
0
def setup():
    with app.app_context():
        db.create_all()
        user = User.create("*****@*****.**", "test")
        db.session.add(user)
        store = Store(name="The newline store", user=user)
        for i in range(2):
            prod = Product(name='Fullstack Book v{}'.format((1+i)),
                           description='Book #{} in the series'.format(i+1),
                           price_cents=100*(i+1),
                           store=store)
            db.session.add(prod)
        db.session.commit()
Example #5
0
def authenticated_request(client):
    new_user = User.create('*****@*****.**', 'examplepass')
    store = Store(name="Test Store", user=new_user)
    db.session.add(new_user)
    db.session.commit()

    response = client.post(url_for('user.login'),
                           data={
                               'email': '*****@*****.**',
                               'password': '******'
                           },
                           follow_redirects=True)
    yield client
Example #6
0
def register():
    if current_user.is_authenticated:
        flash('You are already logged in', 'warning')
        return redirect(url_for('products.index'))
    form = SignupForm()
    if form.validate_on_submit():
        # create a user
        user = User.create(form.email.data, form.password.data)
        db.session.add(user)
        store = Store(name=form.store_name.data,
                      user=user)  # may need another db.session.add(store)
        db.session.commit()
        login_user(user)
        send_welcome_message(user)
        flash("Registered successfully", "success")
        return redirect(url_for('products.index'))
    return render_template('users/register.html', form=form)
Example #7
0
def register():
    if current_user.is_authenticated:
        flash("You are already logged in", 'warning')
        return redirect(url_for("product.index"))

    form = SignupForm()
    if form.validate_on_submit():
        user = User.create(form.email.data, form.password.data)
        db.session.add(user)
        store = Store(name=form.store_name.data, user=user)
        db.session.add(store)
        db.session.commit()

        send_pretty_welcome_message(user)
        login_user(user)
        flash("Registered succesfully.", "success")
        return redirect(session.get('after_login') or url_for("product.index"))

    return render_template("users/register.html", form=form)