2015-05-05 03:10:25 +02:00
|
|
|
'use strict';
|
2020-06-15 11:57:13 +02:00
|
|
|
// TODO remove unused?
|
2015-05-05 03:10:25 +02:00
|
|
|
(function (angular) {
|
2020-09-21 15:11:39 +02:00
|
|
|
const deviseModal = angular.module('DeviseModal', [
|
|
|
|
'Devise',
|
|
|
|
'ui.bootstrap'
|
|
|
|
]);
|
2015-05-05 03:10:25 +02:00
|
|
|
deviseModal.run([
|
2016-03-23 18:39:41 +01:00
|
|
|
'$uibModal',
|
2015-05-05 03:10:25 +02:00
|
|
|
'$http',
|
|
|
|
'Auth',
|
|
|
|
'$rootScope',
|
2016-03-23 18:39:41 +01:00
|
|
|
function ($uibModal, $http, Auth, $rootScope) {
|
2022-04-01 17:48:32 +02:00
|
|
|
let promise = null;
|
2020-09-21 15:11:39 +02:00
|
|
|
function reset () {
|
2015-05-05 03:10:25 +02:00
|
|
|
promise = null;
|
|
|
|
}
|
2020-09-21 15:11:39 +02:00
|
|
|
function partial (fn, arg) {
|
2015-05-05 03:10:25 +02:00
|
|
|
return function () {
|
|
|
|
return fn.call(this, arg);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
$rootScope.$on('devise:unauthorized', function (event, response, deferred) {
|
2020-09-21 15:11:39 +02:00
|
|
|
function retryRequestAfterLogin () {
|
2015-05-05 03:10:25 +02:00
|
|
|
return promise.then(function () {
|
|
|
|
return $http(response.config);
|
|
|
|
}).then(deferred.resolve, partial(deferred.reject, response));
|
|
|
|
}
|
|
|
|
if (!promise) {
|
2016-03-23 18:39:41 +01:00
|
|
|
promise = $uibModal.open({
|
2020-10-19 14:40:18 +02:00
|
|
|
templateUrl: '/shared/deviseModal.html',
|
2021-03-24 15:51:02 +01:00
|
|
|
controller: ['$scope', '$uibModalInstance', function ($scope, $uibModalInstance) {
|
2020-09-21 15:11:39 +02:00
|
|
|
const user = $scope.user = {};
|
2015-05-05 03:10:25 +02:00
|
|
|
$scope.login = function () {
|
2016-03-23 18:39:41 +01:00
|
|
|
$uibModalInstance.close(user);
|
2015-05-05 03:10:25 +02:00
|
|
|
};
|
|
|
|
$scope.dismiss = function () {
|
2016-03-23 18:39:41 +01:00
|
|
|
$uibModalInstance.dismiss('cancel');
|
2015-05-05 03:10:25 +02:00
|
|
|
};
|
2021-03-24 15:51:02 +01:00
|
|
|
}]
|
2020-09-21 15:11:39 +02:00
|
|
|
}).result.finally(reset).then(Auth.login);
|
2015-05-05 03:10:25 +02:00
|
|
|
}
|
|
|
|
retryRequestAfterLogin();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
deviseModal.run([
|
|
|
|
'$templateCache',
|
|
|
|
function ($templateCache) {
|
|
|
|
'use strict';
|
|
|
|
$templateCache.put('deviseModal.html', '<div id=loginModal><div class=modal-header><button type=button class=close ng-click=dismiss()>x</button><h3>Have an Account?</h3></div><div class=modal-body><div class=well><form name=loginForm><div class=form-group ng-class="{\'has-error\': emailError}"><label class=control-label>Email</label><input type=email name=email class=form-control ng-model=user.email required=required ng-blur="emailError = !!loginForm.email.$error.email" ng-focus="emailError = false"></div><div class=form-group><label class=control-label for=password>Password</label><input type=password name=password class=form-control ng-model=user.password required=required></div><button class="btn btn-primary" ng-click=login()>Login</button></form></div></div></div>');
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
}(angular));
|