Beispiel #1
0
def reqister():
    form = RegisterForm()
    if form.validate_on_submit():
        if session.query(User).filter(User.email == form.email.data).first():
            return render_template(
                'register.html',
                title='Регистрация',
                form=form,
                message="Пользователь с таким email уже есть!")
        if session.query(User).filter(User.phone == form.phone.data).first():
            if form.phone.data:
                return render_template(
                    'register.html',
                    title="Регистрация",
                    form=form,
                    message="Пользователь с таким номером телефона уже есть!")
        user = User(surname=form.surname.data,
                    name=form.name.data,
                    age=form.age.data,
                    is_realtor=form.is_realtor.data,
                    email=form.email.data)
        if form.phone.data:
            user.phone = form.phone.data
        print(form.password.data)
        user.set_password(form.password.data)
        session.add(user)
        session.commit()
        return redirect('/login')
    return render_template('register.html', title='Регистрация', form=form)
Beispiel #2
0
def reqister():
    form = RegisterForm()
    if form.validate_on_submit():
        if form.password.data != form.password_again.data:
            return render_template('register.html', title='Register Form',
                                   form=form,
                                   message="Пароли не совпадают")
        session = db_session.create_session()
        if session.query(users.User).filter(users.User.email == form.email.data).first():
            return render_template('register.html', title='Register Form',
                                   form=form,
                                   message="Такой пользователь уже есть")
        user = users.User(
            email=form.email.data,
            surname=form.surname.data,
            name=form.name.data,
            age=form.age.data,
            position=form.position.data,
            speciality=form.speciality.data,
            address=form.address.data,
        )
        user.set_password(form.password.data)
        session.add(user)
        session.commit()
        return jsonify({'status': 'ok'})
    return render_template('register.html', title='Register Form', form=form)
Beispiel #3
0
def reqister():
    form = RegisterForm()
    if form.validate_on_submit():
        if form.password.data != form.r_password.data:
            return render_template('register.html',
                                   title='Регистрация',
                                   form=form,
                                   message="Пароли не совпадают")
        if session.query(User).filter(User.email == form.email.data).first():
            return render_template('register.html',
                                   title='Регистрация',
                                   form=form,
                                   message="Такой пользователь уже есть")
        user = User(surname=form.surname.data,
                    name=form.name.data,
                    age=form.age.data,
                    position=form.position.data,
                    speciality=form.speciality.data,
                    address=form.address.data,
                    email=form.email.data)
        user.set_password(form.password.data)
        session.add(user)
        session.commit()
        return redirect('/login')
    return render_template('register.html', title='Регистрация', form=form)
Beispiel #4
0
def change_user(id):
    form = RegisterForm()
    if request.method == 'GET':
        user = session.query(User).filter(User.id == id).first()
        if user:
            form.surname.data = user.surname
            form.name.data = user.name
            form.age.data = user.age
            form.is_realtor.data = user.is_realtor
            form.email.data = user.email
            form.phone.data = user.phone
        else:
            abort(404)
    if form.validate_on_submit():
        user = session.query(User).filter(User.id == id).first()
        if user:
            user.surname = form.surname.data
            user.name = form.name.data
            user.age = form.age.data
            user.is_realtor = form.is_realtor.data
            user.email = form.email.data
            user.phone = form.phone.data
            user.set_password(form.password.data)
            return redirect('/')
        else:
            abort(404)
    return render_template('/register.html',
                           title="Редактирование пользователя",
                           form=form)
Beispiel #5
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        db_session.global_init('db/blogs.sqlite')
        if len(form.password.data) < 8:
            return render_template('register.html',
                                   title='Регистрация',
                                   form=form,
                                   message="Короткий пароль!")
        if 'qwerty' in form.password.data:
            return render_template(
                'register.html',
                title='Регистрация',
                form=form,
                message="Пароль содержит всем известную комбинацию 'qwerty'!")
        if form.password.data != form.password_again.data:
            return render_template('register.html',
                                   title='Регистрация',
                                   form=form,
                                   message="Пароли не совпадают")
        sessions = db_session.create_session()
        if sessions.query(users.User).filter(
                users.User.email == form.email.data).first():
            return render_template('register.html',
                                   title='Регистрация',
                                   form=form,
                                   message="Такой пользователь уже есть")
        user = users.User(name=form.name.data,
                          email=form.email.data,
                          password=form.password.data)
        user.set_password(form.password.data)
        sessions.add(user)
        sessions.commit()
        return redirect('/login')
    return render_template('register.html', title='Регистрация', form=form)
Beispiel #6
0
def main():
    db_session.global_init('db/blogs.sqlite')
    form = RegisterForm()
    if form.validate_on_submit():
        if form.password.data != form.password_again.data:
            return render_template('register_form.html',
                                   form=form,
                                   message="Пароли не совпадают")
        session = db_session.create_session()
        if session.query(User).filter(User.email == form.email.data).first():
            return render_template('register_form.html',
                                   form=form,
                                   message="Такой колонист уже есть")
        user = User(
            address=form.address.data,
            speciality=form.speciality.data,
            position=form.position.data,
            age=form.age.data,
            surname=form.surname.data,
            name=form.name.data,
            email=form.email.data,
        )
        user.set_password(form.password.data)
        session.add(user)
        session.commit()
        return redirect('/success')
    return render_template('register_form.html', form=form)
Beispiel #7
0
def signup():
    form = RegisterForm()
    if form.validate_on_submit():
        hashed_passwd = generate_password_hash(form.password.data,
                                               method='sha256')
        new_user = User(username=form.username.data,
                        email=form.email.data,
                        password=hashed_passwd)
        db.session.add(new_user)
        db.session.commit()
        return '<h1> user has been created!</h1>'
    return render_template('signup.html', form=form)
def register(request):
    form = RegisterForm(request.POST)

    if request.method == 'POST' and form.validate():
        login = form.login.data
        password = form.password.data
        password2 = form.password2.data
        model = User(login=login, password=password)
        DBSession.add(model)
        DBSession.flush()
        headers = remember(request, model.id)
        return HTTPFound(
            location='/welcome',
            headers=headers
        )

    return dict(
        form=form,
    )
def register():
    form = RegisterForm(request.form)
    if request.method == 'POST' and form.validate():
        name = form.name.data
        username = form.username.data
        email = form.email.data
        password = sha256_crypt.hash(str(form.password.data))

        client = MongoClient('localhost', 27017)
        collection = client['flaskblogdb']['flaskblog']
        doc = {
            'name': name,
            'username': username,
            'email': email,
            'password': password
        }
        collection.insert_one(doc)

        flash(message='User created successfully', category='success')
        return redirect(url_for('home'))

    return render_template('register.html', form=form)