· 7 years ago · Jul 06, 2018, 11:10 AM
1 register( user: UserEdit, password: UserPassword ) {
2 const request = {};
3 Object.assign( request, user );
4 Object.assign( request, password );
5 const subject = new Subject<User>();
6 this.getRegistrationToken().subscribe( token => {
7 this.http.post<User>( '/user/registration', request, {
8 params: { access_token: token.access_token }
9 } ).subscribe(
10 newUser => subject.next( newUser ),
11 error => subject.error( error )
12 );
13 } );
14 return subject.asObservable();
15 }
16
17
18 private getRegistrationToken() {
19 const data = {
20 client_id: 'registrationClient',
21 grant_type: 'registration'
22 };
23 const headers = new HttpHeaders( {
24 'Authorization': 'Basic ' + btoa( `${data.client_id}:reg` ),
25 'Content-Type': 'application/json'
26 } );
27 return this.http.post<Token>( '/oauth/token', null, {
28 headers: headers,
29 params: data
30 } );
31 }
32
33
34export class UserEdit {
35 firstName: string;
36 lastName: string;
37 email: string;
38 telephone: string;
39}
40
41export class UserPassword {
42 password: string;
43 confirmPassword: string;
44}