Пример #1
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        email = form.email.data
        username = form.username.data

        user = User(email=email, username=username)
        user.password = form.password.data

        company = Company()
        company.name = form.company.data

        db.session.add(user)
        db.session.add(company)

        company.set_company_owner(user)
        company.add_user(user)

        db.session.commit()
        company.company_materials_setup()

        db.session.commit()
        token = user.generate_confirmation_token()
        send_email(
            user.email,
            "Confirm Your Account",
            "auth/email/confirm",
            user=user,
            token=token,
        )
        flash("A confirmation email has been sent to you by email.")
        return redirect(url_for("auth.login"))
    return render_template("auth/register.html", form=form)
Пример #2
0
def test_company_owner(clean_db):
    name = "Test Company"
    company = Company()
    company.name = name

    user1 = User()
    user1.username = "******"

    db.session.add(user1)
    db.session.add(company)

    company.set_company_owner(user1)
    db.session.commit()

    db_company = Company.query.filter_by(name=name).first()

    assert user1 == db_company.owner
Пример #3
0
def sample_data():
    set_up()

    user1 = User(username="******",
                 email="*****@*****.**",
                 password="******",
                 confirmed=True)
    user2 = User(username="******",
                 email="*****@*****.**",
                 password="******",
                 confirmed=True)
    user3 = User(username="******",
                 email="*****@*****.**",
                 password="******",
                 confirmed=True)
    user4 = User(username="******",
                 email="*****@*****.**",
                 password="******",
                 confirmed=True)

    company1 = Company(name="ExampleCompanyOne.com")
    company2 = Company(name="ExampleCompanyTwo.com")

    db.session.add(user1)
    db.session.add(user2)
    db.session.add(user3)
    db.session.add(user4)

    company1.add_user(user1)
    company1.add_user(user2)
    company1.set_company_owner(user1)
    company1.add_asset("company1_asset")
    db.session.add(company1)

    company2.add_user(user3)
    company2.add_user(user4)
    company2.set_company_owner(user3)
    company2.add_asset("company2_asset")
    db.session.add(company2)

    db.session.commit()
    company1.company_materials_setup()
    company2.company_materials_setup()
    db.session.commit()