Beispiel #1
0
def test_update_user_change_title_and_password(app):
    with app.app_context():
        user_service = UserService(app)
        user = User()
        user.login = '******'
        user.password = '******'
        user.title = 'First title'
        user = user_service.create(user)
        new_title = 'Test title!'
        new_password = '******'
        updated_user = user_service.update(user.id, {
            'title': new_title,
            'password': new_password
        })
        assert updated_user.title == new_title
        assert user_service.check_password_hash(user.password, new_password)
Beispiel #2
0
def render_login_page():
    login_form = LoginForm()
    if request.method == 'POST' and login_form.validate_on_submit():
        login = login_form.email.data
        password = login_form.password.data
        remember = login_form.remember.data

        user_service = UserService(current_app)
        registered_user = user_service.get_by_login(login)
        if registered_user is not None:
            if user_service.check_password_hash(registered_user.password,
                                                password):
                login_user(registered_user, remember=remember)
                return redirect('/')

    # return render_template("user/login.html", form=login_form)
    return (WebSiteHtmlView("main_blocks/main_template.html").set_title(
        'Вход на сайт').set_content('user/login.html').render(form=login_form))
Beispiel #3
0
def test_create_user_and_login(app):
    with app.test_request_context():
        # Create the user first with a given login and password
        user_service = UserService(app)
        user = User()
        user.login = '******'
        user.password = '******'
        user.title = 'Test user'
        created_user = user_service.create(entity=user)
        assert created_user.id is not None

        # Now get this user by its ID
        user_from_db = user_service.get_by_login(login='******')
        assert user_from_db is not None
        assert user_from_db.title == 'Test user'

        # Compare passwords and login user in case everything is ok
        assert user_service.check_password_hash(
            hash_to_check=user_from_db.password, password_to_check='pwd111')
        login_user(user=user_from_db, remember=False)
        assert current_user.id == user_from_db.id