diff --git a/ng-seed/src/app/session-services/session.service.ts b/ng-seed/src/app/session-services/session.service.ts index 936dcde..9369c57 100644 --- a/ng-seed/src/app/session-services/session.service.ts +++ b/ng-seed/src/app/session-services/session.service.ts @@ -1,7 +1,7 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { environment } from 'environments/environment'; -import { Observable, of } from 'rxjs'; +import { BehaviorSubject, Observable, of } from 'rxjs'; import { catchError } from 'rxjs/operators'; @Injectable({ @@ -9,7 +9,14 @@ import { catchError } from 'rxjs/operators'; }) export class SessionService { private apiUrl = environment.apiEndpoint; - constructor(private _http: HttpClient) { } + private nameSource = new BehaviorSubject(''); + name = this.nameSource.asObservable() + + constructor(private _http: HttpClient) { } + + getForgotDetails(params) { + this.nameSource.next(params); + } getLoginToken(params): Observable { console.log(params.email) @@ -23,4 +30,10 @@ export class SessionService { // return this._http.post(this.apiUrl + 'login', {'email':params.email,'password':params.password}) } + resetPasswordApi(forgotDetails,resetPassword): Observable { + console.log(forgotDetails,resetPassword) + return this._http.post(this.apiUrl + "reset-password/"+forgotDetails.email+'/'+forgotDetails.token,resetPassword) + // return this._http.post(this.apiUrl + 'login', {'email':params.email,'password':params.password}) + } + } diff --git a/ng-seed/src/app/session/forgot-password/forgot-password.component.ts b/ng-seed/src/app/session/forgot-password/forgot-password.component.ts index dea418b..2fd140d 100644 --- a/ng-seed/src/app/session/forgot-password/forgot-password.component.ts +++ b/ng-seed/src/app/session/forgot-password/forgot-password.component.ts @@ -32,6 +32,7 @@ export class ForgotPasswordComponent { this._ser.getForgotToken(forgotMail).subscribe(res => { console.log(res) this.forgotTokenEmail = res + this._ser.getForgotDetails(this.forgotTokenEmail) this.router.navigate(['authentication/reset-password']) }, err => { diff --git a/ng-seed/src/app/session/login/login.component.ts b/ng-seed/src/app/session/login/login.component.ts index 48ca04c..2da3c72 100644 --- a/ng-seed/src/app/session/login/login.component.ts +++ b/ng-seed/src/app/session/login/login.component.ts @@ -69,7 +69,7 @@ export class LoginComponent { } openForgot() { - this.router.navigate(['/forgot-password']); + this.router.navigate(['authentication/forgot-password']) // this.router.navigate(['/home']) } diff --git a/ng-seed/src/app/session/reset-password/reset-password.component.ts b/ng-seed/src/app/session/reset-password/reset-password.component.ts index 9acbd3e..e8973fd 100644 --- a/ng-seed/src/app/session/reset-password/reset-password.component.ts +++ b/ng-seed/src/app/session/reset-password/reset-password.component.ts @@ -1,5 +1,7 @@ import { Component, OnInit, ViewEncapsulation } from '@angular/core'; import { FormControl, FormGroup, Validators } from '@angular/forms'; +import { Router } from '@angular/router'; +import { SessionService } from 'app/session-services/session.service'; @Component({ selector: 'app-reset-password', @@ -9,10 +11,16 @@ import { FormControl, FormGroup, Validators } from '@angular/forms'; }) export class ResetPasswordComponent implements OnInit { form: FormGroup; + forgotApiDetails: string; - constructor() { } + constructor(private router: Router,public _ser:SessionService) { } ngOnInit(): void { + this._ser.name.subscribe(data=>{ + this.forgotApiDetails = data; + console.log(this.forgotApiDetails) + }); + this.form = new FormGroup({ password: new FormControl('',[Validators.required,Validators.maxLength(10)]), password2: new FormControl('',[Validators.required,Validators.maxLength(10)]), @@ -24,14 +32,17 @@ export class ResetPasswordComponent implements OnInit { submit(){ console.log(this.form.value) - return; - // this._ser.getForgotToken(forgotMail).subscribe(res => { - // console.log(res) - // this.forgotTokenEmail = res - // }, err => { + this._ser.resetPasswordApi(this.forgotApiDetails,this.form.value).subscribe(res => { + console.log(res) + if(res.status == 200){ + this.router.navigate(['authentication/login']) + } - // //alert(err.message); - // }) + // this.forgotTokenEmail = res + }, err => { + + //alert(err.message); + }) }