Waiting for token reset

This commit is contained in:
Fergal Moran
2018-05-06 23:23:23 +01:00
parent c0bf822fe0
commit fd45069103
16 changed files with 190 additions and 57 deletions

View File

@@ -16,7 +16,7 @@ import { ProgressbarModule } from 'ngx-bootstrap/progressbar';
import { AngularFireDatabaseModule } from 'angularfire2/database';
import { AngularFireAuthModule } from 'angularfire2/auth';
import { AngularFireModule } from 'angularfire2';
import { QuillModule } from 'ngx-quill'
import { QuillModule } from 'ngx-quill';
import { SocialLoginModule, AuthServiceConfig } from 'angularx-social-login';
import {

View File

@@ -1,6 +1,7 @@
import { Component, OnInit, ReflectiveInjector } from '@angular/core';
import { AppInsightsService } from '../../services/app-insights.service';
import { environment } from 'environments/environment';
import { DomSanitizer } from '@angular/platform-browser';
@Component({
selector: 'app-base-page',
template: ''
@@ -18,4 +19,10 @@ export class BasePageComponent {
private logNavigation() {
this._appInsightsService.logPageView();
}
protected formatError(error: string): string {
return `${error}<br />Please visit <a href="${
environment.HELP_URL
}">here</a> and request help.`;
}
}

View File

@@ -49,8 +49,7 @@
</div>
</div>
</div>
<div class="alert alert-danger" *ngIf="errorMessage" role="alert">
{{errorMessage}}
<div class="alert alert-danger" *ngIf="errorMessage" role="alert" [innerHTML]="errorMessage">
</div>
<div class="col-md-12 new-user-alert" *ngIf="brandNew">
<div class="alert alert-success" role="alert">

View File

@@ -39,8 +39,7 @@
</div>
</div>
</div>
<div class="alert alert-danger" *ngIf="errorMessage" role="alert">
{{errorMessage}}
<div class="alert alert-danger" *ngIf="errorMessage" [innerHTML]="errorMessage">
</div>
<div class="form-group row gutters-tiny">
<div class="col-12 mb-10">

View File

@@ -1,8 +1,6 @@
<div id="page-container"
class="main-content-boxed">
<div id="page-container" class="main-content-boxed">
<main id="main-container">
<div class="bg-image"
style="background-image: url('/assets/img/robothand.jpg'); background-size: 100% 100%;">
<div class="bg-image" style="background-image: url('/assets/img/robothand.jpg'); background-size: 100% 100%;">
<div class="hero-static content content-full bg-white">
<div class="text-center">
<a class="link-effect font-w700">
@@ -14,45 +12,48 @@
</div>
<div class="row justify-content-center">
<div class="col-sm-8 col-md-6 col-xl-4">
<form class="js-validation-signin"
action=""
(ngSubmit)="resetPassword()"
method="post">
<div class="form-group row">
<form class="js-validation-signin" action="" (ngSubmit)="resetPassword()" method="post">
<div class="form-group row" *ngIf="noToken">
<div class="col-12">
<div class="form-material floating">
<input type="text"
class="form-control"
id="login-username"
name="login-username"
[(ngModel)]="username">
<input type="text" class="form-control" id="login-username" name="login-username" [(ngModel)]="username">
<label for="login-username">Email Address</label>
</div>
</div>
</div>
<div class="alert alert-danger"
*ngIf="errorMessage"
role="alert">
{{errorMessage}}
<div class="form-group row" *ngIf="!noToken">
<div class="col-12">
<div class="form-material ">
<input type="password" class="form-control" id="login-password" name="login-password" [(ngModel)]="newPassword">
<label for="login-password">New password</label>
</div>
</div>
</div>
<div class="form-group row gutters-tiny"
*ngIf="successMessage">
<div class="col-12 mb-10">
<div class="alert alert-success"
role="alert">
<div class="form-group row" *ngIf="!noToken">
<div class="col-12 ">
<div class="form-material ">
<input type="password " class="form-control " id="login-password2 " name="login-password2
" [(ngModel)]="newPasswordRepeat ">
<label for="login-password ">Repeat password</label>
</div>
</div>
</div>
<div class="alert alert-danger " *ngIf="errorMessage " role="alert " [innerHTML]="errorMessage ">
</div>
<div class="form-group row gutters-tiny " *ngIf="successMessage ">
<div class="col-12 mb-10 ">
<div class="alert alert-success " role="alert ">
<strong>Success!</strong> {{successMessage}}
</div>
</div>
</div>
<div class="form-group row gutters-tiny">
<div class="col-12 mb-10">
<a [routerLink]="['']"
*ngIf="successMessage"
class="btn btn-block btn-hero btn-noborder btn-rounded btn-alt-secondary">Go Home..</a>
<button type="submit"
*ngIf="!successMessage"
class="btn btn-block btn-hero btn-noborder btn-rounded btn-alt-primary">
<i class="si si-reload mr-10"></i> Reset Password
<div class="form-group row gutters-tiny ">
<div class="col-12 mb-10 ">
<a [routerLink]="[ ''] " *ngIf="successMessage " class="btn btn-block btn-hero btn-noborder
btn-rounded btn-alt-secondary ">Go Home..</a>
<button type="submit " *ngIf="!successMessage " class="btn btn-block btn-hero btn-noborder
btn-rounded btn-alt-primary ">
<i class="si si-reload mr-10 "></i> Reset Password
</button>
</div>
</div>

View File

@@ -3,6 +3,7 @@ import { Component, OnInit } from '@angular/core';
import 'rxjs/add/operator/catch';
import { Observable } from 'rxjs/Observable';
import { BasePageComponent } from '../base-page/base-page.component';
import { AppInsightsService } from '../../services/app-insights.service';
@Component({
selector: 'app-reset',
@@ -13,23 +14,41 @@ export class ResetComponent extends BasePageComponent implements OnInit {
username: string;
errorMessage: string;
successMessage: string;
constructor(private _authService: PodnomsAuthService) {
noToken: boolean = true;
newPassword: string;
newPasswordRepeat: string;
constructor(
private _authService: PodnomsAuthService,
private _insightsService: AppInsightsService
) {
super();
}
ngOnInit() {}
resetPassword() {
if (this.username) {
this._authService.resetPassword(this.username);
// .catch(err => {
// this.errorMessage = err.description;
// return Observable.of(`Error resetting password: ${err.description}`);
// })
// .subscribe(result => {
// console.log('reset.component.ts', 'method', result);
// this.errorMessage = '';
// this.successMessage = `A password reset link has been sent to ${this.username}`;
// });
this._authService.resetPassword(this.username).subscribe(
(result) => {
if (result.status === 200) {
console.log('reset.component.ts', 'method', result);
this.errorMessage = '';
this.successMessage = `A password reset link has been sent to ${
this.username
}`;
} else {
this.errorMessage =
'Unable to reset your password\nPlease visit https://talk.podnoms.com and request help.';
}
},
(err) => {
this.errorMessage = this.formatError(
'Unable to reset your password'
);
this._insightsService.logEvent('client_error', {
message: err.message
});
}
);
} else {
this.errorMessage = 'Please enter your email address';
}

View File

@@ -127,6 +127,15 @@ export class PodnomsAuthService extends BaseService {
window.location.reload(true);
}, 0);
}
public resetPassword(userName: string) {}
public loginSocial(provider: string): void {}
public resetPassword(userName: string): Observable<Response> {
const body = JSON.stringify({
email: userName
});
return this._http
.post<Response>(
environment.API_HOST + '/auth/forgotpassword',
body,
this.httpOptions
);
}
}

View File

@@ -4,7 +4,11 @@ export const environment = {
API_HOST: 'https://api.podnoms.com',
SIGNALR_HOST: 'https://rt.podnoms.com',
BASE_URL: 'https://podnoms.com',
HELP_URL: 'https://talk.podnoms.com',
appInsights: {
instrumentationKey: '020b002a-bd3d-4b25-8a74-cab16fd39dfc'
},
messaging: {
endpoint: 'https://fcm.googleapis.com/fcm/send'
}
};

View File

@@ -7,6 +7,7 @@ export const environment = {
DOMAIN: 'localhost',
SIGNALR_HOST: ROOT_URL,
BASE_URL: 'http://localhost:4200/',
HELP_URL: 'https://talk.podnoms.com',
appInsights: {
instrumentationKey: '020b002a-bd3d-4b25-8a74-cab16fd39dfc'
},