Beispiel #1
0
def get_app(global_config, **settings):
    ConfigurationWrapper.init('admin', **settings)

    config = Configurator(settings=settings)
    config.include('pyramid_jinja2')
    config.add_static_view('admin_sstatic', 'admin:static', cache_max_age=3600)
    config.add_static_view('core_static', 'core:static', cache_max_age=3600)
    config.add_route('index', '/')
    config.add_route('answers', '/answer')
    config.add_route('answer', '/answer/{answer_id}')
    config.add_route('forms', '/form')
    config.add_route('form', '/form/{form_id}')
    config.add_route('bindings', '/form/{form_id}/place')
    config.add_route('binding', '/form/{form_id}/place/{place_id}')
    config.add_route('place', 'place/{place_id}')
    config.add_route('user', '/user')
    config.add_route('user_permissions', '/permissions')
    config.scan()
    config.set_default_permission(Permissions.Auth)
    config.set_authentication_policy(CookieAuthenticationPolicy())
    config.set_authorization_policy(
        AuthorizationPolicy(ConfigurationWrapper.get_auth('admin')))
    """config.add_forbidden_view(lambda r: HTTPTemporaryRedirect('/admin'))"""
    config.add_notfound_view(lambda r: HTTPTemporaryRedirect('/admin'))
    return config.make_wsgi_app()
Beispiel #2
0
def load_user(request: Request) -> User:
    client = ApiClient(ConfigurationWrapper.get_auth('admin'))
    if not (hasattr(request, 'session') and request.session is not None):
        AuthorizationPolicy(ConfigurationWrapper.get_auth('admin')).authenticated_userid(request)
    if hasattr(request, 'session') and request.session is not None:
        result = client.users_client.load(request.session.user_id)
        if not result.is_success:
            logging.warning("Fail to load user for session '" + request.session.session_id + "': " + result.data.message)
            raise Exception(result.data)
        return result.data
    return None
Beispiel #3
0
 def put(self):
     form_id = self.request.matchdict.get('form_id')
     result = ApiClient(
         ConfigurationWrapper.get_auth('admin')).form_client.create_form(
             self.user.id, id=form_id)
     if not result.is_success:
         return {'user': self.user, 'error': result.data}
     return HTTPOkWithRedirect('/admin/form/' + form_id)
Beispiel #4
0
def get_app(global_config, **settings):
    ConfigurationWrapper.init('api', **settings)

    config = Configurator(settings=settings)
    config.include('api.auth_api', route_prefix='/auth')
    config.include('api.users_api', route_prefix='/users')
    config.include('api.permissions_api', route_prefix='/permissions')
    config.include('api.form_api', route_prefix='/form')
    config.include('api.places_api', route_prefix='/place')
    config.add_notfound_view(not_found_view)
    config.add_forbidden_view(forbidden_view)
    config.add_exception_view(exception_view)
    config.set_default_permission(Permissions.Auth)
    config.set_authentication_policy(HeaderAuthenticationPolicy())
    config.set_authorization_policy(
        AuthorizationPolicy(ConfigurationWrapper.get_auth('api')))
    return config.make_wsgi_app()
Beispiel #5
0
 def create(self):
     client = ApiClient(ConfigurationWrapper.get_auth('admin'))
     form_id = self.request.matchdict.get('form_id')
     place_id = self.request.matchdict.get('place_id')
     result = client.form_client.create_binding(form_id, place_id)
     if not result.is_success:
         return {'error': result.data, 'user': self.user}
     return HTTPOkWithRedirect('/admin/form/%s/place' % form_id)
Beispiel #6
0
 def delete(self):
     form_id = self.request.matchdict.get('form_id')
     result = ApiClient(ConfigurationWrapper.get_auth(
         'admin')).form_client.delete_form(form_id)
     if not result.is_success:
         logging.warning("Fail to delete form '%s': %s" %
                         (form_id, result.data.message))
     return HTTPOkWithRedirect('/admin/form')
Beispiel #7
0
def index(req: Request):
    client = ApiClient(ConfigurationWrapper.get_auth("map"))
    form = client.form_client.get_form(req.params.get("id"))
    place_id = client.form_client.get_form(req.params.get("place_id"))
    return {
        'inputs': json.loads(form.data.content),
        'place_id': place_id,
        'form_id': req.params.get("id")
    }
