mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-24 17:31:52 +00:00
[ACA-1811] redirect url for login (#645)
* redirect url for login * cleanup code
This commit is contained in:
@@ -69,6 +69,7 @@ import { AppCurrentUserModule } from './components/current-user/current-user.mod
|
||||
import { AppSearchInputModule } from './components/search/search-input.module';
|
||||
import { AppSearchResultsModule } from './components/search/search-results.module';
|
||||
import { AppLoginModule } from './components/login/login.module';
|
||||
import { AppAuthGuard } from './guards/auth.guard';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
@@ -119,6 +120,7 @@ import { AppLoginModule } from './components/login/login.module';
|
||||
source: 'assets'
|
||||
}
|
||||
},
|
||||
AppAuthGuard,
|
||||
ContentManagementService,
|
||||
NodeActionsService,
|
||||
NodePermissionService,
|
||||
|
@@ -24,7 +24,6 @@
|
||||
*/
|
||||
|
||||
import { Routes } from '@angular/router';
|
||||
import { AuthGuardEcm } from '@alfresco/adf-core';
|
||||
import { LayoutComponent } from './components/layout/layout.component';
|
||||
import { FilesComponent } from './components/files/files.component';
|
||||
import { LibrariesComponent } from './components/libraries/libraries.component';
|
||||
@@ -32,6 +31,7 @@ import { GenericErrorComponent } from './components/common/generic-error/generic
|
||||
import { SearchResultsComponent } from './components/search/search-results/search-results.component';
|
||||
import { ProfileResolver } from './services/profile.resolver';
|
||||
import { LoginComponent } from './components/login/login.component';
|
||||
import { AppAuthGuard } from './guards/auth.guard';
|
||||
|
||||
export const APP_ROUTES: Routes = [
|
||||
{
|
||||
@@ -235,7 +235,7 @@ export const APP_ROUTES: Routes = [
|
||||
component: GenericErrorComponent
|
||||
}
|
||||
],
|
||||
canActivateChild: [AuthGuardEcm],
|
||||
canActivate: [AuthGuardEcm]
|
||||
canActivateChild: [AppAuthGuard],
|
||||
canActivate: [AppAuthGuard]
|
||||
}
|
||||
];
|
||||
|
@@ -26,6 +26,7 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Location } from '@angular/common';
|
||||
import { AuthenticationService } from '@alfresco/adf-core';
|
||||
import { ActivatedRoute, Params } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
templateUrl: './login.component.html'
|
||||
@@ -33,12 +34,18 @@ import { AuthenticationService } from '@alfresco/adf-core';
|
||||
export class LoginComponent implements OnInit {
|
||||
constructor(
|
||||
private location: Location,
|
||||
private auth: AuthenticationService
|
||||
private auth: AuthenticationService,
|
||||
private route: ActivatedRoute
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
if (this.auth.isEcmLoggedIn()) {
|
||||
this.location.forward();
|
||||
} else {
|
||||
this.route.queryParams.subscribe((params: Params) => {
|
||||
const redirectUrl = params['redirectUrl'];
|
||||
this.auth.setRedirect({ provider: 'ECM', url: redirectUrl });
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { AuthGuardEcm, CoreModule } from '@alfresco/adf-core';
|
||||
import { CoreModule } from '@alfresco/adf-core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { APP_INITIALIZER, ModuleWithProviders, NgModule } from '@angular/core';
|
||||
import { LayoutComponent } from '../components/layout/layout.component';
|
||||
@@ -36,6 +36,7 @@ import { MetadataTabComponent } from '../components/info-drawer/metadata-tab/met
|
||||
import { CommentsTabComponent } from '../components/info-drawer/comments-tab/comments-tab.component';
|
||||
import { VersionsTabComponent } from '../components/info-drawer/versions-tab/versions-tab.component';
|
||||
import { ExtensionsModule, ExtensionService } from '@alfresco/adf-extensions';
|
||||
import { AppAuthGuard } from '../guards/auth.guard';
|
||||
|
||||
export function setupExtensions(service: AppExtensionService): Function {
|
||||
return () => service.load();
|
||||
@@ -77,7 +78,7 @@ export class CoreExtensionsModule {
|
||||
});
|
||||
|
||||
extensions.setAuthGuards({
|
||||
'app.auth': AuthGuardEcm
|
||||
'app.auth': AppAuthGuard
|
||||
});
|
||||
|
||||
extensions.setEvaluators({
|
||||
|
56
src/app/guards/auth.guard.ts
Normal file
56
src/app/guards/auth.guard.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
/*!
|
||||
* @license
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* Copyright (C) 2005 - 2018 Alfresco Software Limited
|
||||
*
|
||||
* This file is part of the Alfresco Example Content Application.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import {
|
||||
AuthenticationService,
|
||||
AppConfigService,
|
||||
AuthGuardEcm
|
||||
} from '@alfresco/adf-core';
|
||||
|
||||
@Injectable()
|
||||
export class AppAuthGuard extends AuthGuardEcm {
|
||||
constructor(
|
||||
private _auth: AuthenticationService,
|
||||
private _router: Router,
|
||||
config: AppConfigService
|
||||
) {
|
||||
super(_auth, _router, config);
|
||||
}
|
||||
|
||||
checkLogin(redirectUrl: string): boolean {
|
||||
if (this._auth.isEcmLoggedIn()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!this._auth.isOauth() || this.isOAuthWithoutSilentLogin()) {
|
||||
this._auth.setRedirect({ provider: 'ECM', url: redirectUrl });
|
||||
this._router.navigateByUrl('/login?redirectUrl=' + redirectUrl);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user