Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Заявката до Експрес.
- authenticateUser(user) {
- const headers = new Headers();
- headers.append('Content-type', 'application/json');
- return this.http.post('http://localhost:3000/users/authenticate', user, {headers: headers})
- .map(res => res.json());
- }
- // Функцията която се извиква при натискане на събмит бутона.
- onLoginSubmit() {
- const user = {
- username: this.username,
- password: this.password
- };
- this.authService.authenticateUser(user).subscribe(data => {
- if (data.success) {
- this.authService.storeUserData(data.token, data.user);
- this.flashMessages.show(data.msg, {cssClass: 'alert-success', timeout: 5000});
- this.router.navigate(['/']);
- } else {
- this.flashMessages.show(data.msg, {cssClass: 'alert-danger', timeout: 5000});
- this.router.navigate(['login']);
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement