コード例 #1
0
ファイル: checker.py プロジェクト: enowars/service-DJ_Booth
    async def login_user(self, user, password, addr):
        try:
            try:
                reader, writer = await asyncio.open_connection(addr, self.port)
            except:
                raise OfflineException("Couldn't connect to {}:{}".format(
                    addr, self.port))
            ret = await reader.readuntil(b": ")
            writer.write(b"l\n")
            await reader.readuntil(b": ")
            writer.write(user.encode() + b"\n")
            await reader.readuntil(b": ")
            writer.write(password.encode() + b"\n")
            ret = await reader.readline()
            if b"Sorry" in ret:
                raise Exception(
                    "Unable to log in as the user {} doesn't exist!".format(
                        user))
            await reader.readuntil(b"? ")

            return reader, writer
        except OfflineException as e:
            raise e
        except Exception as e:
            raise BrokenServiceException(
                "Couldn't log in as the user {}, {}".format(user, e))
コード例 #2
0
 async def test(self) -> None:
     try:
         response:aiohttp.ClientResponse = await self.http_session.get(self.scheme + "://" + self.address + ":" + str(self.port) + "/api/debug/test")
     except:
         raise OfflineException()
     if response.status!=200:
         raise BrokenServiceException(f"test Failed: {response}")
     return await response.text()
コード例 #3
0
 async def add_to_session(self, sessionid:int, username:str) -> None:
     try:
         params = {'sessionid': sessionid, 'username': username}
         response:aiohttp.ClientResponse = await self.http_session.post(self.scheme + "://" + self.address + ":" + str(self.port) + "/api/gamesession/adduser", data=params)
     except:
         raise OfflineException()
     if response.status!=200:
         raise BrokenServiceException(f"add_to_session Failed: {response.status}")
コード例 #4
0
 async def login(self, username: str, password: str) ->aiohttp.ClientResponse:
     try:
         params = {'username': username, 'password': password}
         response:aiohttp.ClientResponse = await self.http_session.post(self.scheme + "://" + self.address + ":" + str(self.port) + "/api/account/login", data=params)
     except:
         raise OfflineException()
     if response.status!=200:
         raise BrokenServiceException(f"Login Failed: {response}")
コード例 #5
0
 async def create_session(self, name:str, notes:str, password:str) -> aiohttp.ClientResponse:
     try:
         params = {'name': name, 'notes': notes, 'password': password}
         response:aiohttp.ClientResponse = await self.http_session.post(self.scheme + "://" + self.address + ":" + str(self.port) + "/api/gamesession/create", data=params)
     except:
         raise OfflineException()
     if response.status!=200:
         raise BrokenServiceException(f"create_session Failed: {response}")
     return response
コード例 #6
0
 async def register(self, username: str, email: str, password: str) ->str:
     try:
         params = {'username': username, 'email':email, 'password': password}
         response:aiohttp.ClientResponse = await self.http_session.post(self.scheme + "://" + self.address + ":" + str(self.port) + "/api/account/register", data=params)
         text = await response.text()
         self.logger.debug(text)
         response.close()
     except:
         raise OfflineException()
     if response.status!=200:
         raise BrokenServiceException(f"Register Failed: {response}")
コード例 #7
0
ファイル: checker.py プロジェクト: enowars/service-DJ_Booth
 async def create_user(self, user, password, addr):
     try:
         try:
             reader, writer = await asyncio.open_connection(addr, self.port)
         except:
             raise OfflineException("Couldn't connect to {}:{}".format(
                 addr, self.port))
         ret = await reader.readuntil(b": ")
         writer.write(b"r\n")
         await reader.readuntil(b": ")
         writer.write(user.encode() + b"\n")
         await reader.readuntil(b": ")
         writer.write(password.encode() + b"\n")
         writer.close()
     except OfflineException as e:
         raise e
     except Exception as e:
         raise BrokenServiceException(
             "Couldn't create the user {}, {}".format(user, e))