]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/api/user.service.ts
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / api / user.service.ts
1 import { HttpClient } from '@angular/common/http';
2 import { Injectable } from '@angular/core';
3
4 import { Observable, of as observableOf } from 'rxjs';
5 import { catchError, mapTo } from 'rxjs/operators';
6
7 import { UserFormModel } from '~/app/core/auth/user-form/user-form.model';
8
9 @Injectable({
10 providedIn: 'root'
11 })
12 export 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 }
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
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
55 validatePassword(password: string, username: string = null, oldPassword: string = null) {
56 return this.http.post('api/user/validate_password', {
57 password: password,
58 username: username,
59 old_password: oldPassword
60 });
61 }
62 }