예제 #1
0
def user(database, company):
    user = UserEntity(email='*****@*****.**', company_id=company.id)

    user.hash_password('password')
    database.add(user)
    database.commit()
    return user
예제 #2
0
def is_user_logged():
    if 'X-Token' in request.headers:
        token = request.headers['X-Token']
    elif 'token' in request.cookies:
        token = request.cookies.get('token')
    elif request.content_type == 'application/json':
        token = request.json.get('token')
    else:
        logging.debug("No token provided!")
        return None
    if not token:
        logging.debug("No authentication was supplied")
        abort(401, 'Please supply authentication')

    user = UserEntity.verify_auth_token(token)
    return user
    def test_user_services(self):
        company = CompanyEntity(name='alese.it', domain='alese.it')
        user = UserEntity(email='*****@*****.**', company_id=1)
        db_session.add(company)
        db_session.add(user)
        db_session.commit()

        company = services.company.get_for_domain('alese.it')

        assert company.domain == 'alese.it'

        user = services.user.get_by_email('*****@*****.**')
        assert user.email == '*****@*****.**'

        token = services.user.generate_auth_token(user)
        assert services.user.verify_token(token)
예제 #4
0
def get_by_email(email):
    user = UserEntity.get_user_by_email(email)
    return User.from_model(user)
예제 #5
0
def verify_token(token):
    user = UserEntity.verify_auth_token(token)
    return User.from_model(user)