]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Use Observable in auth.service 32084/head
authorVolker Theile <vtheile@suse.com>
Fri, 6 Dec 2019 14:12:27 +0000 (15:12 +0100)
committerVolker Theile <vtheile@suse.com>
Fri, 6 Dec 2019 14:12:27 +0000 (15:12 +0100)
Signed-off-by: Volker Theile <vtheile@suse.com>
src/pybind/mgr/dashboard/frontend/src/app/core/auth/login/login.component.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/api/auth.service.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/api/auth.service.ts

index b8c5b10a61893840f8a65153e386699ce84fe7b2..430efa87fa4e7a5cae43236d5937e6d218c4c4bf 100644 (file)
@@ -62,7 +62,7 @@ export class LoginComponent implements OnInit {
   }
 
   login() {
-    this.authService.login(this.model).then(() => {
+    this.authService.login(this.model).subscribe(() => {
       this.router.navigate(['']);
     });
   }
index e7ff555705d6c57a3b440e836deb7e61cb15f1a6..6a2e63d7b41926b5efb8a21a5b21732105654209 100644 (file)
@@ -34,7 +34,7 @@ describe('AuthService', () => {
   it('should login and save the user', fakeAsync(() => {
     const fakeCredentials = { username: 'foo', password: 'bar' };
     const fakeResponse = { username: 'foo', token: 'tokenbytes' };
-    service.login(<any>fakeCredentials);
+    service.login(fakeCredentials).subscribe();
     const req = httpTesting.expectOne('api/auth');
     expect(req.request.method).toBe('POST');
     expect(req.request.body).toEqual(fakeCredentials);
index 18382f61d12a953e29f8ccf4ef3a6a52acc5de2d..8ab1fb7d432611712fa70ac2b94a8586be1367b2 100644 (file)
@@ -2,6 +2,9 @@ import { HttpClient } from '@angular/common/http';
 import { Injectable } from '@angular/core';
 import { Router } from '@angular/router';
 
+import { Observable } from 'rxjs';
+import { tap } from 'rxjs/operators';
+
 import { Credentials } from '../models/credentials';
 import { LoginResponse } from '../models/login-response';
 import { AuthStorageService } from '../services/auth-storage.service';
@@ -21,13 +24,12 @@ export class AuthService {
     return this.http.post('api/auth/check', { token: token });
   }
 
-  login(credentials: Credentials) {
-    return this.http
-      .post('api/auth', credentials)
-      .toPromise()
-      .then((resp: LoginResponse) => {
+  login(credentials: Credentials): Observable<LoginResponse> {
+    return this.http.post('api/auth', credentials).pipe(
+      tap((resp: LoginResponse) => {
         this.authStorageService.set(resp.username, resp.token, resp.permissions, resp.sso);
-      });
+      })
+    );
   }
 
   logout(callback: Function = null) {