Users now become unverified when email is changed (#783)

* Users now become unverified when email is changed

Occurs when updating user.email to a new value

* changed wording
This commit is contained in:
jakemanger
2021-11-07 17:04:06 +08:00
committed by GitHub
parent 981e02b738
commit 9eb49482c7
2 changed files with 16 additions and 0 deletions

View File

@@ -545,6 +545,7 @@ class BaseUserManager(Generic[models.UC, models.UD]):
raise UserAlreadyExists()
except UserNotExists:
user.email = value
user.is_verified = False
elif field == "password":
await self.validate_password(value, user)
hashed_password = get_password_hash(value)

View File

@@ -202,6 +202,21 @@ class TestUpdateMe:
data = cast(Dict[str, Any], response.json())
assert data["email"] == "king.arthur@tintagel.bt"
async def test_unverified_after_email_change(
self,
test_app_client: Tuple[httpx.AsyncClient, bool],
verified_user: UserDB,
):
client, _ = test_app_client
json = {"email": "king.arthur@tintagel.bt"}
response = await client.patch(
"/me", json=json, headers={"Authorization": f"Bearer {verified_user.id}"}
)
assert response.status_code == status.HTTP_200_OK
data = cast(Dict[str, Any], response.json())
assert data["is_verified"] is False
async def test_valid_body_is_superuser(
self,
test_app_client: Tuple[httpx.AsyncClient, bool],