Package Exports
- angular-authentication-service
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (angular-authentication-service) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
AngularAuthenticationService
This project was generated with Angular CLI version 1.4.1. This is only a TEST.
##Install with NPM $ npm install angular-authentication-service
##component module import { FormControl, FormControlName, FormGroup, Validators } from '@angular/forms'; import { AuthenticationService,User,LogIn } from 'angular-authentication-service';
export class LoginComponent implements OnInit { @Input() loading: boolean = false; user: User; credentials: LogIn;
@Input() error: string = '';
form = new FormGroup({
username: new FormControl('', [Validators.required, Validators.minLength(3)]),
password: new FormControl('', [Validators.required, Validators.minLength(8)])
});
get username(): any { return this.form.get('username'); }
get password(): any { return this.form.get('password'); }
constructor(private globalservice: GlobalVarsService,private authenticationservice: AuthenticationService){
}
ngOnInit() {
// reset login status
this.user = new User;
this.credentials = new LogIn;
this.credentials.app = "MyAppName";
this.loading = false;
this.error = '';
}
login(): void {
this.loading = true;
this.authenticationservice.login(this.credentials).subscribe(data => {
if (data) {
this.user = data;
this.globalservice.UserData = data;
localStorage.setItem('token', data.access_token);
this.globalservice.isAuthenticated = true;
//this.router.navigate(['home']);
} else {
this.newFunction();
this.loading = false;
localStorage.setItem('token', '');
this.globalservice.isAuthenticated = false;
}
}, err => {
this.handleError(err);
});
}
handleError = function (err) {
this.loading = false;
if (err.status) {
this.error = err.status + ': ' + err.statusText;
} else {
this.error = err.message;
}
localStorage.setItem('token', '');
this.globalservice.authenticated(false);
}}