Skip to content

Commit

Permalink
Redirect to login page if not logged in and anonymous upload is disab…
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles-Antoine Mathieu committed Oct 27, 2020
1 parent 5e192e0 commit 1dcd80a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type Configuration struct {
UploadWhitelist []string `json:"-"`

Authentication bool `json:"authentication"`
NoAnonymousUploads bool `json:"-"`
NoAnonymousUploads bool `json:"noAnonymousUploads"`
OneShot bool `json:"oneShot"`
Removable bool `json:"removable"`
Stream bool `json:"stream"`
Expand Down
7 changes: 7 additions & 0 deletions webapp/js/ctrl/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,5 +224,12 @@ plik.controller('HomeCtrl', ['$scope', '$api', '$config', '$dialog', '$location'
return filesize(size, {base: 2});
};

// Redirect to main page
$scope.mainpage = function () {
$location.search({});
$location.hash("");
$location.path('/');
};

loadUser($config.getUser());
}]);
11 changes: 11 additions & 0 deletions webapp/js/ctrl/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ plik.controller('MainCtrl', ['$scope', '$api', '$config', '$route', '$location',
.then(function (config) {
$scope.config = config;
$scope.setDefaultTTL();
if ( config.noAnonymousUploads ) {
// Redirect to login page if user is not authenticated
$config.getUser()
.then(null, function (error) {
if (error.status === 401 || error.status === 403) {
$location.path('/login');
} else {
$dialog.alert(error);
}
});
}
})
.then(null, function (error) {
$dialog.alert(error);
Expand Down
8 changes: 8 additions & 0 deletions webapp/partials/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
<p>Total Size : {{humanReadableSize(user.stats.totalSize)}}</p>
</div>
</div>
<!-- UPLOAD FILE BUTTON -->
<div class="tile menu">
<div class="menu-item">
<button type="button" class="btn btn-lg btn-primary btn-block" ng-click="mainpage()">
<i class="fa fa-upload"></i> Upload files
</button>
</div>
</div>
<!-- LOGOUT BUTTON -->
<div class="tile menu">
<div class="menu-item">
Expand Down

0 comments on commit 1dcd80a

Please sign in to comment.