Ejemplo n.º 1
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        if form.password.data != form.repeated_password.data:
            return render_template('register.html',
                                   form=form,
                                   error_message="Passwords don't match",
                                   title='Register')
        sess = db_session.create_session()
        if sess.query(Users).filter(Users.email == form.email.data).first():
            return render_template(
                'register.html',
                form=form,
                error_message='User with same email already exists',
                title='Register')
        if sess.query(Users).filter(Users.login == form.login.data).first():
            return render_template('register.html',
                                   form=form,
                                   error_message='User with same login exists',
                                   title='Register')
        user = Users()
        user.email = form.email.data
        user.login = form.login.data
        user.generate_password(form.password.data)
        user.creation_date = datetime.datetime.now()
        sess.add(user)
        sess.commit()
        login_user(user)
        return redirect('/')
    return render_template('register.html', form=form, title='Register')
Ejemplo n.º 2
0
def registration():
    form = RegistrationForm()
    if form.validate_on_submit():
        db_sess = db_session.create_session()

        if db_sess.query(Users).filter(Users.email == form.email.data).first():
            return render_template('registration.html', title='Registration', form=form,
                                   message='Такой пользователь уже зарегистрирован.')

        user = Users()
        user.email = form.email.data
        user.surname = form.surname.data
        user.name = form.name.data
        user.age = form.age.data
        user.position = form.position.data
        user.speciality = form.speciality.data
        user.address = form.address.data
        user.set_password(form.password_1.data)

        db_sess.add(user)
        db_sess.commit()

        login_user(user, remember=True)

        db_sess.close()

        return redirect('/')

    return render_template('registration.html', title='Registration', form=form)
Ejemplo n.º 3
0
 def add_data(form):
     session = create_session()
     user = Users()
     user.email = form.email.data
     user.name = form.name.data
     user.surname = form.surname.data
     user.password = hash_password(form.password.data)
     session.add(user)
     session.commit()