Exemplo n.º 1
0
def test_find_user_id(user):
    # given
    # execute
    user_result = User.find(id_=user.id)

    # expect
    assert user_result
    assert user.id == user_result.id
    assert user.name == user_result.name
    assert user.password == user_result.password
Exemplo n.º 2
0
    def post(cls):
        data = cls.parser.parse_args()

        user = User.find(name=data["username"])

        if user and safe_str_cmp(data["password"], user.password):
            access_token = create_access_token(identity=user.id, fresh=True)
            refresh_token = create_refresh_token(user.id)

            return {
                "access_token": access_token,
                "refresh_token": refresh_token
            }, 200

        return {"message": "Invalid credentials"}, 401
Exemplo n.º 3
0
def test_create_user(db):
    # given
    name = "bob"
    password = "******"

    user = User(name=name, password=password)

    # execute
    user.save()

    # expect
    user_result = User.find(name=name)

    assert user_result
    assert name == user_result.name
    assert password == user_result.password
Exemplo n.º 4
0
def authenticate(user_name, password):
    user = User.find(name=user_name)
    if user and safe_str_cmp(user.password, password):
        return user
Exemplo n.º 5
0
def identity(payload):
    id = payload['identity']
    return User.find(id_=id)