Esempio n. 1
0
def register():
    """
    Route pour enregistrer un nouvel utilisateur
    """
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        actor = Actor(actor_name=form.actor_name.data,
                      email=form.email.data,
                      phone=form.phone.data,
                      manufacturer=form.manufacturer.data)
        actor.set_password(form.password.data)
        db.session.add(actor)
        db.session.flush(
        )  # pour obtenir l'identifiant de l'acteur qui vient d'être ajouté

        adress = Adress(street=form.street.data,
                        city=form.city.data,
                        state=form.state.data,
                        zip_code=form.zip_code.data,
                        country=form.country.data,
                        id=actor.id)
        db.session.add(adress)
        db.session.commit()
        flash('Félicitations, vous êtes maintenant inscrit ✅')

        global manufacturer
        if actor.manufacturer != 1:
            manufacturer = False
        else:
            manufacturer = True

        login_user(actor, remember=True)

        return redirect(url_for('index'))
    return render_template('register.html', title='Register', form=form)
Esempio n. 2
0
def register():
    """
    Route to register a new user
    """
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        actor = Actor(actor_name=form.actor_name.data,
                      email=form.email.data,
                      phone=form.phone.data,
                      manufacturer=form.manufacturer.data)
        actor.set_password(form.password.data)
        db.session.add(actor)
        db.session.flush()  # to get the id of the actor just added

        adress = Adress(street=form.street.data,
                        city=form.city.data,
                        state=form.state.data,
                        zip_code=form.zip_code.data,
                        country=form.country.data,
                        id=actor.id)
        db.session.add(adress)
        db.session.commit()
        flash('Congratulations, you are now registered!')

        global manufacturer
        if actor.manufacturer != 1:
            manufacturer = False
        else:
            manufacturer = True

        login_user(actor, remember=True)

        return redirect(url_for('index'))
    return render_template('register.html', title='Register', form=form)