]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/api/user.service.ts
update ceph source to reef 18.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / api / user.service.ts
CommitLineData
f67539c2 1import { HttpClient } from '@angular/common/http';
11fdf7f2 2import { Injectable } from '@angular/core';
f67539c2 3
e306af50
TL
4import { Observable, of as observableOf } from 'rxjs';
5import { catchError, mapTo } from 'rxjs/operators';
11fdf7f2 6
f67539c2 7import { UserFormModel } from '~/app/core/auth/user-form/user-form.model';
11fdf7f2
TL
8
9@Injectable({
f67539c2 10 providedIn: 'root'
11fdf7f2
TL
11})
12export class UserService {
13 constructor(private http: HttpClient) {}
14
15 list() {
16 return this.http.get('api/user');
17 }
18
19 delete(username: string) {
20 return this.http.delete(`api/user/${username}`);
21 }
22
23 get(username: string) {
24 return this.http.get(`api/user/${username}`);
25 }
26
27 create(user: UserFormModel) {
28 return this.http.post(`api/user`, user);
29 }
30
31 update(user: UserFormModel) {
32 return this.http.put(`api/user/${user.username}`, user);
33 }
9f95a23c
TL
34
35 changePassword(username: string, oldPassword: string, newPassword: string) {
36 // Note, the specified user MUST be logged in to be able to change
37 // the password. The backend ensures that the password of another
38 // user can not be changed, otherwise an error will be thrown.
39 return this.http.post(`api/user/${username}/change_password`, {
40 old_password: oldPassword,
41 new_password: newPassword
42 });
43 }
44
e306af50
TL
45 validateUserName(user_name: string): Observable<boolean> {
46 return this.get(user_name).pipe(
47 mapTo(true),
48 catchError((error) => {
49 error.preventDefault();
50 return observableOf(false);
51 })
52 );
53 }
54
9f95a23c 55 validatePassword(password: string, username: string = null, oldPassword: string = null) {
f67539c2
TL
56 return this.http.post('api/user/validate_password', {
57 password: password,
58 username: username,
59 old_password: oldPassword
60 });
9f95a23c 61 }
11fdf7f2 62}