Skip to content

Commit

Permalink
1. Implemented logout
Browse files Browse the repository at this point in the history
2. Added menu that displays the logged username and a link to log out
  • Loading branch information
maeisabelle08 committed Feb 5, 2016
1 parent aaa6318 commit 61c2c54
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,13 @@ public void saveConfigurationToFile() {
}
}
}

public void removeSavedConfiguration() {
this.properties = new Properties();
File file = new File(PROPERTIES_FILENAME);
if(file.exists()) {
file.delete();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ public LoginForm postLogin(@RequestBody LoginForm loginForm, BindingResult bindi
loginForm.setInstalled(dataHubService.isInstalled());
loginForm.setServerVersionAccepted(dataHubService.isServerAcceptable());
loginForm.setHasErrors(false);
loginForm.setSkipLogin(true);
loginForm.setLoggedIn(true);

environmentConfiguration.saveConfigurationToFile();

session.setAttribute("loginForm", loginForm);
}
catch (DataHubException e) {
LOGGER.error("Login failed", e);
loginForm.setLoggedIn(false);
displayError(loginForm, null, null, e.getMessage());
}

Expand All @@ -64,6 +65,15 @@ public LoginForm getLoginStatus(HttpSession session) {
return loginForm;
}

@RequestMapping(value="logout", method = RequestMethod.POST)
public LoginForm postLogout(HttpSession session) {
LoginForm loginForm = (LoginForm) session.getAttribute("loginForm");
loginForm.setLoggedIn(false);
this.environmentConfiguration.removeSavedConfiguration();
this.retrieveEnvironmentConfiguration(loginForm);
return loginForm;
}

@RequestMapping(value="install", method = RequestMethod.POST)
public void install() {
dataHubService.install();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class LoginForm extends BaseForm {
private String mlPassword;
private boolean serverVersionAccepted;
private boolean installed;
private boolean skipLogin;
private boolean loggedIn;

public String getMlHost() {
return mlHost;
Expand Down Expand Up @@ -59,13 +59,14 @@ public void setInstalled(boolean installed) {
this.installed = installed;
}

public boolean isSkipLogin() {
return skipLogin;
public boolean isLoggedIn() {
return loggedIn;
}

public void setSkipLogin(boolean skipLogin) {
this.skipLogin = skipLogin;
public void setLoggedIn(boolean loggedIn) {
this.loggedIn = loggedIn;
}




}
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<div id="header" class="container-fluid">
<div class="row">
<div class="col-xs-8 col-sm-8 col-md-8"><h1 id="sitename" th:text="#{app.title}"></h1></div>
<div class="col-xs-11 col-sm-8 col-md-8"><h1 id="sitename" th:text="#{app.title}"></h1></div>
<div id="sitemenu" class="dropdown" ng-if="username">
<button class="btn btn-default dropdown-toggle" type="button" id="headerDropdownMenu" data-toggle="dropdown" aria-expanded="true">
Welcome {{username}}! <span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right" role="menu" aria-labelledby="headerDropdownMenu">
<li role="presentation"><a href="javascript:void(0)" ng-click="logout()">Logout</a></li>
</ul>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion quick-start/src/main/webapp/WEB-INF/pages/top/top.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<header></header>
<header username="status.mlUsername"></header>

<div class="container">
<div class="row spacing-top">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.controller('loginController', [

DataHub.getLoginStatus().then(function (request) {
$scope.loginForm = DataHub.status;
if (DataHub.status && DataHub.status.skipLogin) {
if (DataHub.status && DataHub.status.loggedIn) {
$location.path('/top');
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,27 @@ var module = angular.module('dhib.quickstart.directives.header', dependencies);
module.directive('header', [
'$http'
,'$location'
,'DataHub'
,function(
$http
,$location
,DataHub
) {
return {
return {
restrict: 'E'
,scope : {
activeTab : '='
activeTab : '=',
username : '='
}
,transclude: true
,templateUrl : function(element, attrs) {
return attrs.templateUrl || 'directives/header.html';
}
,link : function(scope, element, attrs) {
scope.logout = function () {
DataHub.logout();
$location.path('/login');
}
}
,controller : function($scope, $element, $attrs, $transclude) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.factory('DataHub', [
) {
var service = {

login : function (loginForm) {
login : function (loginForm) {
var promise = $http
.post('api/data-hub/login', loginForm)
.success(function (data) {
Expand All @@ -36,6 +36,18 @@ module.factory('DataHub', [
return promise;
}

,logout : function () {
var promise = $http
.post('api/data-hub/logout')
.success(function (data) {
service.status = data;
})
.error(function () {
service.status = null;
});
return promise;
}

,install : function () {
var promise = $http.post('api/data-hub/install');

Expand Down
11 changes: 11 additions & 0 deletions quick-start/src/main/webapp/WEB-INF/static/css/quick-start.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,15 @@ ul.alert {

.spacing-top {
margin-top: 10px;
}

div#sitemenu {
text-align: right;
color: #ffffff;
}

button#headerDropdownMenu {
background-color: #404040;
border: 0px;
color: #ffffff;
}

0 comments on commit 61c2c54

Please sign in to comment.