From 25411189a71abaedb4403fa5dae81c7e8a475df0 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Wed, 2 Dec 2015 15:40:14 +0000 Subject: [PATCH] redirect to login if session expired in file upload --- .../app/views/project/editor/file-tree.jade | 1 + .../controllers/FileTreeController.coffee | 25 +++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/services/web/app/views/project/editor/file-tree.jade b/services/web/app/views/project/editor/file-tree.jade index 31564b0db1..14f292ed7a 100644 --- a/services/web/app/views/project/editor/file-tree.jade +++ b/services/web/app/views/project/editor/file-tree.jade @@ -357,6 +357,7 @@ script(type="text/ng-template", id="uploadFileModalTemplate") span   .alert.alert-warning.small(ng-if="tooManyFiles") #{translate("maximum_files_uploaded_together", {max:"{{max_files}}"})} .alert.alert-warning.small(ng-if="rateLimitHit") #{translate("too_many_files_uploaded_throttled_short_period")} + .alert.alert-warning.small(ng-if="notLoggedIn") #{translate("session_expired_redirecting_to_login", {seconds:"{{secondsToRedirect}}"})} .modal-body( fine-upload diff --git a/services/web/public/coffee/ide/file-tree/controllers/FileTreeController.coffee b/services/web/public/coffee/ide/file-tree/controllers/FileTreeController.coffee index 489c8e200d..81c2e096ca 100644 --- a/services/web/public/coffee/ide/file-tree/controllers/FileTreeController.coffee +++ b/services/web/public/coffee/ide/file-tree/controllers/FileTreeController.coffee @@ -99,11 +99,28 @@ define [ ] App.controller "UploadFileModalController", [ - "$scope", "ide", "$modalInstance", "$timeout", "parent_folder", - ($scope, ide, $modalInstance, $timeout, parent_folder) -> + "$scope", "ide", "$modalInstance", "$timeout", "parent_folder", "$window" + ($scope, ide, $modalInstance, $timeout, parent_folder, $window) -> $scope.parent_folder_id = parent_folder?.id $scope.tooManyFiles = false $scope.rateLimitHit = false + $scope.secondsToRedirect = 10 + $scope.notLoggedIn = false + + + needToLogBackIn = -> + $scope.notLoggedIn = true + decreseTimeout = -> + $timeout (() -> + if $scope.secondsToRedirect == 0 + $window.location.href = "/login?redir=/project/#{ide.project_id}" + else + decreseTimeout() + $scope.secondsToRedirect = $scope.secondsToRedirect - 1 + ), 1000 + + decreseTimeout() + uploadCount = 0 $scope.onUpload = () -> @@ -127,8 +144,12 @@ define [ return true $scope.onError = (id, name, reason)-> + console.log(id, name, reason) if reason.indexOf("429") != -1 $scope.rateLimitHit = true + else if reason.indexOf("403") != -1 + needToLogBackIn() + $scope.cancel = () -> $modalInstance.dismiss('cancel')