mirror of
https://github.com/maxdorninger/MediaManager.git
synced 2026-02-19 23:49:11 -05:00
Merge pull request #117 from maxdorninger/fix-password-updating-instead-of-email
fix password being set to new email when trying to update oneself's email
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import contextlib
|
||||
import logging
|
||||
import uuid
|
||||
from typing import Optional
|
||||
from typing import Optional, Any
|
||||
|
||||
from fastapi import Depends, Request
|
||||
from fastapi_users import BaseUserManager, FastAPIUsers, UUIDIDMixin, models
|
||||
@@ -46,6 +46,19 @@ class UserManager(UUIDIDMixin, BaseUserManager[User, uuid.UUID]):
|
||||
reset_password_token_secret = SECRET
|
||||
verification_token_secret = SECRET
|
||||
|
||||
async def on_after_update(
|
||||
self,
|
||||
user: models.UP,
|
||||
update_dict: dict[str, Any],
|
||||
request: Optional[Request] = None,
|
||||
) -> None:
|
||||
log.info(f"User {user.id} has been updated. Changes: {update_dict}")
|
||||
if "is_superuser" in update_dict and update_dict["is_superuser"]:
|
||||
log.info(f"User {user.id} has been granted superuser privileges.")
|
||||
if "email" in update_dict:
|
||||
updated_user = UserUpdate(is_verified=True)
|
||||
await self.update(user=user, user_update=updated_user)
|
||||
|
||||
async def on_after_register(self, user: User, request: Optional[Request] = None):
|
||||
log.info(f"User {user.id} has registered.")
|
||||
if user.email in config.admin_emails:
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
credentials: 'include',
|
||||
body: JSON.stringify({
|
||||
...(newPassword !== '' && { password: newPassword }),
|
||||
...(newEmail !== '' && { password: newEmail })
|
||||
...(newEmail !== '' && { email: newEmail })
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user