From e5857bc68ebe71c7ecc04707a3e7a09cff78847e Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Sat, 8 Jul 2017 12:12:20 +0200 Subject: [PATCH] Use angular strap modal instead of angular-ui-bootstrap one. --- src/login/index.js | 11 ++---- src/login/login.controller.js | 36 ------------------- src/login/login.service.js | 57 ++++++++++++++++-------------- src/login/login.tmpl.html | 65 +++++++++++++++++++---------------- 4 files changed, 71 insertions(+), 98 deletions(-) delete mode 100644 src/login/login.controller.js diff --git a/src/login/index.js b/src/login/index.js index 0e8a9d8..ad71013 100644 --- a/src/login/index.js +++ b/src/login/index.js @@ -21,14 +21,14 @@ var angular = require('angular'); var ngStorage = require('meanie-angular-storage'), - ngHttpAuth = require('angular-http-auth'); + ngHttpAuth = require('angular-http-auth'), + ngStrap = require('angular-strap'); // Note: ngHttpAuth seems to have no module.exports. ngHttpAuth = 'http-auth-interceptor'; var LoginService = require('./login.service'); var LoginConfig = require('./login.config'); -var LoginController = require('./login.controller'); module.exports = angular.module('accountant.login', [ ngHttpAuth, @@ -39,16 +39,11 @@ module.exports = angular.module('accountant.login', [ .config(LoginConfig) - .controller('LoginModalController', LoginController) - .run(function($rootScope, LoginService) { - var onAuthLoginRequired = $rootScope.$on('event:auth-loginRequired', LoginService.login); - - var onAuthLoginCancelled = $rootScope.$on('event:auth-loginCancelled', LoginService.cancelLogin); + var onAuthLoginRequired = $rootScope.$on('event:auth-loginRequired', LoginService.loginModal); $rootScope.$on('$destroy', function() { onAuthLoginRequired = angular.noop(); - onAuthLoginCancelled = angular.noop(); }); }) diff --git a/src/login/login.controller.js b/src/login/login.controller.js deleted file mode 100644 index 3db1e1d..0000000 --- a/src/login/login.controller.js +++ /dev/null @@ -1,36 +0,0 @@ -var base64 = require('base64util'); - -module.exports = function($scope, $uibModalInstance, $http, $log) { - var vm = this; - - vm.data = { - email: null, - password: null - }; - - vm.ok = function() { - var email = vm.data.email; - var password = vm.data.password; - - // Encode authentication data. - var authdata = base64.encode(email + ':' + password); - - return $http.post('/api/user/login', {}, { - ignoreAuthModule: true, - headers: { - 'authorization': 'Basic ' + authdata - } - }).then(function(result) { - $log.log(result); - - $uibModalInstance.close(result.data); - }, function(response) { - // FIXME Alexis Lahouze 2017-06-11 Handle error. - $log.log("Error on login", response); - }); - }; - - vm.cancel = function() { - $uibModalInstance.dismiss('cancel'); - }; -}; diff --git a/src/login/login.service.js b/src/login/login.service.js index d28eafc..8140b79 100644 --- a/src/login/login.service.js +++ b/src/login/login.service.js @@ -1,38 +1,45 @@ +var base64 = require('base64util'); + var loginTmpl = require('./login.tmpl.html'); -module.exports = function($uibModal, $storage, $document, $log, authService) { - var login = function () { - $storage.session.clear(); +module.exports = function($storage, $http, authService, $modal) { + var login = function(email, password) { + // Encode authentication data. + var authdata = base64.encode(email + ':' + password); - var modalInstance = $uibModal.open({ - ariaLabelledBy: 'modal-title', - ariaDescribedBy: 'modal-body', - templateUrl: loginTmpl, - controller: 'LoginModalController', - controllerAs: '$ctrl' - }); - - modalInstance.result.then(function (data) { - $log.log(data); - - $storage.session.set('refresh_token', data.refresh_token); - $storage.session.set('access_token', data.access_token); + return $http.post('/api/user/login', {}, { + ignoreAuthModule: true, + headers: { + 'authorization': 'Basic ' + authdata + } + }).then(function (result) { + $storage.session.set('refresh_token', result.data.refresh_token); + $storage.session.set('access_token', result.data.access_token); authService.loginConfirmed(); - }, function () { - $log.info('Modal dismissed at: ' + new Date()); - - // FIXME Alexis Lahouze 2017-06-11 Redirect to error page. - authService.loginCancelled(null, 'Login cancelled by user action.'); + }, function(result) { + loginModal(); }); }; - var cancelLogin = function () { - // FIXME Alexis Lahouze 2017-06-11 Redirect to error page. + var loginModal = function () { + $storage.session.clear(); + + $modal({ + templateUrl: loginTmpl, + controller: function($scope, $login) { + $scope.$login = function() { + $scope.$hide(); + $login($scope.email, $scope.password); + }; + }, + locals: { + $login: login, + } + }); }; return { - 'login': login, - 'cancelLogin': cancelLogin + 'loginModal': loginModal, }; }; diff --git a/src/login/login.tmpl.html b/src/login/login.tmpl.html index 9cbcdbb..64a54ef 100644 --- a/src/login/login.tmpl.html +++ b/src/login/login.tmpl.html @@ -1,31 +1,38 @@ -