From fe453a003626c5a2da02af3f8acd5e1e9b565d45 Mon Sep 17 00:00:00 2001 From: Ilavarasi1 Date: Mon, 1 Apr 2019 08:01:26 +0000 Subject: [PATCH] Provide error handling for login. Closes #798. --- pebbles/server.py | 25 ++++++++++++++++- .../js/controllers/DashboardController.js | 1 + .../static/js/directives/ErrorDirective.js | 27 ++++++++++++++++--- pebbles/static/js/services/AuthService.js | 1 + pebbles/templates/error.html | 10 ++++++- 5 files changed, 59 insertions(+), 5 deletions(-) diff --git a/pebbles/server.py b/pebbles/server.py index bdf6bff0..ddd9e816 100644 --- a/pebbles/server.py +++ b/pebbles/server.py @@ -111,10 +111,32 @@ @sso.login_handler def login(user_info): + error_number = '' + logging.warn("in views login") + logging.warn("user_info['eppn'] is %s" %user_info['eppn']) eppn = user_info['eppn'] user = User.query.filter_by(eppn=eppn).first() + logging.warn("user is %s" %user) + #user_avail = User.query.filter_by(email_id=user_info['email_id']).first() + #logging.warn("user_avail is %s " %user_avail) + #logging.warn("userinfo is %s " %user_info['email_id']) if not user: - user = create_user(eppn, password=uuid.uuid4().hex, email_id=user_info['email_id']) + logging.warn("userinfo is %s " %user_info['email_id']) + user_avail = User.query.filter_by(email_id=user_info['email_id']).first() + logging.warn("user_avail is %s " %user_avail) + if user_avail: + logging.warn("trying to create user") + logging.warn("User info is %s" %user_info['email_id']) + error_description = 'You already have an account. Please login through that account using alternate login. If you have trouble, contact your administrator' + return render_template( + 'error.html', + error_title='User already exists as guest user', + error_description=error_description, + error_number=500 + ) + else: + logging.warn("trying to create user") + user = create_user(eppn, password=uuid.uuid4().hex, email_id=user_info['email_id']) if not user.email_id: user = update_email(eppn, email_id=user_info['email_id']) if not user.is_active: @@ -127,6 +149,7 @@ def login(user_info): error_title='User Blocked', error_description=error_description ) + if user.is_admin: icons = admin_icons elif user.is_group_owner: diff --git a/pebbles/static/js/controllers/DashboardController.js b/pebbles/static/js/controllers/DashboardController.js index 096e7982..75bbdbb0 100644 --- a/pebbles/static/js/controllers/DashboardController.js +++ b/pebbles/static/js/controllers/DashboardController.js @@ -444,6 +444,7 @@ app.controller('PoolConfigController', ['$scope', 'Restangular', var fetchPoolConfig = function(){ configService.getList({'namespace': 'DockerDriver', 'key': 'pool_vm'}).then(function (response) { + console.log("it is ", response); $scope.poolConfigs = response; }); }; diff --git a/pebbles/static/js/directives/ErrorDirective.js b/pebbles/static/js/directives/ErrorDirective.js index b9c0657b..9a6ab8b7 100644 --- a/pebbles/static/js/directives/ErrorDirective.js +++ b/pebbles/static/js/directives/ErrorDirective.js @@ -1,15 +1,36 @@ -app.directive('pbErrors', ['localStorageService', function(localStorageService) { +app.directive('pbErrors', ['$window', '$location', '$timeout', 'localStorageService', function($window, $location, $timeout, localStorageService) { return { restrict: 'E', link: function(scope, element, attrs) { var errors = localStorageService.get('errors'); if (errors && (errors instanceof Array)) { errors.forEach(function(x) { - if (x.length != 2) { + console.log(" x.length" , x.length); + console.log("x[2] ", x[2]); + console.log("x[3] ", x[3]); + if (x.length == 3 && x[2] == 500) { + console.log("hei"); + $.notify({message: "" + x[0] + ": " + x[1]}, {type: 'danger'}, {duration: 0}); + $timeout(function() { + $location.path(' '); + hostname = $window.location.hostname; + urlvalue = 'https' + '://' + hostname + '/Shibboleth.sso/Logout?return=' + 'https' +'://' + hostname; + //urlvalue = 'https' + '://' + hostname + '/Shibboleth.sso/Logout'; + $window.location.href = urlvalue; + },20000 ); + //$.notify({message: "" + x[0] + ": " + x[1]}, {type: 'danger'}, {duration: 0}); + //localStorageService.clearAll(); + } + else if (x.length != 2) { return; } - $.notify({message: "" + x[0] + ": " + x[1]}, {type: 'danger'}); + //else { + //$timeout(function() { + // $.notify({message: "" + x[0] + ": " + x[1]}, {type: 'danger', z_index: 2000,}); + //},20); + //} }); + //$.notify({message: "" + x[0] + ": " + x[1]}, {type: 'danger'}, {duration: 0}); localStorageService.set('errors', []); } } diff --git a/pebbles/static/js/services/AuthService.js b/pebbles/static/js/services/AuthService.js index 3595a897..65d544e4 100644 --- a/pebbles/static/js/services/AuthService.js +++ b/pebbles/static/js/services/AuthService.js @@ -13,6 +13,7 @@ app.factory('AuthService', ['$q', 'localStorageService', 'Session', 'Restangular me.setGroupManagerStatus(response.is_group_manager); me.setUserId(response.user_id); me.setIcons(response.icon_value); + console.log("response is ", response); return deferred.resolve(response); }, function(response) { if (response.status === 401) { diff --git a/pebbles/templates/error.html b/pebbles/templates/error.html index c3400790..40092c51 100644 --- a/pebbles/templates/error.html +++ b/pebbles/templates/error.html @@ -10,10 +10,18 @@ .controller('HakaErrorController', function($location, localStorageService) { var errors = localStorageService.get('errors'); + console.log("errors are ", errors); + console.log("errors are ", errors); if (! errors) { errors = []; } - errors.push(["{{ error_title }}", "{{ error_description}}"]); + if ("{{ error_number }}" == 500) { + errors.push(["{{ error_title }}", "{{ error_description}}", "{{ error_number }}"]); + } + else { + errors.push(["{{ error_title }}", "{{ error_description}}"]); + } + console.log("pushed errors are ", errors); localStorageService.set('errors', errors); window.location.assign("/"); });