Skip to content

Commit 66b0ce2

Browse files
tinomthomasmaibin
authored andcommitted
BAEL - 1916 (#4705)
* BAEL - 1916 * BAEL - 1916 Added JUnit tests * BAEL-1916 Renamed the project * Renamed the project
1 parent 1f26ae8 commit 66b0ce2

78 files changed

Lines changed: 2335 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
(function () {
2+
'use strict';
3+
4+
angular
5+
.module('app', ['ngRoute'])
6+
.config(config)
7+
.run(run);
8+
9+
config.$inject = ['$routeProvider', '$locationProvider'];
10+
function config($routeProvider, $locationProvider) {
11+
$routeProvider
12+
.when('/', {
13+
controller: 'HomeController',
14+
templateUrl: 'home/home.view.html',
15+
controllerAs: 'vm'
16+
})
17+
.when('/login', {
18+
controller: 'LoginController',
19+
templateUrl: 'login/login.view.html',
20+
controllerAs: 'vm'
21+
})
22+
.otherwise({ redirectTo: '/login' });
23+
}
24+
25+
run.$inject = ['$rootScope', '$location', '$http', '$window'];
26+
function run($rootScope, $location, $http, $window) {
27+
var userData = $window.sessionStorage.getItem('userData');
28+
if (userData) {
29+
$http.defaults.headers.common['Authorization'] = 'Basic ' + JSON.parse(userData).authData;
30+
}
31+
32+
$rootScope.$on('$locationChangeStart', function (event, next, current) {
33+
var restrictedPage = $.inArray($location.path(), ['/login']) === -1;
34+
var loggedIn = $window.sessionStorage.getItem('userData');;
35+
if (restrictedPage && !loggedIn) {
36+
$location.path('/login');
37+
}
38+
});
39+
}
40+
})();
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
(function () {
2+
'use strict';
3+
4+
angular
5+
.module('app')
6+
.controller('HomeController', HomeController);
7+
8+
HomeController.$inject = ['$window', '$http', '$scope'];
9+
function HomeController($window, $http, $scope) {
10+
var vm = this;
11+
12+
vm.user = null;
13+
14+
initController();
15+
16+
function initController() {
17+
18+
$http({
19+
url: 'http://localhost:8082/user',
20+
method: "GET"
21+
}).then(function (response) {
22+
vm.user = response.data.name;
23+
},function(error){
24+
console.log(error);
25+
});
26+
};
27+
28+
$scope.logout = function(){
29+
$window.sessionStorage.setItem('userData', '');
30+
$http.defaults.headers.common['Authorization'] = 'Basic';
31+
}
32+
}
33+
34+
})();
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<h1>Hi {{vm.user}}!</h1>
2+
<p>You're logged in!!</p>
3+
<p><a href="#!/login" class="btn btn-primary" ng-click="logout()">Logout</a></p>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html ng-app="app">
3+
4+
<head>
5+
</head>
6+
<body>
7+
<div ng-view></div>
8+
9+
<script src="//code.jquery.com/jquery-3.1.1.min.js"></script>
10+
<script src="//code.angularjs.org/1.6.0/angular.min.js"></script>
11+
<script src="//code.angularjs.org/1.6.0/angular-route.min.js"></script>
12+
<script src="app.js"></script>
13+
<script src="home/home.controller.js"></script>
14+
<script src="login/login.controller.js"></script>
15+
</body>
16+
17+
</html>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
(function () {
2+
'use strict';
3+
4+
angular
5+
.module('app')
6+
.controller('LoginController', LoginController);
7+
8+
LoginController.$inject = ['$location', '$window', '$http'];
9+
function LoginController($location, $window, $http) {
10+
var vm = this;
11+
vm.login = login;
12+
13+
(function initController() {
14+
$window.localStorage.setItem('token', '');
15+
})();
16+
17+
function login() {
18+
$http({
19+
url: 'http://localhost:8082/login',
20+
method: "POST",
21+
data: { 'userName': vm.username, 'password': vm.password }
22+
}).then(function (response) {
23+
if (response.data) {
24+
var token = $window.btoa(vm.username + ':' + vm.password);
25+
var userData = {
26+
userName: vm.username,
27+
authData: token
28+
}
29+
$window.sessionStorage.setItem('userData', JSON.stringify(userData));
30+
$http.defaults.headers.common['Authorization'] = 'Basic ' + token;
31+
$location.path('/');
32+
} else {
33+
alert("Authentication failed.")
34+
}
35+
});
36+
};
37+
}
38+
})();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<div>
2+
<h2>Login</h2>
3+
<form name="form" ng-submit="vm.login()" role="form">
4+
<div>
5+
<label for="username">Username</label>
6+
<input type="text" name="username" id="username" ng-model="vm.username" required />
7+
<span ng-show="form.username.$dirty && form.username.$error.required">Username is required</span>
8+
</div>
9+
<div>
10+
<label for="password">Password</label>
11+
<input type="password" name="password" id="password" ng-model="vm.password" required />
12+
<span ng-show="form.password.$dirty && form.password.$error.required">Password is required</span>
13+
</div>
14+
<div class="form-actions">
15+
<button type="submit" ng-disabled="form.$invalid || vm.dataLoading">Login</button>
16+
</div>
17+
</form>
18+
</div>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
a {
2+
cursor: pointer;
3+
}
4+
5+
.help-block {
6+
font-size: 12px;
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<div class="jumbotron">
2+
<div class="container">
3+
<div class="col-sm-8 col-sm-offset-2">
4+
<router-outlet></router-outlet>
5+
</div>
6+
</div>
7+
</div>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app',
5+
templateUrl: './app/app.component.html'
6+
})
7+
8+
export class AppComponent { }
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { NgModule } from '@angular/core';
2+
import { BrowserModule } from '@angular/platform-browser';
3+
import { FormsModule } from '@angular/forms';
4+
import { HttpModule } from '@angular/http';
5+
6+
import { AppComponent } from './app.component';
7+
import { routing } from './app.routing';
8+
9+
import { HomeComponent } from './home/home.component';
10+
import { LoginComponent } from './login/login.component';
11+
12+
@NgModule({
13+
imports: [
14+
BrowserModule,
15+
FormsModule,
16+
HttpModule,
17+
routing
18+
],
19+
declarations: [
20+
AppComponent,
21+
HomeComponent,
22+
LoginComponent
23+
],
24+
bootstrap: [AppComponent]
25+
})
26+
27+
export class AppModule { }

0 commit comments

Comments
 (0)