Skip to content

Commit

Permalink
Fix #489 and also make the rememberMe checkbox actually remember
Browse files Browse the repository at this point in the history
  • Loading branch information
gashcrumb committed Aug 21, 2013
1 parent 5e47195 commit f15cfc0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
2 changes: 1 addition & 1 deletion hawtio-web/src/main/webapp/app/core/html/login.html
Expand Up @@ -21,7 +21,7 @@
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox"> Remember me
<input type="checkbox" ng-model="rememberMe"> Remember me
</label>
<button type="submit" class="btn btn-success" ng-disabled="!login.$valid"><i class="icon-check"></i> Sign In</button>
</div>
Expand Down
30 changes: 21 additions & 9 deletions hawtio-web/src/main/webapp/app/core/js/app.ts
Expand Up @@ -3,7 +3,6 @@ module Core {
export function AppController($scope, $location, workspace, jolokiaStatus, $document, pageTitle:Core.PageTitle, localStorage, userDetails, lastLocation, jolokiaUrl) {

if (userDetails.username === null) {
// sigh, hack
$location.url('/help');
}

Expand Down Expand Up @@ -105,7 +104,7 @@ module Core {
success: () => {
userDetails.username = null;
userDetails.password = null;
$scope.$apply();
Core.$apply($scope);
},
error: (xhr, textStatus, error) => {
// TODO, more feedback
Expand All @@ -120,24 +119,37 @@ module Core {
notification('error', 'Failed to log out, ' + error);
break;
}
$scope.$apply();
Core.$apply($scope);
}
});
};

$scope.$watch(() => { return localStorage['regexs'] }, $scope.setRegexIndicator);

$scope.$watch('userDetails', (newValue, oldValue) => {
$scope.maybeRedirect = () => {
if (userDetails.username === null) {
lastLocation.url = $location.url('/login');
var currentUrl = $location.url();
if (!currentUrl.startsWith('/login')) {
lastLocation.url = currentUrl;
$location.url('/login');
}
} else {
if ($location.url().startsWith('/login')) {
var url:Object = '/help';
if (angular.isDefined(lastLocation.url)) {
url = lastLocation.url;
}
$location.url(url);
}
}
//console.log("userDetails: ", userDetails);
}

$scope.$watch('userDetails', (newValue, oldValue) => {
$scope.maybeRedirect();
}, true);

$scope.$on('$routeChangeStart', function() {
if (userDetails.username === null) {
lastLocation.url = $location.url('/login');
}
$scope.maybeRedirect();
});

$scope.$on('$routeChangeSuccess', function() {
Expand Down
26 changes: 17 additions & 9 deletions hawtio-web/src/main/webapp/app/core/js/login.ts
@@ -1,15 +1,25 @@
module Core {

export function LoginController($scope, jolokia, userDetails, jolokiaUrl, workspace, $location, lastLocation) {
export function LoginController($scope, jolokia, userDetails, jolokiaUrl, workspace, $location, lastLocation, localStorage, $rootScope) {
jolokia.stop();

$scope.backstretch = (<any>$).backstretch("img/fire.jpg");

$scope.username = '';
$scope.password = '';

$scope.rememberMe = false;

var details = angular.fromJson(localStorage[jolokiaUrl]);
if (details) {
$scope.username = details['username'];
$scope.password = details['password'];
$scope.rememberMe = details['rememberMe'];
}

$scope.$on('$routeChangeStart', function() {
$scope.backstretch.destroy();
});

$scope.doLogin = () => {

var url = jolokiaUrl.replace("jolokia", "auth/login/");
Expand All @@ -19,20 +29,18 @@ module Core {
success: () => {
userDetails.username = $scope.username;
userDetails.password = $scope.password;
userDetails.rememberMe = $scope.rememberMe;

if ($scope.rememberMe) {
localStorage[jolokiaUrl] = angular.toJson(userDetails);
} else {
delete localStorage[jolokiaUrl];
}

//$.ajaxSetup(userDetails);

jolokia.start();
workspace.loadTree();

$location.url(lastLocation.url);
$scope.backstretch.destroy();

$scope.$apply();
Core.$apply($scope);
},
error: (xhr, textStatus, error) => {
// TODO placeholder for more feedback
Expand All @@ -47,7 +55,7 @@ module Core {
notification('error', 'Failed to log in, ' + error);
break;
}
$scope.$apply();
Core.$apply($scope);
},
beforeSend: (xhr) => {
xhr.setRequestHeader('Authorization', Core.getBasicAuthHeader($scope.username, $scope.password));
Expand Down

0 comments on commit f15cfc0

Please sign in to comment.