mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-09 22:51:22 +00:00
GUAC-1161: Convert login page to directive which accepts a dynamic form. Display login directive when credentials are needed.
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Glyptodon LLC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The config block for setting up the authentication interceptor.
|
||||
*/
|
||||
angular.module('index').config(['$httpProvider',
|
||||
function indexInterceptorConfig($httpProvider) {
|
||||
$httpProvider.interceptors.push('authenticationInterceptor');
|
||||
}]);
|
||||
|
||||
|
@@ -161,15 +161,6 @@ angular.module('index').config(['$routeProvider', '$locationProvider',
|
||||
resolve : { updateCurrentToken: updateCurrentToken }
|
||||
})
|
||||
|
||||
// Login screen
|
||||
.when('/login/', {
|
||||
title : 'APP.NAME',
|
||||
bodyClassName : 'login',
|
||||
templateUrl : 'app/login/templates/login.html',
|
||||
controller : 'loginController'
|
||||
// No need to update token here - the login screen ignores all auth
|
||||
})
|
||||
|
||||
// Client view
|
||||
.when('/client/:type/:id/:params?', {
|
||||
bodyClassName : 'client',
|
||||
|
@@ -36,6 +36,14 @@ angular.module('index').controller('indexController', ['$scope', '$injector',
|
||||
*/
|
||||
$scope.guacNotification = guacNotification;
|
||||
|
||||
/**
|
||||
* The credentials that the authentication service is currently expecting,
|
||||
* if any. If the user is logged in, this will be null.
|
||||
*
|
||||
* @type Form[]|Form|Field[]|Field
|
||||
*/
|
||||
$scope.expectedCredentials = null;
|
||||
|
||||
/**
|
||||
* Basic page-level information.
|
||||
*/
|
||||
@@ -92,6 +100,21 @@ angular.module('index').controller('indexController', ['$scope', '$injector',
|
||||
keyboard.reset();
|
||||
};
|
||||
|
||||
// Display login screen if a whole new set of credentials is needed
|
||||
$scope.$on('guacInvalidCredentials', function loginInvalid(event, parameters, expected) {
|
||||
$scope.expectedCredentials = expected;
|
||||
});
|
||||
|
||||
// Prompt for remaining credentials if provided credentials were not enough
|
||||
$scope.$on('guacInsufficientCredentials', function loginInsufficient(event, parameters, expected) {
|
||||
// TODO: Implement insufficient credential prompting
|
||||
});
|
||||
|
||||
// Clear login screen if login was successful
|
||||
$scope.$on('guacLogin', function loginSuccessful() {
|
||||
$scope.expectedCredentials = null;
|
||||
});
|
||||
|
||||
// Update title and CSS class upon navigation
|
||||
$scope.$on('$routeChangeSuccess', function(event, current, previous) {
|
||||
|
||||
|
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Glyptodon LLC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
angular.module('index').factory('authenticationInterceptor', ['$injector',
|
||||
function authenticationInterceptor($injector) {
|
||||
|
||||
// Required services
|
||||
var $location = $injector.get('$location');
|
||||
var $q = $injector.get('$q');
|
||||
|
||||
var service = {};
|
||||
|
||||
/**
|
||||
* Redirect users to login if authorization fails. This is called
|
||||
* automatically when this service is registered as an interceptor, as
|
||||
* documented at:
|
||||
*
|
||||
* https://docs.angularjs.org/api/ng/service/$http#interceptors
|
||||
*
|
||||
* @param {HttpPromise} rejection
|
||||
* The promise associated with the HTTP request that failed.
|
||||
*
|
||||
* @returns {Promise}
|
||||
* A rejected promise containing the originally-rejected HttpPromise.
|
||||
*/
|
||||
service.responseError = function responseError(rejection) {
|
||||
|
||||
// Only redirect failed authentication requests
|
||||
if ((rejection.status === 401 || rejection.status === 403)
|
||||
&& rejection.config.url === 'api/tokens') {
|
||||
|
||||
// Only redirect if not already on login page
|
||||
if ($location.path() !== '/login/')
|
||||
$location.path('/login/');
|
||||
|
||||
}
|
||||
|
||||
return $q.reject(rejection);
|
||||
|
||||
};
|
||||
|
||||
return service;
|
||||
|
||||
}]);
|
Reference in New Issue
Block a user