2 * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 var AECBlueprintValidationUIApp = angular.module('BlueprintValidationUIManagement', ['ngDialog', 'ui.router', 'base64','App.config','ngStorage','ui.bootstrap', 'ngResource','ngFileUpload','ngMaterial']);
19 AECBlueprintValidationUIApp.config(function($stateProvider, $urlRouterProvider) {
20 $urlRouterProvider.otherwise('/login')
23 templateUrl: 'views/indexMain.html',
29 templateUrl: 'views/login.html'
31 .state('newSubmission', {
32 url: "/newSubmission",
36 controller: 'AECNewSubmissionController',
37 templateUrl: 'views/newSubmission.html'
41 .state('committedSubmissions', {
42 url: "/committedSubmissions",
46 controller: 'AECCommittedSubmissionsController',
47 templateUrl: 'views/committedSubmissions.html'
51 .state('findBySubmissionId', {
52 url: "/findBySubmissionId",
56 controller: 'AECFindBySubmissionIdController',
57 templateUrl: 'views/findBySubmissionId.html'
63 AECBlueprintValidationUIApp.controller('Login',function($scope, $http, $filter, filterFilter, $state, $base64,$rootScope,$controller,appContext) {
64 $rootScope.tokenId ="";
65 $scope.usernameVal = '';
66 $scope.passwordVal = '';
67 $rootScope.message = "Please enter credentials";
68 $scope.$state = $state;
70 var baseURL = window.location.protocol + '//' + window.location.host;
71 /* eslint-disable no-console */
72 console.log('Base URL for current frame is: ' + baseURL);
73 /* eslint-enable no-console */
74 $scope.goLogin = function() {
75 var arr = $scope.passwordVal;
76 if ($scope.usernameVal == '' && $scope.passwordVal == '') {
77 $scope.userMessage = 'Please enter a username.';
78 $scope.passwordMessage = 'Please enter a password.';
79 } else if ($scope.usernameVal == '') {
80 $scope.userMessage = 'Please enter a username.';
81 $scope.passwordMessage = '';
82 } else if ($scope.passwordVal == '') {
83 $scope.passwordMessage = 'Please enter a password.';
84 $scope.userMessage = '';
85 } else if (arr.length < 6) {
86 $scope.passwordMessage = 'Please enter a valid password.';
87 $scope.userMessage = '';
90 $scope.passwordMessage = '';
91 $scope.userMessage ='';
92 // var userPwd = $scope.usernameVal + ":" + $scope.passwordVal;
93 // var auth = $base64.encode(userPwd);
95 * $http({ method: 'POST', url: appContext+'/login', //url:
96 * 'http://'+hostUrl+'/AECPortalMgmt/login', headers: {
97 * 'Authorization': "Basic " + auth, 'Content-Type':
98 * "application/json", 'Accept': "application/json" }, data: { } }).
99 * then(function(response) { if (response.data.statusCode == 200) {
100 * $rootScope.tokenId = response.data.tokenId;
101 * localStorage.setItem("tokenId",response.data.tokenId);
102 * $state.transitionTo('sites'); } else if (response.data.statusCode ==
103 * 401){ $scope.passwordVal= null; $scope.passwordMessage = 'Invalid
104 * Credentials, please try again...';
106 * localStorage.removeItem("tokenId"); } }, function(error) { if
107 * (error.status == 401) { $scope.passwordMessage = 'Invalid
108 * Credentials, please try again...'; $scope.passwordVal ="";
109 * localStorage.removeItem("tokenId"); } else if (error.status ==
110 * 400) { $scope.passwordMessage = 'Session Invalid, please login
111 * again...'; $scope.passwordVal ="";
112 * localStorage.removeItem("tokenId"); } else if (error.status ==
113 * 307) { $scope.passwordMessage = 'Session expired,Please try
114 * again...'; $scope.passwordVal ="";
115 * localStorage.removeItem("tokenId"); } });
117 $state.transitionTo('committedSubmissions');
120 $scope.goLogout = function() {
123 url: appContext+'/logout',
125 'Content-Type': "application/json",
126 'Accept': "application/json",
127 'tokenId' : $rootScope.tokenId
132 * data: { 'username': $scope.usernameVal, 'passowrd':
133 * $scope.passwordVal }
135 }).then(function(response) {
136 if (response.data.statusCode == 200) {
137 $rootScope.tokenId ="";
138 localStorage.removeItem("tokenId");
139 $state.transitionTo('login');
140 $rootScope.message = 'User logged out, please login again...';
142 }, function(response) {
143 $scope.message = 'Unknown error,Try again later' + response.status;