[FWA-3] fix cannot hash password
This commit is contained in:
parent
3fed0650c9
commit
db091176da
@ -40,7 +40,8 @@ class RepositoryUsers:
|
|||||||
if not db_user:
|
if not db_user:
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
self.user.query.where(User.id == user_id).update(user.dict(exclude_unset=True))
|
user.update_password()
|
||||||
|
self.user.query.where(User.id == user_id).update(user.dict(exclude_unset=True, exclude_none=True))
|
||||||
db.commit()
|
db.commit()
|
||||||
except Exception:
|
except Exception:
|
||||||
db.rollback()
|
db.rollback()
|
||||||
|
@ -3,6 +3,7 @@ from uuid import UUID
|
|||||||
from pydantic import ConfigDict
|
from pydantic import ConfigDict
|
||||||
from fastapi import Form
|
from fastapi import Form
|
||||||
|
|
||||||
|
from backend.core.security.security import hash_password
|
||||||
from backend.schemas.main_model import MainModel
|
from backend.schemas.main_model import MainModel
|
||||||
|
|
||||||
class UserBase(MainModel):
|
class UserBase(MainModel):
|
||||||
@ -21,6 +22,9 @@ class UserProfile(MainModel):
|
|||||||
is_lock: bool | None = None
|
is_lock: bool | None = None
|
||||||
model_config = ConfigDict(from_attributes=True)
|
model_config = ConfigDict(from_attributes=True)
|
||||||
|
|
||||||
|
def update_password(self):
|
||||||
|
self.password = (None if self.password is None else hash_password(self.password))
|
||||||
|
|
||||||
class UserSeeds(UserCreate):
|
class UserSeeds(UserCreate):
|
||||||
is_admin: bool
|
is_admin: bool
|
||||||
is_lock: bool
|
is_lock: bool
|
||||||
|
@ -32,12 +32,9 @@ export default function Profile() {
|
|||||||
const { formData } = formHandler
|
const { formData } = formHandler
|
||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
formHandler.fillForm(
|
formHandler.fillForm({
|
||||||
{
|
|
||||||
name: userInfo?.name,
|
name: userInfo?.name,
|
||||||
},
|
})
|
||||||
{ silentValidation: false },
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const submit = async (event) => {
|
const submit = async (event) => {
|
||||||
@ -53,6 +50,8 @@ export default function Profile() {
|
|||||||
|
|
||||||
if (resp.status === 200) {
|
if (resp.status === 200) {
|
||||||
setUser(resp.data)
|
setUser(resp.data)
|
||||||
|
formHandler.setFieldValue('password', '')
|
||||||
|
formHandler.setFieldValue('confirm-password', '')
|
||||||
notify.success({
|
notify.success({
|
||||||
title: 'Update profile success!',
|
title: 'Update profile success!',
|
||||||
description: 'Your profile has been updated!',
|
description: 'Your profile has been updated!',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user