X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=sdnr%2Fwireless-transport%2Fcode-Carbon-SR1%2Fapps%2Fdlux%2Fdlux-web%2Fsrc%2Fcommon%2Flogin%2Flogin.module.js;fp=sdnr%2Fwireless-transport%2Fcode-Carbon-SR1%2Fapps%2Fdlux%2Fdlux-web%2Fsrc%2Fcommon%2Flogin%2Flogin.module.js;h=72702c656787e05bdbdb10ff92d5068afa5484cb;hb=27fb2d06608fbb070ae2c15a5580a4f5b2423d15;hp=0000000000000000000000000000000000000000;hpb=60315525ab5e7c12a9f47c409092e8dba6ad656d;p=ccsdk%2Fapps.git diff --git a/sdnr/wireless-transport/code-Carbon-SR1/apps/dlux/dlux-web/src/common/login/login.module.js b/sdnr/wireless-transport/code-Carbon-SR1/apps/dlux/dlux-web/src/common/login/login.module.js new file mode 100644 index 00000000..72702c65 --- /dev/null +++ b/sdnr/wireless-transport/code-Carbon-SR1/apps/dlux/dlux-web/src/common/login/login.module.js @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2014 Inocybe Technologies, and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +define(['angularAMD', 'jquery', 'common/authentification/auth.module', 'ocLazyLoad'], function (ng, $) { + var login = angular.module('app.common.login', ['app.common.auth', 'ui.router.state']); + + login.config(function ($stateProvider, $httpProvider) { + $stateProvider + .state('login', { + url: '/login', + views: { + 'mainContent@': { + templateUrl: 'src/common/login/login.tpl.html', + controller: 'LoginCtrl' + } + }, + resolve: { + loadController: ['$ocLazyLoad', function ($ocLazyLoad) { + return $ocLazyLoad.load({ + files: ['src/common/login/login.controller.js'] + }); + }] + } + }); + + $httpProvider.interceptors.push('NbInterceptor'); + }); + + login.run(function ($rootScope, $location, Auth) { + + // to avoid recursive loop + var publicPath = ['/login']; + + var isPublicPath = function (route) { + var found = false; + $.each(publicPath, function (key, value) { + found = found || route.match('^' + value); + }); + return found; + }; + + $rootScope.$on('$stateChangeStart', function () { + if (!isPublicPath($location.url()) && !Auth.isAuthed()) { + $location.path('/login'); + } + }); + + }); + + return login; +});