Skip to content

Commit

Permalink
Provide error handling for login. Closes #798.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilavarasi1 committed Apr 1, 2019
1 parent 2c87db1 commit fe453a0
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 5 deletions.
25 changes: 24 additions & 1 deletion pebbles/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions pebbles/static/js/controllers/DashboardController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
};
Expand Down
27 changes: 24 additions & 3 deletions pebbles/static/js/directives/ErrorDirective.js
Original file line number Diff line number Diff line change
@@ -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: "<b>" + x[0] + ":</b> " + 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: "<b>" + x[0] + ":</b> " + x[1]}, {type: 'danger'}, {duration: 0});
//localStorageService.clearAll();
}
else if (x.length != 2) {
return;
}
$.notify({message: "<b>" + x[0] + ":</b> " + x[1]}, {type: 'danger'});
//else {
//$timeout(function() {
// $.notify({message: "<b>" + x[0] + ":</b> " + x[1]}, {type: 'danger', z_index: 2000,});
//},20);
//}
});
//$.notify({message: "<b>" + x[0] + ":</b> " + x[1]}, {type: 'danger'}, {duration: 0});
localStorageService.set('errors', []);
}
}
Expand Down
1 change: 1 addition & 0 deletions pebbles/static/js/services/AuthService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 9 additions & 1 deletion pebbles/templates/error.html
Original file line number Diff line number Diff line change
Expand Up @@ -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("/");
});
Expand Down

0 comments on commit fe453a0

Please sign in to comment.