Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export class LoginPage implements OnInit {
- loginForm: FormGroup;
- loading = false;
- submitted = false;
- returnUrl: string;
- error = '';
- constructor(
- private formBuilder: FormBuilder,
- private route: ActivatedRoute,
- private router: Router,
- private authenticationService: AuthenticationService) {
- }
- ngOnInit() {
- this.loginForm = this.formBuilder.group({
- username: ['', Validators.required],
- password: ['', Validators.required]
- });
- // reset login status
- this.authenticationService.logout();
- // get return url from route parameters or default to '/'
- this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/';
- }
- /**
- * Convenience getter for easy access to form fields
- */
- get controls() {
- return this.loginForm.controls;
- }
- onSubmit() {
- this.submitted = true;
- // stop here if form is invalid
- if (this.loginForm.invalid) {
- return;
- }
- this.loading = true;
- this.authenticationService
- .login(this.controls.username.value, this.controls.password.value)
- .pipe(first())
- .subscribe(
- data => {
- console.log('url where we go ' + this.returnUrl); //return the good url
- console.log(data);
- this.router.navigateByUrl(this.returnUrl, { replaceUrl: true })
- .then(function(res) {
- console.log(res); //return true
- });
- },
- error => {
- this.error = error;
- this.loading = false;
- console.log(this.error);
- });
- }
Add Comment
Please, Sign In to add comment