Browse Source

Merge branch 'features' of onunez/soma-frontend into development

Oscar José Nuñez Chávez 5 years ago
parent
commit
41df037be6

+ 9 - 0
src/app/components/new-password/new-password.component.html

@@ -11,7 +11,16 @@
         <div class="card">
         <div class="card">
           <div *ngIf="!newPass" class="header">
           <div *ngIf="!newPass" class="header">
             <h1 class="lead">{{ errorMessage }}</h1>
             <h1 class="lead">{{ errorMessage }}</h1>
+
+            <div *ngIf="sendOtherToken">
+              <div class="tokenExpired">
+                <a class="btn btn-primary" (click)="getNewToken()">
+                  Enviar nuevo correo para recuperar contraseña
+                </a>
+              </div>
+            </div>
           </div>
           </div>
+
           <div class="header" *ngIf="newPass">
           <div class="header" *ngIf="newPass">
             <h1 class="lead">Nueva contraseña</h1>
             <h1 class="lead">Nueva contraseña</h1>
           </div>
           </div>

+ 69 - 10
src/app/components/new-password/new-password.component.ts

@@ -25,6 +25,8 @@ export class NewPasswordComponent implements OnInit {
   submitted: boolean = false;
   submitted: boolean = false;
   showDetails: boolean;
   showDetails: boolean;
   newPass: boolean;
   newPass: boolean;
+  userData: any;
+  sendOtherToken: boolean;
 
 
   constructor(
   constructor(
     private formBuilder: FormBuilder,
     private formBuilder: FormBuilder,
@@ -37,6 +39,12 @@ export class NewPasswordComponent implements OnInit {
   }
   }
 
 
   ngOnInit() {
   ngOnInit() {
+    Swal.fire({
+      allowOutsideClick: false,
+      type: "info",
+      text: "Espere por favor...",
+    });
+    Swal.showLoading();
     if (this.token !== null) {
     if (this.token !== null) {
       this.userService
       this.userService
         .validateUserToken({
         .validateUserToken({
@@ -45,8 +53,9 @@ export class NewPasswordComponent implements OnInit {
         })
         })
         .subscribe(
         .subscribe(
           (res) => {
           (res) => {
-            console.log(res);
-            let userData = res["data"].user;
+            Swal.close();
+            this.sendOtherToken = false;
+            this.userData = res["data"].user;
             this.newPass = true;
             this.newPass = true;
             this.validToken = true;
             this.validToken = true;
             this.activateForm = this.formBuilder.group(
             this.activateForm = this.formBuilder.group(
@@ -68,10 +77,12 @@ export class NewPasswordComponent implements OnInit {
             );
             );
           },
           },
           (err) => {
           (err) => {
+            Swal.close();
             this.newPass = false;
             this.newPass = false;
             this.userActivated = true;
             this.userActivated = true;
             this.invalidToken = true;
             this.invalidToken = true;
             this.errorMessage = err.message;
             this.errorMessage = err.message;
+            this.sendOtherToken = true;
           }
           }
         );
         );
     } else {
     } else {
@@ -80,6 +91,38 @@ export class NewPasswordComponent implements OnInit {
     }
     }
   }
   }
 
 
+  getNewToken() {
+    Swal.fire({
+      allowOutsideClick: false,
+      type: "info",
+      text: "Espere por favor...",
+    });
+    Swal.showLoading();
+    this.userService
+      .sendAnotherToken({
+        token: this.token,
+      })
+      .subscribe(
+        (res) => {
+          Swal.fire({
+            type: "success",
+            title: "Exito",
+            text: "Se ha enviado otro correo para recuperación de contraseña",
+          }).then((result) => {
+            this.successActivation = true;
+            this.validToken = false;
+            this.invalidToken = false;
+            window.location.href = "#/investment-proposals";
+          });
+        },
+        (err) => {
+          Swal.close();
+          this.validToken = false;
+          this.errorMessage = err.message;
+        }
+      );
+  }
+
   get f() {
   get f() {
     return this.activateForm.controls;
     return this.activateForm.controls;
   }
   }
@@ -91,24 +134,40 @@ export class NewPasswordComponent implements OnInit {
     if (this.activateForm.invalid) {
     if (this.activateForm.invalid) {
       return;
       return;
     }
     }
-
+    Swal.fire({
+      allowOutsideClick: false,
+      type: "info",
+      text: "Espere por favor...",
+    });
+    Swal.showLoading();
     this.userService
     this.userService
       .changePassword({
       .changePassword({
         password: this.f.password.value,
         password: this.f.password.value,
         confirm_password: this.f.confirm_password.value,
         confirm_password: this.f.confirm_password.value,
-        /*phone_number: this.f.phone_number.value,
-        distribuidora: this.f.distribuidora.value,
-        cod_tarifa: this.f.cod_tarifa.value*/
+        email: this.userData.email,
+        first_name: this.userData.first_name,
+        last_name: this.userData.last_name,
+        phone_number: this.userData.phone_number,
       })
       })
       .subscribe(
       .subscribe(
         (res) => {
         (res) => {
-          this.successActivation = true;
-          this.validToken = false;
-          this.activateMessage = "Su clave ha sido actualizada exitosamente";
+          Swal.fire({
+            type: "success",
+            title: "Exito",
+            text: "Su clave ha sido actualizada exitosamente",
+          }).then((result) => {
+            this.successActivation = true;
+            this.validToken = false;
+            window.location.href = "#/investment-proposals";
+          });
         },
         },
         (err) => {
         (err) => {
+          Swal.fire({
+            type: "error",
+            title: "Error en el servidor",
+            text: err.message,
+          });
           this.validToken = false;
           this.validToken = false;
-          this.errorMessage = err.message;
         }
         }
       );
       );
     //
     //

+ 4 - 0
src/app/services/user.service.ts

@@ -172,6 +172,10 @@ export class UserService {
   changePassword(user: {
   changePassword(user: {
     password: string;
     password: string;
     confirm_password: string;
     confirm_password: string;
+    first_name: string;
+    last_name: string;
+    email: string;
+    phone_number: string;
   }): Observable<boolean> {
   }): Observable<boolean> {
     return this.http
     return this.http
       .post<any>(`${environment.productionApiUrl}/user/change-password`, user)
       .post<any>(`${environment.productionApiUrl}/user/change-password`, user)