本文整理匯總了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();
}
});
}