コード例 #1
0
ファイル: routes.py プロジェクト: vdng/BDD_SNCF
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = RegistrationForm()
    if request.method == 'POST':

        if form.validate_on_submit():
            user = Client(pseudo=form.pseudo.data,
                          nom=form.nom.data,
                          prenom=form.prenom.data,
                          age=form.age.data,
                          argent=300)
            user.set_password(form.password.data)
            db.session.add(user)
            db.session.commit()
            flash('Félicitations, vous avez créer votre compte !', 'info')
            current_app.logger.info('redirect')
            return redirect(url_for('auth.login'))
        else:
            current_app.logger.error('Erreur de formulaire')

    current_app.logger.info('render_template')
    return render_template('auth/register.html',
                           title='Créer son compte',
                           form=form)
コード例 #2
0
def client_register():
    form = ClientRegistrationForm()
    if form.validate_on_submit():
        client = Client(username=form.username.data,
                        email=form.email.data,
                        name=form.name.data)
        client.set_password(form.password.data)
        db.session.add(client)
        db.session.commit()
        flash('Congratulations, you are now a registered user!')
        return redirect(url_for('client_login'))
    return render_template('client/register.html', title='Register', form=form)
コード例 #3
0
ファイル: routes.py プロジェクト: botasDEV/Projeto_3
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        client = Client(name=form.name.data,
                        username=form.username.data,
                        email=form.email.data)
        client.set_password(form.password.data)
        db.session.add(client)
        db.session.commit()
        flash('Congratulations, you are now a registered user!')
        return redirect(url_for('login'))
    return render_template('register.html', form=form)
コード例 #4
0
ファイル: routes.py プロジェクト: vdng/BDD_SNCF
def create_admin():
    has_admin = Client.query.filter_by(admin=True).first()
    if has_admin:
        flash('Un admin existe déjà !', 'info')
    else:
        admin = Client(pseudo='admin',
                       nom='admin',
                       prenom='admin',
                       age=99,
                       argent=0,
                       admin=True)
        admin.set_password('admin')
        db.session.add(admin)
        db.session.commit()
        flash('Vous venez de créer un admin !', 'success')
    return redirect(url_for('edit.edit_index'))
コード例 #5
0
ファイル: routes.py プロジェクト: sogreshilin/Edu.Database
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        category = ClientCategory.query.filter_by(
            name=form.category.data).first()
        client = Client(category=category,
                        first_name=form.first_name.data,
                        last_name=form.last_name.data,
                        phone_number=form.phone_number.data,
                        email=form.email.data)
        client.set_password(form.password.data)
        db.session.add(client)
        db.session.commit()
        flash(_('Congratulations, you are now a registered user!'))
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', title='Register', form=form)
コード例 #6
0
def post_auth():
    if current_user.is_authenticated:
        return json.dumps({'state': 2}), 200, {
            'ContentType': 'application/json'
        }
    if not request.json or not 'clientInfo' in request.json:
        return json.dumps({'error': 'incorrect_params'}), 400, {
            'ContentType': 'application/json'
        }
    info = json.loads(request.json['clientInfo'])

    if Client.query.filter_by(mail=info['email']).first() is not None:
        return json.dumps({'state': 0}), 200, {
            'ContentType': 'application/json'
        }
    client = Client(login=info['name'], mail=info['email'], roleid=1)
    client.set_password(info['password'])
    db.session.add(client)
    db.session.commit()
    return json.dumps({'state': 1}), 200, {'ContentType': 'application/json'}