本文整理汇总了TypeScript中src/app/service/auth.service.AuthService类的典型用法代码示例。如果您正苦于以下问题:TypeScript service.AuthService类的具体用法?TypeScript service.AuthService怎么用?TypeScript service.AuthService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了service.AuthService类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
this.authService.authenticateUser(this.user).subscribe((data: any) => {
if (data.success) {
console.log('logged in', data);
this.authService.storeUserData(data.token, data.user);
this.router.navigate(['dashboard']);
} else {
console.log('not logged in', data);
this.router.navigate(['login']);
}
});
示例2: onRegisterSubmit
onRegisterSubmit() {
console.log(this.user);
if (!this.validateService.validateRegister(this.user)) {
this.flashMessagesService.show('Please fill out all the form fields', { cssClass: 'alert-danger', timeout: 5000 });
return false;
}
if (!this.validateService.validateEmail(this.user.email)) {
this.flashMessagesService.show('Please enter a valid email', { cssClass: 'alert-danger', timeout: 5000 });
return false;
}
this.authService.registerUser(this.user).subscribe((data: any) => {
if (data.success) {
this.flashMessagesService.show('You are now registered', { cssClass: 'alert-success', timeout: 5000 });
this.router.navigate(['/login']);
} else {
this.flashMessagesService.show('Something went wrong', { cssClass: 'alert-danger', timeout: 5000 });
this.router.navigate(['/register']);
}
});
}
示例3: onLogoutClick
onLogoutClick() {
this.authService.logout();
this.router.navigate(['/login']);
}
示例4: ngOnInit
ngOnInit() {
this.authService.getCurrentUser().subscribe(data =>
console.log(data));
}