Beispiel #8
0
def get_app(global_config, **settings):
    ConfigurationWrapper.init('map', **settings)

    config = Configurator(settings=settings)
    config.include('pyramid_jinja2')
    config.add_static_view('map_static', 'map:static', cache_max_age=3600)
    config.add_static_view('core_static', 'core:static', cache_max_age=3600)
    config.add_route('index', '/')
    config.add_route('enter', '/enter')
    config.add_route('exit', '/exit')
    config.add_route('anketa', '/anketa')
    config.add_route('xXx_PRO100anketka228_xXx', '/xXx_PRO100anketka228_xXx')
    config.add_route('choose', '/choose')
    config.add_route('registration', '/registration')
    config.scan()
    config.add_notfound_view(lambda r: HTTPTemporaryRedirect('/'))
    config.set_default_permission(Permissions.Null)
    config.set_authentication_policy(CookieAuthenticationPolicy())
    config.set_authorization_policy(AuthorizationPolicy(ConfigurationWrapper.get_auth('map')))
    return config.make_wsgi_app()
Beispiel #9
0
 def edit(self):
     answer_id = self.request.matchdict.get('answer_id')
     answer = dict()
     for id in self.request.params:
         answer[id] = self.request.params[id]
     answer = json.dumps(answer)
     result = ApiClient(
         ConfigurationWrapper.get_auth('admin')).form_client.set_answer(
             answer_id, answer)
     if not result.is_success:
         return {'user': self.user, 'error': result.data}
     return self.get('Ответ записан')
Beispiel #10
0
 def register(self):
     login = self.request.params.get('login')
     email = self.request.params.get('email')
     new_password1 = self.request.params.get('new_password1')
     new_password2 = self.request.params.get('new_password2')
     if new_password1 != new_password2:
         return {'error': 'Пароли не совпадают'}
     client = ApiClient(ConfigurationWrapper.get_auth('map'))
     result = client.users_client.create(login, new_password1, email)
     if not result.is_success:
         return {'error': 'Логин занят'}
     return HTTPOkWithRedirect('/enter')
Beispiel #11
0
    def __call__(self):
        client = ApiClient(ConfigurationWrapper.get_auth('admin'))
        skip = int(self.request.params.get('skip', 0))
        take = int(self.request.params.get('take', 50000))
        result = client.permission_client.get_user_permissions  (self.user.id, skip, take)
        if not result.is_success:
            raise Exception(result.data)

        return {
            'user': self.user,
            'permissions': result.data
        }
Beispiel #12
0
    def enter(self):
        login = self.request.params.get('login', '')
        password = self.request.params.get('password', '')
        remember = self.request.params.get('remember')
        result = ApiClient(ConfigurationWrapper.get_auth(
            'map')).auth_client.authenticate_by_pass(login, password,
                                                     self.request.client_addr)
        if not result.is_success:
            return {'result': result.data}

        max_age = 30 * 24 * 60 * 60 if remember else None
        return self.redirect(lambda r: r.set_cookie(
            'auth.sid', result.data, httponly=True, max_age=max_age))
Beispiel #13
0
    def __call__(self):
        client = ApiClient(ConfigurationWrapper.get_auth('admin'))
        skip = int(self.request.params.get('skip', 0))
        take = int(self.request.params.get('take', 50000))
        answer_result = client.form_client.get_answers(
            self.request.session.user_id, skip, take)
        if not answer_result.is_success:
            return {'user': self.user, 'error': answer_result.data}

        answer_result.data.items = list(
            map(lambda answer: self.add_form_info(client, answer),
                answer_result.data.items))
        return {'user': self.user, 'answers': answer_result.data}
Beispiel #14
0
    def __call__(self):
        client = ApiClient(ConfigurationWrapper.get_auth('admin'))
        skip = int(self.request.params.get('skip', 0))
        take = int(self.request.params.get('take', 50000))
        forms_result = client.form_client.get_forms(
            self.request.session.user_id, skip, take)
        if not forms_result.is_success:
            return {'user': self.user, 'error': forms_result.data}

        return {
            'user': self.user,
            'forms': forms_result.data,
            'random_uuid': str(uuid.uuid4())
        }
Beispiel #15
0
def index_228(req: Request):
    client = ApiClient(ConfigurationWrapper.get_auth("map"))
    user = load_user(req)
    ids = user.id if user else \
        "00000000-0000-0000-0000--000000000000"

    answer = dict()
    for id in req.params:
        answer[id] = req.params[id]
    form_id = answer.pop("form_id")
    place_id = answer.pop("place_id")
    answer = json.dumps(answer)
    form = client.form_client.create_answer(ids, form_id, place_id, answer)
    return HTTPOkWithRedirect("/")
