async def find_email_and_refresh_token( self, email: UserEmail, refresh_token: UserRefreshToken) -> User: await self._ensure_indexes() user: Optional[User] = await self._find_one( self._collection, { 'email': email.value(), 'refresh_token': refresh_token.value() }) if not user: raise UserNotFoundError.create( detail={ 'email': email.value(), 'refresh_token': refresh_token.value() }) return user
def forget_password(self) -> None: self._refresh_token = UserRefreshToken.generate() self._refresh_token_expiration_in = UserRefreshTokenExpirationIn.generate( ) self.record_aggregate_event( UserPasswordForgotten( UserPasswordForgotten.Attributes( self._id, self._email, self._refresh_token, self._refresh_token_expiration_in)))
def decode(self, data: Dict[str, Any]) -> Event: return UserPasswordForgotten( UserPasswordForgotten.Attributes( UserId(data['id']), UserEmail(data['email']), UserRefreshToken(data['refresh_token']), UserRefreshTokenExpirationIn( data['refresh_token_expiration_in']), ))
def to_aggregate(self, data: Dict[str, Any]) -> User: return User( UserId(data['id']), UserEmail(data['email']), UserPassword(data['password'], True), None if data['refresh_token'] is None else UserRefreshToken( data['refresh_token']), None if data['refresh_token_expiration_in'] is None else UserRefreshTokenExpirationIn(data['refresh_token_expiration_in']), )
def test_refresh_token_successfully() -> None: assert isinstance(UserRefreshToken('0' * 6), UserRefreshToken)
def test_refresh_token_fails(value: str) -> None: pytest.raises(UserRefreshTokenNotValidError, lambda: UserRefreshToken(value))
async def handle(self, command: ResetUserPasswordCommand) -> None: await self._service( UserEmail(command.email), UserRefreshToken(command.refresh_token), UserPassword(command.new_password) )