Basic Error messages and some correct valid added to login & register
This commit is contained in:
parent
c9b994a11e
commit
b45bc19ba7
4 changed files with 38 additions and 3 deletions
|
@ -16,9 +16,19 @@
|
||||||
<span class="input-group-addon"><i class="icon-lock"></i></span>
|
<span class="input-group-addon"><i class="icon-lock"></i></span>
|
||||||
<input type="password" class="form-control" formControlName="password" placeholder="Password">
|
<input type="password" class="form-control" formControlName="password" placeholder="Password">
|
||||||
</div>
|
</div>
|
||||||
|
<div class="mb-4">
|
||||||
|
<div [ngSwitch]="loginStatus">
|
||||||
|
<div *ngSwitchCase="'success'" class="alert alert-success" role="alert">
|
||||||
|
Login Succeeded, routing to homepage.
|
||||||
|
</div>
|
||||||
|
<div *ngSwitchCase="'send_failed'" class="alert alert-danger" role="alert">
|
||||||
|
Error received, please try again.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-6">
|
<div class="col-6">
|
||||||
<button type="submit" class="btn btn-primary px-4">Login</button>
|
<button type="submit" [disabled]="!signin.valid" class="btn btn-primary px-4">Login</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-6 text-right">
|
<div class="col-6 text-right">
|
||||||
<button type="button" class="btn btn-link px-0">Forgot password?</button>
|
<button type="button" class="btn btn-link px-0">Forgot password?</button>
|
||||||
|
|
|
@ -12,6 +12,7 @@ import 'rxjs/add/operator/map';
|
||||||
export class LoginComponent implements OnInit {
|
export class LoginComponent implements OnInit {
|
||||||
signin: FormGroup;
|
signin: FormGroup;
|
||||||
returnUrl: string;
|
returnUrl: string;
|
||||||
|
loginStatus: any;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
|
@ -52,10 +53,14 @@ export class LoginComponent implements OnInit {
|
||||||
.subscribe(
|
.subscribe(
|
||||||
result => {
|
result => {
|
||||||
console.log('logged in!');
|
console.log('logged in!');
|
||||||
|
this.loginStatus = "success";
|
||||||
|
console.log(this.loginStatus);
|
||||||
this.router.navigate([this.returnUrl]);
|
this.router.navigate([this.returnUrl]);
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
console.log( error._body );
|
console.log( error._body );
|
||||||
|
this.loginStatus = "send_failed";
|
||||||
|
console.log(this.loginStatus);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,6 +134,17 @@
|
||||||
</div>
|
</div>
|
||||||
<div heading="Pending" *ngSwitchDefault>Please Select a User Type</div>
|
<div heading="Pending" *ngSwitchDefault>Please Select a User Type</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div [ngSwitch]="registerStatus">
|
||||||
|
<div *ngSwitchCase="'success'" class="alert alert-success" role="alert">
|
||||||
|
Register Succeeded.
|
||||||
|
</div>
|
||||||
|
<div *ngSwitchCase="'validation_failed'" class="alert alert-danger" role="alert">
|
||||||
|
Form validation failed, please ensure the form is filled.
|
||||||
|
</div>
|
||||||
|
<div *ngSwitchCase="'send_failed'" class="alert alert-danger" role="alert">
|
||||||
|
Failed to send to server, please try again later.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -16,6 +16,7 @@ export class RegisterComponent {
|
||||||
customerForm: ValidationManager;
|
customerForm: ValidationManager;
|
||||||
organisationForm: ValidationManager;
|
organisationForm: ValidationManager;
|
||||||
years: Object[];
|
years: Object[];
|
||||||
|
registerStatus: any;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private http: Http,
|
private http: Http,
|
||||||
|
@ -57,6 +58,8 @@ export class RegisterComponent {
|
||||||
console.log(this.signupForm.isValid());
|
console.log(this.signupForm.isValid());
|
||||||
if (!this.signupForm.isValid() && !this.customerForm.isValid()) {
|
if (!this.signupForm.isValid() && !this.customerForm.isValid()) {
|
||||||
console.log("Not Valid!");
|
console.log("Not Valid!");
|
||||||
|
this.registerStatus = "validation_failed";
|
||||||
|
console.log(this.registerStatus);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let signupForm = this.signupForm.getForm().value;
|
let signupForm = this.signupForm.getForm().value;
|
||||||
|
@ -90,6 +93,8 @@ export class RegisterComponent {
|
||||||
console.log(this.signupForm.isValid());
|
console.log(this.signupForm.isValid());
|
||||||
if (!this.signupForm.isValid() || !this.organisationForm.isValid()) {
|
if (!this.signupForm.isValid() || !this.organisationForm.isValid()) {
|
||||||
console.log("Not Valid!");
|
console.log("Not Valid!");
|
||||||
|
this.registerStatus = "validation_failed";
|
||||||
|
console.log(this.registerStatus);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let signupForm = this.signupForm.getForm().value;
|
let signupForm = this.signupForm.getForm().value;
|
||||||
|
@ -112,10 +117,14 @@ export class RegisterComponent {
|
||||||
.subscribe(
|
.subscribe(
|
||||||
result => {
|
result => {
|
||||||
console.log('registered!');
|
console.log('registered!');
|
||||||
|
this.registerStatus = "success";
|
||||||
|
console.log(this.registerStatus);
|
||||||
this.router.navigate(['/dashboard']);
|
this.router.navigate(['/dashboard']);
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
console.log( error._body );
|
console.log( error._body );
|
||||||
|
this.registerStatus = "send_failed";
|
||||||
|
console.log(this.registerStatus);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue