本文整理汇总了TypeScript中ng2-ui-auth.AuthService类的典型用法代码示例。如果您正苦于以下问题:TypeScript AuthService类的具体用法?TypeScript AuthService怎么用?TypeScript AuthService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AuthService类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: intercept
intercept(
request: HttpRequest<any>,
next: HttpHandler
): Observable<HttpEvent<any>> {
if (!this.auth) {
this.auth = this.injector.get(AuthService);
}
if (this.auth.isAuthenticated()) {
request = request.clone({
setHeaders: {
'X-Auth-Token': this.auth.getToken()
}
});
}
// Add CSRF token for the Play CSRF filter
const token = this.cookieService.get('PLAY_CSRF_TOKEN');
if (token) {
// Play looks for a token with the name Csrf-Token
// https://www.playframework.com/documentation/2.4.x/ScalaCsrf
request = request.clone({
setHeaders: {
'Csrf-Token': token
}
});
}
return next.handle(request);
}
示例2: logout
logout(): void {
// clear token remove user from local storage to log user out
this.auth.logout()
.subscribe({
complete: () => {
this.localstorage.clear('client_id');
this.user = null;
// UIService.notify('You have been logged out', 'info');
// $state.go('login');
}
});
this.auth.removeToken();
this.router.navigateByUrl('/login');
}
示例3:
.map((response: Response) => {
let token = response.json() && response.json().token;
console.log(token);
if (typeof token !== 'undefined') {
this.auth.setToken(token);
if (this.auth.isAuthenticated() === true) {
this.getUserDetails();
if (this.user['default_client_id'] !== null) {
this.setDefaultClientId(this.user['default_client_id']);
}
return true;
}
}
return false;
});
示例4: isClientRole
isClientRole() {
if (this.auth.getPayload().data.role_id == 10) {
return true;
} else {
return false;
}
}
示例5: loginWithGoogle
loginWithGoogle() {
this.auth.authenticate('google')
.subscribe({
error: (err: any) => this.eh.handleError(err),
complete: () => this.router.navigateByUrl('main')
});
}
示例6: login
login(loginData: ILoginData) {
this.auth.login(loginData)
.subscribe({
error: (err: any) => this.eh.handleError(err),
complete: () => this.router.navigateByUrl('main')
});
}
示例7: logout
logout() {
this.auth.logout()
.subscribe({
error: (err: any) => this.eh.handleError(err),
complete: () => this.router.navigateByUrl('login')
});
}
示例8: getUserDetails
getUserDetails() {
var userDetails = this.auth.getPayload();
if (typeof userDetails !== 'undefined') {
this.user = userDetails.data;
} else {
return false;
}
}
示例9: canActivate
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
if (this.auth.isAuthenticated()) {
return true;
}
console.log('unauthenticated navigating to login');
this.router.navigateByUrl('/login');
return false;
}
示例10: link
link() {
this.auth.link('google')
.subscribe({
error: (err: any) => this.eh.handleError(err),
complete: () => {
this.expiration = this.auth.getExpirationDate();
this.user = this.auth.getPayload();
}
});
}