Skip to content

Commit

Permalink
Service gửi thông tin người dùng cho server
Browse files Browse the repository at this point in the history
  • Loading branch information
hoanphi2201 committed Apr 6, 2019
1 parent f98d1e6 commit 5e80344
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Management/src/app/pages/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ export class LoginComponent implements OnInit, AfterViewInit {
if (res && !res.error) {
console.log(res);
const data = Object.assign(res, response.authResponse);
this.authenticationService.loginFacebook(data).subscribe(
(user: any) => {
localStorage.setItem('accessToken', response.authResponse.accessToken);
showNotification('top', 'right', 300, `Xin chào ${user.name} `);
this.router.navigate([this.returnUrl]);
}
);
}
}
);
Expand Down Expand Up @@ -145,7 +152,12 @@ export class LoginComponent implements OnInit, AfterViewInit {
id: profile.getId(),
avatar: profile.getImageUrl()
};

this.authenticationService.loginGoogle(data).subscribe(
(user: any) => {
showNotification('top', 'right', 300, `Xin chào ${user.name} `);
this.router.navigate([this.returnUrl]);
}
);

}, (error) => {
showNotification('top', 'right', 300, `Rất tiếc, đã xảy ra lỗi !`);
Expand Down
27 changes: 27 additions & 0 deletions Management/src/app/shared/services/authentication.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,33 @@ export class AuthenticationService {
private router: Router) {

}
login(username: string, password: string): Observable<any> {
return this._httpService.post(`${AppSettings.API_ENDPOINT}/auth/user/login`, { username: username, password: password }, {
withCredentials: true
}).pipe(
tap(_ => {}),
catchError(this.handleError<any>('login'))
);

}

loginFacebook(data: any): Observable<any> {
return this._httpService.post(`${AppSettings.API_ENDPOINT}/auth/user/login-facebook`, data, {
withCredentials: true
}).pipe(
tap(_ => {}),
catchError(this.handleError<any>('loginFacebook'))
);

}
loginGoogle(data: any): Observable<any> {
return this._httpService.post(`${AppSettings.API_ENDPOINT}/auth/user/login-google`, data, {
withCredentials: true
}).pipe(
tap(_ => {}),
catchError(this.handleError<any>('loginGoogle'))
);
}
private handleError<T> (operation = 'operation', result?: T) {
return (error: any): Observable<T> => {
this.router.navigate(['/pages', 'errors']);
Expand Down

0 comments on commit 5e80344

Please sign in to comment.