Ejemplo n.º 1
0
    async def process_request(self, path, request_headers):
        try:
            username, password_digest = decode_auth_header(request_headers)
            if not hmac.compare_digest(password_digest, teamserver_digest):
                logging.error(f"User {username} failed authentication")
                return http.HTTPStatus.UNAUTHORIZED, [], b'UNAUTHORIZED\n'
        except KeyError:
            logging.error('Received handshake with no authorization header')
            return http.HTTPStatus.FORBIDDEN, [], b'FORBIDDEN\n'

        logging.info(f"User {username} authenticated successfully")
Ejemplo n.º 2
0
    async def register(self, websocket):
        name, _ = decode_auth_header(websocket.request_headers)
        if list(filter(lambda x: x.name == name, self.users)):
            raise UsernameAlreadyPresentError(
                f"User with username '{name}' already exists")

        user = User(name, websocket)
        self.users.add(user)
        await self.broadcast_event(events.USER_LOGIN,
                                   f"{user.name} has joined!",
                                   exclude=[user])
        return user