Beispiel #16
0
 def edit(self):
     form_id = self.request.matchdict.get('form_id')
     answer = dict()
     for id in self.request.params:
         answer[id] = self.request.params[id]
     title = answer.pop('title')
     description = answer.pop('description')
     content = json.dumps(answer)
     result = ApiClient(
         ConfigurationWrapper.get_auth('admin')).form_client.set_form(
             form_id, title, description, content)
     if not result.is_success:
         return {'user': self.user, 'error': result.data}
     return self.get('Формы поправлена')
Beispiel #17
0
    def get(self, success=None):
        form_id = self.request.matchdict.get('form_id')
        form_result = ApiClient(ConfigurationWrapper.get_auth(
            'admin')).form_client.get_form(form_id)
        if not form_result.is_success:
            return {'user': self.user, 'error': form_result.data}

        inputs = json.loads(form_result.data.content)
        return {
            'success': success,
            'user': self.user,
            'form': form_result.data,
            'inputs': inputs
        }
Beispiel #18
0
    def __call__(self):
        client = ApiClient(ConfigurationWrapper.get_auth('admin'))
        form_id = self.request.matchdict.get('form_id')
        skip = int(self.request.params.get('skip', 0))
        take = int(self.request.params.get('take', 50000))
        bindings_result = client.form_client.get_bindings(form_id, skip, take)
        if not bindings_result.is_success:
            return {'user': self.user, 'error': bindings_result.data}

        return {
            'user': self.user,
            'form_id': form_id,
            'places': bindings_result.data,
            'random_uuid': str(uuid.uuid4())
        }
Beispiel #19
0
 def put(self):
     latitude = self.request.params.get('lat')
     longitude = self.request.params.get('lon')
     nominatim = ConfigurationWrapper.instance('api').get('nominatim')
     request = Request.blank(
         nominatim + '/reverse?format=json&lat=%s&lon=%s&addressdetails=1' %
         (latitude, longitude))
     request.user_agent = 'CoolMap/1.0.0'
     response = request.get_response()
     if response.status_code != HTTPStatus.OK.value:
         return HTTPBadResponse(
             FailResultSimple('FailGeodecoding', 'Fail to geodecoding'))
     data = response.json_body
     osm_type = data.get('osm_type')[0].upper()
     osm_id = data.get('osm_id')
     title = data.get('display_name')
     address = json.dumps(data.get('address'))
     place = self._add_or_update(osm_id, osm_type, address, title)
     return HTTPOk(place)
Beispiel #20
0
 def get(self, success: str = None):
     client = ApiClient(ConfigurationWrapper.get_auth('admin'))
     answer_id = self.request.matchdict.get('answer_id')
     answer_result = client.form_client.get_answer(answer_id)
     if not answer_result.is_success:
         return {'user': self.user, 'error': answer_result.data}
     form_result = client.form_client.get_form(answer_result.data.form_id)
     if not form_result.is_success:
         return {'user': self.user, 'error': form_result.data}
     inputs = json.loads(form_result.data.content)
     answers = json.loads(answer_result.data.answer)
     for input_id in inputs:
         label = inputs[input_id]
         inputs[input_id] = {
             'label': label,
             'answer': answers.get(input_id, '')
         }
     return {
         'success': success,
         'user': self.user,
         'answer_id': answer_id,
         'form': form_result.data,
         'inputs': inputs
     }
Beispiel #21
0
import uuid

from core.configuration import ConfigurationWrapper
from core.entities import *
from sqlalchemy import create_engine, Table
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm.session import Session

Base = declarative_base()
Engine = create_engine(ConfigurationWrapper.instance('api').get('database'))


class SessionWrapper(Session):
    def __init__(self, **kwargs):
        super(SessionWrapper, self).__init__(**kwargs)

    def __enter__(self) -> 'SessionWrapper':
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        if exc_type is None:
            self.commit()
        else:
            self.rollback()
        self.close()


def create_transaction() -> SessionWrapper:
    return SessionWrapper(bind=Engine)

Beispiel #22
0
def index(req: Request):
    client = ApiClient(ConfigurationWrapper.get_auth("map"))
    #print(req.params.get("place_id"))
    forms = client.form_client.get_forms_place_id(req.params.get("place_id"))
    return {'forms': forms.data.items, 'place_id': req.params.get("place_id")}