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