Ejemplo n.º 1
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)
Ejemplo n.º 2
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')
Ejemplo n.º 3
0
def api_client(settings: Settings, admin_keys: Keys):
    """Return `ApiClient` object with valid `Keys`

    You can test API without authorization through web interface each time
    You should use it to test API as authorized user"""
    ApiClient.netloc = settings.app_api_netloc
    ApiClient.admin_keys = admin_keys
    return ApiClient()
Ejemplo n.º 4
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)
Ejemplo n.º 5
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")
    }
Ejemplo n.º 6
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
Ejemplo n.º 7
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('Ответ записан')
Ejemplo n.º 8
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
        }
Ejemplo n.º 9
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')
Ejemplo n.º 10
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))
Ejemplo n.º 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))
        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}
Ejemplo n.º 12
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())
        }
Ejemplo n.º 13
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('Формы поправлена')
Ejemplo n.º 14
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("/")
Ejemplo n.º 15
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
        }
Ejemplo n.º 16
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())
        }
Ejemplo n.º 17
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
     }
Ejemplo n.º 18
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")}
Ejemplo n.º 19
0
 def __init__(self, auth: IAuthProvider):
     self.client = ApiClient(auth)