Beispiel #1
0
 def get_current_user_from_header(self):
     user = self.request.headers.get('user')
     pwd = self.request.headers.get('pwd')
     if (user is None) or (pwd is None):
         return 0
     user = self.toString(user)
     pwd = self.toString(pwd)
     ret,userId = authManager.userAuthByNamePwd(user,pwd)
     if error.ERR_CODE_OK_ != ret:
         return 0
     return userId
Beispiel #2
0
 def post(self):
     requestApi = copy.deepcopy(restDef.RESTFUL_API[restDef.HTTP_RES['userLogin']]['@POST']['REQUEST'])
     responseApi = copy.deepcopy(restDef.RESTFUL_API[restDef.HTTP_RES['userLogin']]['@POST']['RESP'])
     self._getAllArguments(requestApi)
     retcode,userId = authManager.userAuthByNamePwd(requestApi['name'],requestApi['pwd'])
     if retcode!=error.ERR_CODE_OK_\
         or userId is None:
         self.send_error_msg(self.__ERRCODE__['loginfail'])
         return
     # change user state
     if error.ERR_CODE_OK_!=authManager.userChangeStatus(userId,'online'):
         self.send_error_msg(self.__ERRCODE__['innererr'])
         return
     # set cookie
     self.set_secure_cookie('user',str(userId),expires_days=None)
     responseApi['id'] = userId
     self.write(escape.json_encode(responseApi))