Example #1
0
 def get(self):
     user_id = self.request.matchdict.get('user_id')
     with create_transaction() as transaction:
         state = transaction.query(UserSql).filter(
             UserSql.id == user_id).first()
         return HTTPOk(state.val()) if state is not None \
             else HTTPNotFound(FailResultSimple("UserNotFound", "Пользователь не найдена"))
Example #2
0
 def session(self):
     with create_transaction() as transaction:
         auth_sid = self.request.matchdict.get('auth_sid')
         state = transaction.query(SessionStateSql).filter(
             SessionStateSql.id == auth_sid).first()
         return HTTPOk(state.val()) if state is not None \
             else HTTPNotFound(FailResultSimple("SessionNotFound", "Сессия не найдена"))
Example #3
0
 def get_form(self):
     id = self.request.matchdict.get('id')
     with create_transaction() as transaction:
         form = transaction.query(FormSql) \
             .filter(FormSql.id == id) \
             .first()
         return HTTPOk(form.val()) if form \
             else HTTPNotFound(FailResultSimple('FormNotFound', 'Форма не найдена'))
Example #4
0
 def delete_answer(self):
     id = self.request.matchdict.get('id')
     with create_transaction() as transaction:
         deleted = transaction.query(AnswerSql) \
             .filter(AnswerSql.id == id) \
             .delete()
         return HTTPOk() if deleted \
             else HTTPNotFound(FailResultSimple('AnswerNotFound', 'Ответ не найдена'))
Example #5
0
 def get_answer(self):
     id = self.request.matchdict.get('id')
     with create_transaction() as transaction:
         answer = transaction.query(AnswerSql) \
             .filter(AnswerSql.id == id) \
             .first()
         return HTTPOk(answer.val()) if answer \
             else HTTPNotFound(FailResultSimple('AnswerNotFound', 'Ответ не найдена'))
Example #6
0
 def delete_binding(self):
     form_id = self.request.matchdict.get('form_id')
     place_id = self.request.matchdict.get('place_id')
     with create_transaction() as transaction:
         deleted = transaction.query(BindingSql) \
             .filter(BindingSql.form_id == form_id and BindingSql.place_id == place_id) \
             .delete()
         return HTTPOk() if deleted \
             else HTTPNotFound(FailResultSimple('BindingNotFound', 'Привязка не найдена'))
Example #7
0
 def set_answer(self):
     id = self.request.matchdict.get('id')
     answer = self.request.body.decode()
     with create_transaction() as transaction:
         patched = transaction.query(AnswerSql) \
             .filter(AnswerSql.id == id) \
             .update({AnswerSql.answer: answer})
         return HTTPOk() if patched \
             else HTTPNotFound(FailResultSimple('AnswerNotFound', 'Ответ не найдена'))
Example #8
0
 def set_form(self):
     id = self.request.matchdict.get('id')
     data = self.request.body.decode()
     data = json.loads(data)
     with create_transaction() as transaction:
         patched = transaction.query(FormSql) \
             .filter(FormSql.id == id) \
             .update(data)
         return HTTPOk() if patched \
             else HTTPNotFound(FailResultSimple('FormNotFound', 'Форма не найдена'))
Example #9
0
 def put_form(self):
     id = self.request.matchdict.get('id')
     data = self.request.body.decode()
     data = json.loads(data)
     data["id"] = id
     form = FormSql(**data)
     try:
         with create_transaction() as transaction:
             transaction.add(form)
         return HTTPOk()
     except IntegrityError:
         return HTTPNotFound(FailResultSimple('FormNotCreated', 'Форма не создана'))
Example #10
0
 def put_answer(self):
     id = self.request.matchdict.get('id')
     data = self.request.body.decode()
     data = json.loads(data)
     data["id"] = id
     answer = AnswerSql(**data)
     try:
         with create_transaction() as transaction:
             transaction.add(answer)
         return HTTPOk()
     except IntegrityError:
         return HTTPNotFound(FailResultSimple('AnswerNotCreated', 'Ответ не создана'))
Example #11
0
 def put(self):
     login = self.request.params.get('login')
     email = self.request.params.get('email')
     password = self.request.body.decode()
     try:
         with create_transaction() as transaction:
             user = UserSql(login, password, email)
             transaction.add(user)
             return HTTPOk(user.id)
     except IntegrityError:
         return HTTPBadResponse(
             FailResultSimple("FailRegister",
                              "Не удалось зарегистрировать"))
Example #12
0
    def authenticate_by_pass(self):
        login = self.request.params.get('login')
        client_addr = self.request.params.get('client_addr')
        password = self.request.body.decode()

        with create_transaction() as transaction:
            user = transaction.query(UserSql)\
                .filter((UserSql.login == login) & (UserSql.password == password))\
                .first()
            if user is None:
                return HTTPForbidden(
                    FailResultSimple("UserNotFound", "Пользователь не найден"))

            state = SessionStateSql(user_id=user.id,
                                    auth_mode="ByPass",
                                    ip_address=client_addr)
            transaction.add(state)
            return HTTPOk(sid=state.id)
Example #13
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)
Example #14
0
def forbidden_view(req: Request):
    return HTTPForbidden(FailResultSimple('Forbidden', 'Authorization has been denied for this request'))