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.component.html | 27 ++++++++++++++++ client/src/app/account/account.component.ts | 45 +++++++++++++++++++++++++++ client/src/app/account/account.routes.ts | 5 +++ client/src/app/account/account.service.ts | 19 +++++++++++ client/src/app/account/index.ts | 2 ++ 5 files changed, 98 insertions(+) create mode 100644 client/src/app/account/account.component.html create mode 100644 client/src/app/account/account.component.ts create mode 100644 client/src/app/account/account.routes.ts create mode 100644 client/src/app/account/account.service.ts create mode 100644 client/src/app/account/index.ts (limited to 'client/src/app/account') diff --git a/client/src/app/account/account.component.html b/client/src/app/account/account.component.html new file mode 100644 index 000000000..ad8f690bd --- /dev/null +++ b/client/src/app/account/account.component.html @@ -0,0 +1,27 @@ +

Account

+ +
{{ information }}
+
{{ error }}
+ +
+
+ + +
+ The password should have more than 5 characters +
+
+ +
+ + +
+ + +
diff --git a/client/src/app/account/account.component.ts b/client/src/app/account/account.component.ts new file mode 100644 index 000000000..5c42103f8 --- /dev/null +++ b/client/src/app/account/account.component.ts @@ -0,0 +1,45 @@ +import { Control, ControlGroup, Validators } from '@angular/common'; +import { Component, OnInit } from '@angular/core'; +import { Router } from '@angular/router'; + +import { AccountService } from './account.service'; + +@Component({ + selector: 'my-account', + template: require('./account.component.html'), + providers: [ AccountService ] +}) + +export class AccountComponent implements OnInit { + changePasswordForm: ControlGroup; + information: string = null; + error: string = null; + + constructor( + private accountService: AccountService, + private router: Router + ) {} + + ngOnInit() { + this.changePasswordForm = new ControlGroup({ + newPassword: new Control('', Validators.compose([ Validators.required, Validators.minLength(6) ])), + newConfirmedPassword: new Control('', Validators.compose([ Validators.required, Validators.minLength(6) ])), + }); + } + + changePassword(newPassword: string, newConfirmedPassword: string) { + this.information = null; + this.error = null; + + if (newPassword !== newConfirmedPassword) { + this.error = 'The new password and the confirmed password do not correspond.'; + return; + } + + this.accountService.changePassword(newPassword).subscribe( + ok => this.information = 'Password updated.', + + err => this.error = err + ); + } +} diff --git a/client/src/app/account/account.routes.ts b/client/src/app/account/account.routes.ts new file mode 100644 index 000000000..e348c6ebe --- /dev/null +++ b/client/src/app/account/account.routes.ts @@ -0,0 +1,5 @@ +import { AccountComponent } from './account.component'; + +export const AccountRoutes = [ + { path: 'account', component: AccountComponent } +]; 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); + } +} diff --git a/client/src/app/account/index.ts b/client/src/app/account/index.ts new file mode 100644 index 000000000..7445003fd --- /dev/null +++ b/client/src/app/account/index.ts @@ -0,0 +1,2 @@ +export * from './account.component'; +export * from './account.routes'; -- cgit v1.2.3 From 0f6da32b148c0f4146b2ae9ad1add9a9f00cc339 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 23 Aug 2016 14:37:49 +0200 Subject: Client: update to new form api --- client/src/app/account/account.component.html | 8 ++++---- client/src/app/account/account.component.ts | 22 +++++++++++++--------- 2 files changed, 17 insertions(+), 13 deletions(-) (limited to 'client/src/app/account') diff --git a/client/src/app/account/account.component.html b/client/src/app/account/account.component.html index ad8f690bd..4797fa914 100644 --- a/client/src/app/account/account.component.html +++ b/client/src/app/account/account.component.html @@ -3,14 +3,14 @@
{{ information }}
{{ error }}
-
+
-
+
The password should have more than 5 characters
@@ -19,7 +19,7 @@
diff --git a/client/src/app/account/account.component.ts b/client/src/app/account/account.component.ts index 5c42103f8..54939f43b 100644 --- a/client/src/app/account/account.component.ts +++ b/client/src/app/account/account.component.ts @@ -1,5 +1,6 @@ -import { Control, ControlGroup, Validators } from '@angular/common'; +import { Validators } from '@angular/common'; import { Component, OnInit } from '@angular/core'; +import { FormControl, FormGroup, REACTIVE_FORM_DIRECTIVES } from '@angular/forms'; import { Router } from '@angular/router'; import { AccountService } from './account.service'; @@ -7,11 +8,14 @@ import { AccountService } from './account.service'; @Component({ selector: 'my-account', template: require('./account.component.html'), - providers: [ AccountService ] + providers: [ AccountService ], + directives: [ REACTIVE_FORM_DIRECTIVES ] }) export class AccountComponent implements OnInit { - changePasswordForm: ControlGroup; + newPassword = ''; + newConfirmedPassword = ''; + changePasswordForm: FormGroup; information: string = null; error: string = null; @@ -21,22 +25,22 @@ export class AccountComponent implements OnInit { ) {} ngOnInit() { - this.changePasswordForm = new ControlGroup({ - newPassword: new Control('', Validators.compose([ Validators.required, Validators.minLength(6) ])), - newConfirmedPassword: new Control('', Validators.compose([ Validators.required, Validators.minLength(6) ])), + this.changePasswordForm = new FormGroup({ + 'new-password': new FormControl('', [ Validators.required, Validators.minLength(6) ]), + 'new-confirmed-password': new FormControl('', [ Validators.required, Validators.minLength(6) ]), }); } - changePassword(newPassword: string, newConfirmedPassword: string) { + changePassword() { this.information = null; this.error = null; - if (newPassword !== newConfirmedPassword) { + if (this.newPassword !== this.newConfirmedPassword) { this.error = 'The new password and the confirmed password do not correspond.'; return; } - this.accountService.changePassword(newPassword).subscribe( + this.accountService.changePassword(this.newPassword).subscribe( ok => this.information = 'Password updated.', err => this.error = err -- 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') 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 From ab32b0fc805b92c5a1d7ac5901cb1a38e94622ca Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Sep 2016 22:40:57 +0200 Subject: Dirty update to Angular RC6 --- client/src/app/account/account.component.ts | 8 +++----- client/src/app/account/index.ts | 1 + 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'client/src/app/account') diff --git a/client/src/app/account/account.component.ts b/client/src/app/account/account.component.ts index 54939f43b..a22738d3f 100644 --- a/client/src/app/account/account.component.ts +++ b/client/src/app/account/account.component.ts @@ -1,15 +1,13 @@ -import { Validators } from '@angular/common'; +import { } from '@angular/common'; import { Component, OnInit } from '@angular/core'; -import { FormControl, FormGroup, REACTIVE_FORM_DIRECTIVES } from '@angular/forms'; +import { FormControl, FormGroup, Validators } from '@angular/forms'; import { Router } from '@angular/router'; import { AccountService } from './account.service'; @Component({ selector: 'my-account', - template: require('./account.component.html'), - providers: [ AccountService ], - directives: [ REACTIVE_FORM_DIRECTIVES ] + template: require('./account.component.html') }) export class AccountComponent implements OnInit { diff --git a/client/src/app/account/index.ts b/client/src/app/account/index.ts index 7445003fd..823d9fe5f 100644 --- a/client/src/app/account/index.ts +++ b/client/src/app/account/index.ts @@ -1,2 +1,3 @@ export * from './account.component'; export * from './account.routes'; +export * from './account.service'; -- cgit v1.2.3 From 4b2f33f3c6d109365090b08244d7f99ad4e69025 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Sep 2016 22:16:51 +0200 Subject: Client: reactive forms --- client/src/app/account/account.component.html | 16 +++++----- client/src/app/account/account.component.ts | 44 +++++++++++++++++++-------- 2 files changed, 40 insertions(+), 20 deletions(-) (limited to 'client/src/app/account') diff --git a/client/src/app/account/account.component.html b/client/src/app/account/account.component.html index 4797fa914..5a8847acd 100644 --- a/client/src/app/account/account.component.html +++ b/client/src/app/account/account.component.html @@ -3,25 +3,25 @@
{{ information }}
{{ error }}
- +
-
- The password should have more than 5 characters +
+ {{ formErrors['new-password'] }}
- + diff --git a/client/src/app/account/account.component.ts b/client/src/app/account/account.component.ts index a22738d3f..b503406c9 100644 --- a/client/src/app/account/account.component.ts +++ b/client/src/app/account/account.component.ts @@ -1,44 +1,64 @@ import { } from '@angular/common'; import { Component, OnInit } from '@angular/core'; -import { FormControl, FormGroup, Validators } from '@angular/forms'; +import { FormBuilder, FormGroup } from '@angular/forms'; import { Router } from '@angular/router'; import { AccountService } from './account.service'; +import { FormReactive, USER_PASSWORD } from '../shared'; @Component({ selector: 'my-account', template: require('./account.component.html') }) -export class AccountComponent implements OnInit { - newPassword = ''; - newConfirmedPassword = ''; - changePasswordForm: FormGroup; +export class AccountComponent extends FormReactive implements OnInit { information: string = null; error: string = null; + form: FormGroup; + formErrors = { + 'new-password': '', + 'new-confirmed-password': '' + }; + validationMessages = { + 'new-password': USER_PASSWORD.MESSAGES, + 'new-confirmed-password': USER_PASSWORD.MESSAGES + }; + constructor( private accountService: AccountService, + private formBuilder: FormBuilder, private router: Router - ) {} + ) { + super(); + } - ngOnInit() { - this.changePasswordForm = new FormGroup({ - 'new-password': new FormControl('', [ Validators.required, Validators.minLength(6) ]), - 'new-confirmed-password': new FormControl('', [ Validators.required, Validators.minLength(6) ]), + buildForm() { + this.form = this.formBuilder.group({ + 'new-password': [ '', USER_PASSWORD.VALIDATORS ], + 'new-confirmed-password': [ '', USER_PASSWORD.VALIDATORS ], }); + + this.form.valueChanges.subscribe(data => this.onValueChanged(data)); + } + + ngOnInit() { + this.buildForm(); } changePassword() { + const newPassword = this.form.value['new-password']; + const newConfirmedPassword = this.form.value['new-confirmed-password']; + this.information = null; this.error = null; - if (this.newPassword !== this.newConfirmedPassword) { + if (newPassword !== newConfirmedPassword) { this.error = 'The new password and the confirmed password do not correspond.'; return; } - this.accountService.changePassword(this.newPassword).subscribe( + this.accountService.changePassword(newPassword).subscribe( ok => this.information = 'Password updated.', err => this.error = err -- cgit v1.2.3 From ec8d8440a893ba64075da2e57ea04c7976e0b303 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 19 Sep 2016 22:49:31 +0200 Subject: Client: use templateUrl/styleUrls instead of require --- client/src/app/account/account.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'client/src/app/account') diff --git a/client/src/app/account/account.component.ts b/client/src/app/account/account.component.ts index b503406c9..851eaf198 100644 --- a/client/src/app/account/account.component.ts +++ b/client/src/app/account/account.component.ts @@ -8,7 +8,7 @@ import { FormReactive, USER_PASSWORD } from '../shared'; @Component({ selector: 'my-account', - template: require('./account.component.html') + templateUrl: './account.component.html' }) export class AccountComponent extends FormReactive implements OnInit { -- cgit v1.2.3