Feature: Allow password change
This commit is contained in:
parent
72b0e0e97d
commit
27205f7790
@ -42,31 +42,27 @@ def save(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/me", response_model=schemas.User)
|
@router.get("/me", response_model=schemas.UserMe)
|
||||||
def show_me(
|
def show_me(
|
||||||
user: UserToken = Depends(get_user),
|
user: UserToken = Depends(get_user),
|
||||||
) -> schemas.User:
|
) -> schemas.UserMe:
|
||||||
with SessionFuture() as db:
|
with SessionFuture() as db:
|
||||||
item = db.execute(select(User).where(User.id == user.id_)).scalar_one()
|
item = db.execute(select(User).where(User.id == user.id_)).scalar_one()
|
||||||
return user_info(item, db, user)
|
return user_me(item)
|
||||||
|
|
||||||
|
|
||||||
@router.put("/me", response_model=schemas.User)
|
@router.put("/me", response_model=schemas.UserMe)
|
||||||
def update_me(
|
def update_me(
|
||||||
data: schemas.UserIn,
|
data: schemas.UserIn,
|
||||||
user: UserToken = Depends(get_user),
|
user: UserToken = Depends(get_user),
|
||||||
) -> schemas.User:
|
) -> schemas.UserMe:
|
||||||
try:
|
try:
|
||||||
with SessionFuture() as db:
|
with SessionFuture() as db:
|
||||||
item: User = db.execute(select(User).where(User.id == user.id_)).scalar_one()
|
item: User = db.execute(select(User).where(User.id == user.id_)).scalar_one()
|
||||||
if "users" in user.permissions:
|
|
||||||
item.name = data.name
|
|
||||||
item.locked_out = data.locked_out
|
|
||||||
add_roles(item, data.roles, db)
|
|
||||||
if data.password and item.password != data.password:
|
if data.password and item.password != data.password:
|
||||||
item.password = data.password
|
item.password = data.password
|
||||||
db.commit()
|
db.commit()
|
||||||
return user_info(item, db, user)
|
return user_me(item)
|
||||||
except SQLAlchemyError as e:
|
except SQLAlchemyError as e:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||||
@ -184,6 +180,16 @@ def user_info(item: User, db: Session, user: UserToken) -> schemas.User:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def user_me(item: User) -> schemas.UserMe:
|
||||||
|
return schemas.UserMe(
|
||||||
|
id="me",
|
||||||
|
name=item.name,
|
||||||
|
password="",
|
||||||
|
lockedOut=item.locked_out,
|
||||||
|
roles=[],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def blank_user_info(db: Session) -> schemas.UserIn:
|
def blank_user_info(db: Session) -> schemas.UserIn:
|
||||||
return schemas.UserIn(
|
return schemas.UserIn(
|
||||||
name="",
|
name="",
|
||||||
|
@ -27,6 +27,14 @@ class User(UserIn):
|
|||||||
alias_generator = to_camel
|
alias_generator = to_camel
|
||||||
|
|
||||||
|
|
||||||
|
class UserMe(UserIn):
|
||||||
|
id_: str
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
anystr_strip_whitespace = True
|
||||||
|
alias_generator = to_camel
|
||||||
|
|
||||||
|
|
||||||
class UserLink(BaseModel):
|
class UserLink(BaseModel):
|
||||||
id_: Optional[uuid.UUID]
|
id_: Optional[uuid.UUID]
|
||||||
name: Optional[str]
|
name: Optional[str]
|
||||||
|
@ -232,6 +232,15 @@
|
|||||||
>
|
>
|
||||||
<h3 class="item-name">Users</h3>
|
<h3 class="item-name">Users</h3>
|
||||||
</mat-card>
|
</mat-card>
|
||||||
|
<mat-card
|
||||||
|
fxLayout="column"
|
||||||
|
class="square-button"
|
||||||
|
matRipple
|
||||||
|
*ngIf="auth.allowed('authenticated')"
|
||||||
|
[routerLink]="['/', 'users', 'me']"
|
||||||
|
>
|
||||||
|
<h3 class="item-name">Change Password</h3>
|
||||||
|
</mat-card>
|
||||||
<mat-card
|
<mat-card
|
||||||
fxLayout="column"
|
fxLayout="column"
|
||||||
class="square-button"
|
class="square-button"
|
||||||
|
@ -73,7 +73,12 @@ export class UserDetailComponent implements OnInit, AfterViewInit {
|
|||||||
this.ser.saveOrUpdate(this.getItem()).subscribe(
|
this.ser.saveOrUpdate(this.getItem()).subscribe(
|
||||||
() => {
|
() => {
|
||||||
this.toaster.show('Success', '');
|
this.toaster.show('Success', '');
|
||||||
this.router.navigateByUrl('/users');
|
console.log(this.item.id);
|
||||||
|
if ((this.item.id as string) === 'me') {
|
||||||
|
this.router.navigateByUrl('/');
|
||||||
|
} else {
|
||||||
|
this.router.navigateByUrl('/users');
|
||||||
|
}
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
this.toaster.show('Error', error);
|
this.toaster.show('Error', error);
|
||||||
|
Loading…
Reference in New Issue
Block a user