Esempio n. 1
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    settings['sqlalchemy.url'] = settings['cn.dialect'] + quote_plus(settings['sqlalchemy.url'])
    engine = engine_from_config(settings, 'sqlalchemy.')
    dbConfig['url'] = settings['sqlalchemy.url']
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    Base.metadata.create_all(engine)
    Base.metadata.reflect(views=True, extend_existing=False)

    config = Configurator(settings=settings)
    # Add renderer for datetime objects
    json_renderer = JSON()
    json_renderer.add_adapter(datetime, datetime_adapter)
    json_renderer.add_adapter(Decimal, decimal_adapter)
    config.add_renderer('json', json_renderer)

    # Set up authentication and authorization
    includeme(config)
    config.set_root_factory(SecurityRoot)


    # Set the default permission level to 'read'
    config.set_default_permission('read')
    config.include('pyramid_tm')
    add_routes(config)
    config.scan()
    return config.make_wsgi_app()
Esempio n. 2
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    settings['sqlalchemy.url'] = settings['cn.dialect'] + quote_plus(
        settings['sqlalchemy.url'])
    engine = engine_from_config(settings, 'sqlalchemy.')
    dbConfig['url'] = settings['sqlalchemy.url']
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    Base.metadata.create_all(engine)
    Base.metadata.reflect(views=True, extend_existing=False)

    config = Configurator(settings=settings)
    # Add renderer for datetime objects
    json_renderer = JSON()
    json_renderer.add_adapter(datetime, datetime_adapter)
    json_renderer.add_adapter(Decimal, decimal_adapter)
    config.add_renderer('json', json_renderer)

    # Set up authentication and authorization
    includeme(config)
    config.set_root_factory(SecurityRoot)

    # Set the default permission level to 'read'
    config.set_default_permission('read')
    config.include('pyramid_tm')
    add_routes(config)
    config.scan()
    return config.make_wsgi_app()
Esempio n. 3
0
def instance(request):
    table = Base.metadata.tables['VAllUsersApplications']
    query = select([
        table
    ]).where((table.c['TUse_PK_ID'] == request.authenticated_userid) & (table.c['TRol_Label'] != 'Interdit')).order_by(table.c['TIns_Order'])
    result = DBSession.execute(query).fetchall()
    return [dict(row) for row in result]
Esempio n. 4
0
def site(request):
    noimage = request.params.get('noimage')
    if(noimage):
        query = select([
        Site.Name.label('title'),
        Site.Country.label('country'),
        Site.Locality.label('locality'),
        Site.LongName.label('legend'),
        Site.UILabel.label('label')
        ]).where(Site.Name == dbConfig['siteName'])
    else :
       query = select([
        Site.Name.label('title'),
        Site.Country.label('country'),
        Site.Locality.label('locality'),
        Site.LongName.label('legend'),
        Site.ImageBackPortal.label('imgBackPortal'),
        Site.ImageLogoPortal.label('imgLogoPortal'),
        Site.BackgroundHomePage.label('imgBackHomePage'),
        Site.UILabel.label('label')
        ]).where(Site.Name == dbConfig['siteName']) 
    result = DBSession.execute(query).fetchone()
    print('*************************')
    #print(dict(result))
    return dict(result)
Esempio n. 5
0
def users(request):
    """Return the list of all the users with their ids.
    """
    query = select([
        User.id.label('PK_id'),
        User.Login.label('fullname')
    ]).where(User.HasAccess == True).order_by(User.Lastname, User.Firstname)
    return [dict(row) for row in DBSession.execute(query).fetchall()]
Esempio n. 6
0
def users(request):
    """Return the list of all the users with their ids.
    """
    query = select([User.id.label('PK_id'),
                    User.Login.label('fullname')
                    ]).where(User.HasAccess == True).order_by(
                        User.Lastname, User.Firstname)
    return [dict(row) for row in DBSession.execute(query).fetchall()]
Esempio n. 7
0
def current_user(request):
    """Return the list of all the users with their ids.
    """
    query = select([User.id.label('PK_id'),
                    User.Login.label('fullname')
                    ]).where(User.id == request.authenticated_userid)
    print
    return dict(DBSession.execute(query).fetchone())
Esempio n. 8
0
def current_user(request):
    """Return the list of all the users with their ids.
    """
    query = select([
        User.id.label('PK_id'),
        User.Login.label('fullname')
    ]).where(User.id == request.authenticated_userid)
    return dict(DBSession.execute(query).fetchone())
Esempio n. 9
0
def site(request):
    query = select([
        Site.Name.label('title'),
        Site.Country.label('country'),
        Site.Locality.label('locality'),
        Site.LongName.label('legend'),
        Site.ImageBackPortal.label('imgBackPortal'),
        Site.ImageLogoPortal.label('imgLogoPortal'),
        Site.BackgroundHomePage.label('imgBackHomePage'),
        Site.UILabel.label('label')
    ]).where(Site.Name == dbConfig['siteName'])
    result = DBSession.execute(query).fetchone()
    return dict(result)
Esempio n. 10
0
def login(request): 
    user_id = request.POST.get('user_id', '')
    pwd = request.POST.get('password', '')
    user = DBSession.query(User).filter(User.id==user_id).one()
    if user is not None and user.check_password(pwd):
        claims = {
            "iss": user_id,
        }
        jwt = make_jwt(request, claims)
        response = Response(body='login success', content_type='text/plain')
        remember(response, jwt)
        transaction.commit()
        return response
    else:
        transaction.commit()
        return HTTPUnauthorized()
Esempio n. 11
0
def login(request):
    user_id = request.POST.get('user_id', '')
    pwd = request.POST.get('password', '')
    user = DBSession.query(User).filter(User.id == user_id).one()
    if user is not None and user.check_password(pwd):
        claims = {
            "iss": user_id,
        }
        jwt = make_jwt(request, claims)
        response = Response(body='login success', content_type='text/plain')
        remember(response, jwt)
        transaction.commit()
        return response
    else:
        transaction.commit()
        return HTTPUnauthorized()
Esempio n. 12
0
def role_loader(user_id, request):
    result = DBSession.query(User.Role).filter(User.id==user_id).one()
    transaction.commit()
    return result
Esempio n. 13
0
def role_loader(user_id, request):
    result = DBSession.query(User.Role).filter(User.id == user_id).one()
    transaction.commit()
    return result