| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- import { Component, OnInit, ViewChild } from "@angular/core";
- import { ActivatedRoute } from "@angular/router";
- import { FormGroup, FormBuilder, Validators } from "@angular/forms";
- import { UserService } from "@app/services/user.service";
- import Swal from "sweetalert2";
- import {
- ValidatorComponent,
- PasswordStrengthValidator,
- } from "../plugins/validator/validator.component";
- @Component({
- selector: "app-new-password",
- templateUrl: "./new-password.component.html",
- styleUrls: ["./new-password.component.scss"],
- })
- export class NewPasswordComponent implements OnInit {
- token: string;
- validToken: boolean;
- activateForm: FormGroup;
- errorMessage: string;
- userActivated: boolean;
- successActivation: boolean;
- activateMessage: string;
- invalidToken: boolean;
- submitted: boolean = false;
- showDetails: boolean;
- newPass: boolean;
- userData: any;
- sendOtherToken: boolean;
- constructor(
- private formBuilder: FormBuilder,
- private route: ActivatedRoute,
- private userService: UserService
- ) {
- this.route.queryParams.subscribe((params) => {
- this.token = params["token"];
- });
- }
- ngOnInit() {
- Swal.fire({
- allowOutsideClick: false,
- type: "info",
- text: "Espere por favor...",
- });
- Swal.showLoading();
- if (this.token !== null) {
- this.userService
- .validateUserToken({
- token: this.token,
- process: "pwd_recovery",
- })
- .subscribe(
- (res) => {
- Swal.close();
- this.sendOtherToken = false;
- this.userData = res["data"].user;
- this.newPass = true;
- this.validToken = true;
- this.activateForm = this.formBuilder.group(
- {
- // Load information
- password: [
- "",
- [
- Validators.required,
- Validators.minLength(8),
- PasswordStrengthValidator,
- ],
- ],
- confirm_password: ["", Validators.required],
- },
- {
- validator: ValidatorComponent("password", "confirm_password"),
- }
- );
- },
- (err) => {
- Swal.close();
- this.newPass = false;
- this.userActivated = true;
- this.invalidToken = true;
- this.errorMessage = err.message;
- this.sendOtherToken = true;
- }
- );
- } else {
- this.invalidToken = true;
- this.errorMessage = "No existe el token";
- }
- }
- 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() {
- return this.activateForm.controls;
- }
- newPassword() {
- this.submitted = true;
- // stop here if form is invalid
- if (this.activateForm.invalid) {
- return;
- }
- Swal.fire({
- allowOutsideClick: false,
- type: "info",
- text: "Espere por favor...",
- });
- Swal.showLoading();
- this.userService
- .changePassword({
- password: this.f.password.value,
- confirm_password: this.f.confirm_password.value,
- email: this.userData.email,
- first_name: this.userData.first_name,
- last_name: this.userData.last_name,
- phone_number: this.userData.phone_number,
- })
- .subscribe(
- (res) => {
- 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) => {
- Swal.fire({
- type: "error",
- title: "Error en el servidor",
- text: err.message,
- });
- this.validToken = false;
- }
- );
- //
- }
- }
- /*
- Swal.fire({
- allowOutsideClick: false,
- type: 'info',
- text: 'Espere por favor...'
- });
- Swal.showLoading();
- this.authService.login(
- {
- email: this.f.email.value,
- password: this.f.password.value
- }
- )
- .subscribe(success => {
- if (success) {
- window.location.href="#/dashboard";
- }
- else {
- Swal.fire({
- type: 'error',
- title: 'No se pudo auntenticar',
- text: "Email o contraseña incorrecta"
- })
- }
- },(err) => {
- Swal.fire({
- type: 'error',
- title: 'Error en el servidor',
- text: "No su pudo obtener la informacion"
- });
- });
- */
|