[FWA-3] fix cannot hash password

This commit is contained in:
Sam Liu 2024-06-11 12:55:46 +00:00
parent 3fed0650c9
commit db091176da
3 changed files with 11 additions and 7 deletions

View File

@ -40,7 +40,8 @@ class RepositoryUsers:
if not db_user:
return None
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()
except Exception:
db.rollback()

View File

@ -3,6 +3,7 @@ from uuid import UUID
from pydantic import ConfigDict
from fastapi import Form
from backend.core.security.security import hash_password
from backend.schemas.main_model import MainModel
class UserBase(MainModel):
@ -21,6 +22,9 @@ class UserProfile(MainModel):
is_lock: bool | None = None
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):
is_admin: bool
is_lock: bool

View File

@ -32,12 +32,9 @@ export default function Profile() {
const { formData } = formHandler
createEffect(() => {
formHandler.fillForm(
{
formHandler.fillForm({
name: userInfo?.name,
},
{ silentValidation: false },
)
})
})
const submit = async (event) => {
@ -53,6 +50,8 @@ export default function Profile() {
if (resp.status === 200) {
setUser(resp.data)
formHandler.setFieldValue('password', '')
formHandler.setFieldValue('confirm-password', '')
notify.success({
title: 'Update profile success!',
description: 'Your profile has been updated!',