创建使用电子邮件地址和密码登录的用户身份

async def create_email_identity(self, 
            client_id, identity, passwd, *, 
            user_id=None # 如果设置用户ID，则创建该用户的新登录身份
        ) -> SessionIdentity :
        """ 创建使用电子邮件地址和密码登录的用户身份 """
        
        assert passwd

        value, _ = await self._client.get(f"/users/identity/{identity}")
        if value:
            raise ValueError(f' {identity} has already been registered')

        if user_id is None: # 新用户
            user_id = await self._user_id_generator.new()

        # 加密登录标识
        hashed = sha256_crypt.using(rounds=2000, salt_size=8).hash(passwd)

        profile = {
            "user_id": user_id,
            "identity": identity,
            "hashed": hashed
        }

        token = genword(length=32, charset="ascii_50")
        key = f"/users/verifying/{token}"

        await self._client.put(key, json.dumps(profile))

        return SessionIdentity(user_id=user_id, identity=identity)