Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show username when logged in #65

Open
wants to merge 22 commits into
base: javascript-show-username
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5ad62d5
use latest version of Maven plugin
selvasingh Apr 7, 2019
ab81fac
set memory size
selvasingh Apr 7, 2019
c016c32
Merge branch 'master' of https://github.com/Microsoft/inventory-hub-j…
selvasingh Apr 7, 2019
754c540
Merge branch 'master' of https://github.com/Microsoft/inventory-hub-j…
selvasingh Apr 9, 2019
97bb769
Merge branch 'master' of https://github.com/Microsoft/inventory-hub-j…
selvasingh Apr 9, 2019
ec9ddf1
Merge branch 'master' of https://github.com/Microsoft/inventory-hub-j…
selvasingh Sep 28, 2019
97277b4
Merge branch 'master' of https://github.com/Microsoft/inventory-hub-j…
selvasingh Sep 28, 2019
e4b1d38
updated about page and removed unwanted dependencies
selvasingh Sep 28, 2019
e916758
rolled back to old css
selvasingh Sep 28, 2019
987c541
fixed splitting messages across consumers
selvasingh Sep 30, 2019
c79a084
Merge branch 'master' of https://github.com/Microsoft/inventory-hub-j…
selvasingh Sep 30, 2019
3d9e30c
fixed doc
selvasingh Sep 30, 2019
77e73d3
removed initialization
selvasingh Oct 1, 2019
a92bb9a
Merge branch 'master' of https://github.com/Microsoft/inventory-hub-j…
selvasingh Oct 1, 2019
b78ab70
added /api/username
selvasingh Oct 3, 2019
150d512
experimental
selvasingh Oct 3, 2019
7f100b7
show username when logged in
selvasingh Oct 3, 2019
337a235
Merge branch 'master' of https://github.com/Microsoft/inventory-hub-j…
selvasingh Oct 3, 2019
0b92063
added /api/username (#64)
selvasingh Oct 3, 2019
e4e0be9
Merge branch 'master' of https://github.com/Microsoft/inventory-hub-j…
selvasingh Oct 3, 2019
7890518
calls api/username
selvasingh Oct 4, 2019
1c42b46
username + logout
selvasingh Oct 4, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for
* license information.
*/

package org.inventory.hub.controller;

import java.security.Principal;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@ResponseBody
public class SecurityController {

public SecurityController() {
}

@RequestMapping(value = "/api/username", method = RequestMethod.GET)
public String currentUsername(final Principal principal) {

System.out.println("======= /api/username ===== ");
String username = new String();
if (principal != null)
username = principal.getName();

System.out.println("username=" + username);
System.out.println("====== success");

return username;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for
* license information.
*/

'use strict';
angular.module('inventoryHubApp')
.controller('usernameCtrl', ['$scope', '$location', 'usernameSvc',
function ($scope, $location, usernameSvc) {
$scope.error = '';
$scope.loadingMessage = '';
$scope.username = null;

$scope.fetchUsername = function () {
usernameSvc.getUsername().success(function(results) {
$scope.username = results;
}).error(function (err){
$scope.error = err;
$scope.loadingMessage = '';

});
};
}]);
15 changes: 15 additions & 0 deletions dashboard-web-app/src/main/resources/static/Scripts/usernameSvc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for
* license information.
*/

'use strict';
angular.module('inventoryHubApp')
.factory('usernameSvc', ['$http', function ($http) {
return {
getUsername: function(){
return $http.get('api/username');
}
};
}]);
10 changes: 10 additions & 0 deletions dashboard-web-app/src/main/resources/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
<ul class="navbar-nav">
<li ng-class="{ active: isActive('/Home') }"><a class="nav-link" href="#/Home">Home</a></li>
<li ng-class="{ active: isActive('/About') }"><a class="nav-link" href="#/About" target="_blank">About</a></li>
<li ng-app="inventoryHubApp" ng-controller="usernameCtrl" ng-init="fetchUsername()">
<div ng-if="username">
Welcome {{ username }}!
<a ng-class="{ active: isActive('/Logout) }"
class="nav-link"
href="/logout">Welcome {{ username }}! (logout)</a>
</div>
</li>
</ul>
</div>
</div>
Expand All @@ -45,6 +53,8 @@
<script src="Scripts/homeCtrl.js"></script>
<script src="Scripts/productsSvc.js"></script>
<script src="Scripts/aboutCtrl.js"></script>
<script src="Scripts/usernameSvc.js"></script>
<script src="Scripts/usernameCtrl.js"></script>

<script src="libs/sockjs/sockjs.min.js" type="text/javascript"></script>
<script src="libs/stomp-websocket/lib/stomp.min.js" type="text/javascript"></script>
Expand Down