Esempio n. 1
0
 def render_post(self, request):
     """
     Render HTTP POST request
     :param request: http request
     """
     log = self._log.getChild("render_post")
     try:
         self.postUrlList[request.url](request)
     except KeyError:
         response = Response()
         response.responseCode = 404
         self.write(response)
     except (error.BaseException, BaseSessionException) as bErr:
         response = Response()
         response.responseCode = 400
         response.content = validator.create_json_response(
             errorCode=bErr.errno, reason=bErr.errorMsg)
         response.headers['Content-Type'] = 'application/json'
         self.write(response)
     except Exception as err:
         log.exception("Exception in rended: {}".format(err))
         response = Response()
         response.responseCode = 500
         response.content = validator.create_json_response(
             errorCode=500, reason="Internal error.")
         response.headers['Content-Type'] = 'application/json'
         self.write(response)
Esempio n. 2
0
 def render_post(self, request):
     """
     Render HTTP POST request
     :param request: http request
     """
     log = self._log.getChild("render_post")
     try:
         self.postUrlList[request.url](request)
     except KeyError:
         response = Response()
         response.responseCode = 404
         self.write(response)
     except (error.BaseException, BaseSessionException) as bErr:
         response = Response()
         response.responseCode = 400
         response.content = validator.create_json_response(errorCode=bErr.errno, reason=bErr.errorMsg)
         response.headers['Content-Type'] = 'application/json'
         self.write(response)
     except Exception as err:
         log.exception("Exception in rended: {}".format(err))
         response = Response()
         response.responseCode = 500
         response.content = validator.create_json_response(errorCode=500, reason="Internal error.")
         response.headers['Content-Type'] = 'application/json'
         self.write(response)
Esempio n. 3
0
 def auth(self, request):
     """
     Authorize user
     :param request:
     :return:
     """
     log = self._log.getChild("auth")
     login = request.get_param('login')
     password = request.get_param('password')
     user = self.dbHandler.get_user(login, password)
     cookie = self.dbHandler.set_session(user.id)
     response = Response()
     response.set_cookie(self.cookieName, cookie)
     response.content = validator.create_json_response(data={})
     response.headers['Content-Type'] = '; '.join(['application/json', 'charset=utf-8'])
     log.info("Set cookie: {}, login: {}, userid: {}".format(cookie, login, user.id))
     self.write(response)
Esempio n. 4
0
 def auth(self, request):
     """
     Authorize user
     :param request:
     :return:
     """
     log = self._log.getChild("auth")
     login = request.get_param('login')
     password = request.get_param('password')
     user = self.dbHandler.get_user(login, password)
     cookie = self.dbHandler.set_session(user.id)
     response = Response()
     response.set_cookie(self.cookieName, cookie)
     response.content = validator.create_json_response(data={})
     response.headers['Content-Type'] = '; '.join(
         ['application/json', 'charset=utf-8'])
     log.info("Set cookie: {}, login: {}, userid: {}".format(
         cookie, login, user.id))
     self.write(response)
Esempio n. 5
0
 def registration(self, request):
     """
     Registrate new user
     :param request: http request
     :return:
     """
     log = self._log.getChild("registration")
     login = request.get_param('login')
     password = request.get_param('password')
     validator.is_valid_login(login)
     validator.is_valid_password(password)
     userId = self.dbHandler.register_user(login, password)
     cookie = self.dbHandler.set_session(userId)
     response = Response()
     response.set_cookie(self.cookieName, cookie)
     response.content = validator.create_json_response(data={})
     response.headers['Content-Type'] = '; '.join(['application/json', 'charset=utf-8'])
     log.info("Set cookie: {}, login: {}, userid: {}".format(cookie, login, userId))
     self.write(response)
Esempio n. 6
0
 def registration(self, request):
     """
     Registrate new user
     :param request: http request
     :return:
     """
     log = self._log.getChild("registration")
     login = request.get_param('login')
     password = request.get_param('password')
     validator.is_valid_login(login)
     validator.is_valid_password(password)
     userId = self.dbHandler.register_user(login, password)
     cookie = self.dbHandler.set_session(userId)
     response = Response()
     response.set_cookie(self.cookieName, cookie)
     response.content = validator.create_json_response(data={})
     response.headers['Content-Type'] = '; '.join(
         ['application/json', 'charset=utf-8'])
     log.info("Set cookie: {}, login: {}, userid: {}".format(
         cookie, login, userId))
     self.write(response)