mirror of
https://github.com/ceph/ceph
synced 2025-01-20 10:01:45 +00:00
Merge pull request #32084 from votdev/auth_service_observable
mgr/dashboard: Use Observable in auth.service Reviewed-by: Alfonso Martínez <almartin@redhat.com>
This commit is contained in:
commit
9960f9365a
@ -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(['']);
|
||||
});
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user