From 629d8d6f70cf83b55011dff53bfe1c4a95ac3433 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 5 Aug 2016 18:04:08 +0200 Subject: Client: implement password change --- client/src/app/account/account.service.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 client/src/app/account/account.service.ts (limited to 'client/src/app/account/account.service.ts') diff --git a/client/src/app/account/account.service.ts b/client/src/app/account/account.service.ts new file mode 100644 index 000000000..19b4e0624 --- /dev/null +++ b/client/src/app/account/account.service.ts @@ -0,0 +1,19 @@ +import { Injectable } from '@angular/core'; + +import { AuthHttp, AuthService } from '../shared'; + +@Injectable() +export class AccountService { + private static BASE_USERS_URL = '/api/v1/users/'; + + constructor(private authHttp: AuthHttp, private authService: AuthService) { } + + changePassword(newPassword: string) { + const url = AccountService.BASE_USERS_URL + this.authService.getUser().id; + const body = { + password: newPassword + }; + + return this.authHttp.put(url, body); + } +} -- cgit v1.2.3 From de59c48f5f317018e3f746bbe4a7b7efe00109f2 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 23 Aug 2016 16:54:21 +0200 Subject: Client: centralize http res extraction in a service --- client/src/app/account/account.service.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'client/src/app/account/account.service.ts') diff --git a/client/src/app/account/account.service.ts b/client/src/app/account/account.service.ts index 19b4e0624..355bcef74 100644 --- a/client/src/app/account/account.service.ts +++ b/client/src/app/account/account.service.ts @@ -1,12 +1,16 @@ import { Injectable } from '@angular/core'; -import { AuthHttp, AuthService } from '../shared'; +import { AuthHttp, AuthService, RestExtractor } from '../shared'; @Injectable() export class AccountService { private static BASE_USERS_URL = '/api/v1/users/'; - constructor(private authHttp: AuthHttp, private authService: AuthService) { } + constructor( + private authHttp: AuthHttp, + private authService: AuthService, + private restExtractor: RestExtractor + ) {} changePassword(newPassword: string) { const url = AccountService.BASE_USERS_URL + this.authService.getUser().id; @@ -14,6 +18,8 @@ export class AccountService { password: newPassword }; - return this.authHttp.put(url, body); + return this.authHttp.put(url, body) + .map(this.restExtractor.extractDataBool) + .catch((res) => this.restExtractor.handleError(res)); } } -- cgit v1.2.3