Added better routing and auto logout on login
Note that this is fully working auth login now
This commit is contained in:
parent
c7810de2b6
commit
845b166364
5 changed files with 27 additions and 9 deletions
|
@ -1,18 +1,20 @@
|
|||
import { Component } from '@angular/core';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Validators, FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { Http, Response } from '@angular/http';
|
||||
import { ApiService } from '../providers/api-service';
|
||||
import {Router } from '@angular/router';
|
||||
import { Router, ActivatedRoute } from '@angular/router';
|
||||
import 'rxjs/add/operator/map';
|
||||
|
||||
@Component({
|
||||
templateUrl: 'login.component.html',
|
||||
providers: [ApiService]
|
||||
})
|
||||
export class LoginComponent {
|
||||
export class LoginComponent implements OnInit {
|
||||
signin: FormGroup;
|
||||
returnUrl: string;
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private http: Http,
|
||||
private formBuilder: FormBuilder,
|
||||
private router: Router,
|
||||
|
@ -24,6 +26,20 @@ export class LoginComponent {
|
|||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
// reset login status
|
||||
this.api
|
||||
.logout()
|
||||
.subscribe(
|
||||
result => {
|
||||
console.log('Logged out!');
|
||||
}
|
||||
);
|
||||
|
||||
// get return url from route parameters or default to '/'
|
||||
this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/';
|
||||
}
|
||||
|
||||
onSubmit() {
|
||||
console.log(this.signin.value);
|
||||
|
||||
|
@ -32,7 +48,7 @@ export class LoginComponent {
|
|||
.subscribe(
|
||||
result => {
|
||||
console.log('logged in!');
|
||||
this.router.navigate(['/dashboard'])
|
||||
this.router.navigate([this.returnUrl]);
|
||||
},
|
||||
error => {
|
||||
console.log( error._body );
|
||||
|
|
Reference in a new issue