Пример #1
0
def create_user(email=EXAMPLE_EMAIL, password=EXAMPLE_PASSWORD):
    user = User.create(email, password)
    # store = Store(name=STORE_NAME, user=user)
    # db.session.add(store)
    db.session.add(user)
    db.session.commit()
    return user
Пример #2
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
Пример #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
Пример #4
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
Пример #5
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)