Skip to content

Commit

Permalink
Merge pull request #584 from LINCnil/new_account
Browse files Browse the repository at this point in the history
New account
  • Loading branch information
kevin-atnos authored Sep 23, 2021
2 parents 261546e + 7a91376 commit 35158b6
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 151 deletions.
7 changes: 6 additions & 1 deletion src/app/modules/home/forms/password/password.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { TranslateService } from '@ngx-translate/core';
})
export class PasswordComponent implements OnInit {
@Input() reset = false;
@Input() accountData = null;
@Output() canceled = new EventEmitter<boolean>();
@Output() validated = new EventEmitter<boolean>();
loading: boolean = false;
Expand Down Expand Up @@ -91,7 +92,11 @@ export class PasswordComponent implements OnInit {
ngOnSubmit() {
this.loading = true;
this.authService
.checkPassword(this.signUp.controls.password.value)
.sendPassword(
this.accountData.id,
this.signUp.controls.password.value,
this.signUp.controls.confirmPassword.value
)
.then(() => {
this.loading = false;
this.validated.emit(true);
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

16 changes: 14 additions & 2 deletions src/app/modules/home/forms/uuid/uuid.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,27 @@
[class.is-not-empty]="f.uuid.value.length > 0"
[class.is-invalid]="f.uuid.value.length > 0 && f.uuid.errors"
>
<legend>{{ "authentication.create_account" | translate }}</legend>
<ng-container *ngIf="reset; else noReset">
<legend>{{ "authentication.account_recovery" | translate }}</legend>
<p class="is-valid">
{{ "authentication.recovery_code_message" | translate }}
</p>
</ng-container>
<ng-template #noReset>
<legend>{{ "authentication.create_account" | translate }}</legend>
</ng-template>

<p class="msg" *ngIf="msgFromBack">
{{ msgFromBack }}
</p>

<input
type="text"
placeholder="{{ 'authentication.activation_code' | translate }}"
placeholder="{{
reset
? ('authentication.recovery_code' | translate)
: ('authentication.activation_code' | translate)
}}"
id="pia-account-activate-code"
formControlName="uuid"
/>
Expand Down
10 changes: 6 additions & 4 deletions src/app/modules/home/forms/uuid/uuid.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, EventEmitter, OnInit, Output } from '@angular/core';
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import {
FormGroup,
FormBuilder,
Expand All @@ -8,15 +8,17 @@ import {

import { AuthService } from 'src/app/services/auth.service';
import { TranslateService } from '@ngx-translate/core';
import { User } from 'src/app/models/user.model';

@Component({
selector: 'app-uuid',
templateUrl: './uuid.component.html',
styleUrls: ['../form.scss', './uuid.component.scss']
})
export class UuidComponent implements OnInit {
@Input() reset = false;
@Output() canceled = new EventEmitter<boolean>();
@Output() validated = new EventEmitter<boolean>();
@Output() validated = new EventEmitter<boolean | User>();

loading: boolean = false;
uuidActivation: FormGroup;
Expand Down Expand Up @@ -54,9 +56,9 @@ export class UuidComponent implements OnInit {
this.loading = true;
this.authService
.checkUuid(this.uuidActivation.controls.uuid.value)
.then(() => {
.then((response: User) => {
this.loading = false;
this.validated.emit(true);
this.validated.emit(response);
})
.catch(err => {
this.loading = false;
Expand Down
15 changes: 9 additions & 6 deletions src/app/modules/home/home.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ <h2 [innerHTML]="'authentication.subtitle1' | translate"></h2>
<ng-container *ngSwitchCase="'checkUuid'">
<app-uuid
(canceled)="changeDisplay('logIn')"
(validated)="changeDisplay('signUp')"
(validated)="changeDisplay('signUp'); accountData = $event"
></app-uuid>
</ng-container>

<!-- New account - Define password -->
<ng-container *ngSwitchCase="'signUp'">
<app-password
(validated)="changeDisplay('logIn'); fromValidation = true"
(validated)="changeDisplay('logIn'); fromValidation = $event"
(canceled)="changeDisplay('checkUuid')"
[accountData]="accountData"
></app-password>
</ng-container>

Expand All @@ -53,18 +54,20 @@ <h2 [innerHTML]="'authentication.subtitle1' | translate"></h2>

<!-- Account recovery - Reset code -->
<ng-container *ngSwitchCase="'resetPassword'">
<app-reset-password
<app-uuid
[reset]="true"
(canceled)="changeDisplay('forgetPassword')"
(validated)="changeDisplay('newPassword')"
></app-reset-password>
(validated)="changeDisplay('newPassword'); accountData = $event"
></app-uuid>
</ng-container>

<!-- Account recovery - New password -->
<ng-container *ngSwitchCase="'newPassword'">
<app-password
[reset]="true"
(canceled)="changeDisplay('resetPassword')"
(validated)="changeDisplay('logIn')"
(validated)="changeDisplay('logIn'); fromValidation = $event"
[accountData]="accountData"
></app-password>
</ng-container>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/app/modules/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class HomeComponent implements OnInit, OnDestroy {
logIn: FormGroup;
fromValidation: boolean = false;
stepForm = 'logIn';
public accountData = null;

constructor(
private router: Router,
Expand Down
2 changes: 0 additions & 2 deletions src/app/modules/home/home.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { HomeRoutingModule } from './home-routing.module';
import { UuidComponent } from './forms/uuid/uuid.component';
import { PasswordComponent } from './forms/password/password.component';
import { SignInComponent } from './forms/sign-in/sign-in.component';
import { ResetPasswordComponent } from './forms/reset-password/reset-password.component';
import { ForgetPasswordComponent } from './forms/forget-password/forget-password.component';
import { AuthService } from 'src/app/services/auth.service';
import { ApiService } from 'src/app/services/api.service';
Expand All @@ -18,7 +17,6 @@ import { PiaI18nModule } from '@atnos/pia-i18n';
UuidComponent,
PasswordComponent,
SignInComponent,
ResetPasswordComponent,
ForgetPasswordComponent
],
providers: [AuthService, ApiService],
Expand Down
51 changes: 39 additions & 12 deletions src/app/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,27 +143,54 @@ export class AuthService {
localStorage.setItem('currentUser', JSON.stringify(currentUser));
}

async checkUuid(uuid: string): Promise<boolean | Error> {
async checkUuid(uuid: string): Promise<User> {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(true);
}, 2000);
if (this.apiService && this.apiService.base) {
this.apiService
.get('/users/unlock_access/' + uuid)
.then((result: User) => {
resolve(result);
})
.catch(error => {
reject(error);
});
} else {
reject();
}
});
}

async checkPassword(password: string): Promise<boolean | Error> {
async sendPassword(
userId: number,
password: string,
confirmPassword: string
): Promise<any> {
const formData = new FormData();
formData.append('password', password);
formData.append('password_confirmation', confirmPassword);

return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(true);
}, 2000);
this.apiService
.put('/users/' + userId + '/change-password', formData)
.then((result: any) => {
resolve(result);
})
.catch(err => {
reject(err);
});
});
}

async reset(email: string): Promise<boolean | Error> {
async reset(email: string): Promise<User> {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(true);
}, 2000);
this.apiService
.get('/users/password-forgotten/' + email)
.then((result: User) => {
resolve(result);
})
.catch(err => {
reject(err);
});
});
}

Expand Down

0 comments on commit 35158b6

Please sign in to comment.