diff --git a/app/portainer/__module.js b/app/portainer/__module.js index a2ad9053d..6ddfb5f2a 100644 --- a/app/portainer/__module.js +++ b/app/portainer/__module.js @@ -65,40 +65,6 @@ angular.module('portainer.app', []) } }; - var init = { - name: 'portainer.init', - abstract: true, - url: '/init', - data: { - requiresLogin: false - }, - views: { - 'sidebar@': {} - } - }; - - var initEndpoint = { - name: 'portainer.init.endpoint', - url: '/endpoint', - views: { - 'content@': { - templateUrl: 'app/portainer/views/init/endpoint/initEndpoint.html', - controller: 'InitEndpointController' - } - } - }; - - var initAdmin = { - name: 'portainer.init.admin', - url: '/admin', - views: { - 'content@': { - templateUrl: 'app/portainer/views/init/admin/initAdmin.html', - controller: 'InitAdminController' - } - } - }; - var endpoints = { name: 'portainer.endpoints', url: '/endpoints', @@ -198,6 +164,40 @@ angular.module('portainer.app', []) } }; + var init = { + name: 'portainer.init', + abstract: true, + url: '/init', + data: { + requiresLogin: false + }, + views: { + 'sidebar@': {} + } + }; + + var initEndpoint = { + name: 'portainer.init.endpoint', + url: '/endpoint', + views: { + 'content@': { + templateUrl: 'app/portainer/views/init/endpoint/initEndpoint.html', + controller: 'InitEndpointController' + } + } + }; + + var initAdmin = { + name: 'portainer.init.admin', + url: '/admin', + views: { + 'content@': { + templateUrl: 'app/portainer/views/init/admin/initAdmin.html', + controller: 'InitAdminController' + } + } + }; + var registries = { name: 'portainer.registries', url: '/registries', @@ -318,6 +318,21 @@ angular.module('portainer.app', []) } }; + var updatePassword = { + name: 'portainer.updatePassword', + url: '/update-password', + views: { + 'content@': { + templateUrl: 'app/portainer/views/update-password/updatePassword.html', + controller: 'UpdatePasswordController' + }, + 'sidebar@': {} + }, + params: { + password: '' + } + }; + var users = { name: 'portainer.users', url: '/users', @@ -404,9 +419,6 @@ angular.module('portainer.app', []) $stateRegistryProvider.register(about); $stateRegistryProvider.register(account); $stateRegistryProvider.register(authentication); - $stateRegistryProvider.register(init); - $stateRegistryProvider.register(initEndpoint); - $stateRegistryProvider.register(initAdmin); $stateRegistryProvider.register(endpoints); $stateRegistryProvider.register(endpoint); $stateRegistryProvider.register(endpointAccess); @@ -416,6 +428,9 @@ angular.module('portainer.app', []) $stateRegistryProvider.register(groupAccess); $stateRegistryProvider.register(groupCreation); $stateRegistryProvider.register(home); + $stateRegistryProvider.register(init); + $stateRegistryProvider.register(initEndpoint); + $stateRegistryProvider.register(initAdmin); $stateRegistryProvider.register(registries); $stateRegistryProvider.register(registry); $stateRegistryProvider.register(registryAccess); @@ -427,6 +442,7 @@ angular.module('portainer.app', []) $stateRegistryProvider.register(stackCreation); $stateRegistryProvider.register(support); $stateRegistryProvider.register(tags); + $stateRegistryProvider.register(updatePassword); $stateRegistryProvider.register(users); $stateRegistryProvider.register(user); $stateRegistryProvider.register(teams); diff --git a/app/portainer/views/account/accountController.js b/app/portainer/views/account/accountController.js index b842b7317..304fd2586 100644 --- a/app/portainer/views/account/accountController.js +++ b/app/portainer/views/account/accountController.js @@ -1,6 +1,6 @@ angular.module('portainer.app') -.controller('AccountController', ['$scope', '$state', '$sanitize', 'Authentication', 'UserService', 'Notifications', 'SettingsService', -function ($scope, $state, $sanitize, Authentication, UserService, Notifications, SettingsService) { +.controller('AccountController', ['$scope', '$state', 'Authentication', 'UserService', 'Notifications', 'SettingsService', +function ($scope, $state, Authentication, UserService, Notifications, SettingsService) { $scope.formValues = { currentPassword: '', newPassword: '', @@ -9,10 +9,8 @@ function ($scope, $state, $sanitize, Authentication, UserService, Notifications, $scope.updatePassword = function() { $scope.invalidPassword = false; - var currentPassword = $sanitize($scope.formValues.currentPassword); - var newPassword = $sanitize($scope.formValues.newPassword); - UserService.updateUserPassword($scope.userID, currentPassword, newPassword) + UserService.updateUserPassword($scope.userID, $scope.formValues.currentPassword, $scope.formValues.newPassword) .then(function success() { Notifications.success('Success', 'Password successfully updated'); $state.reload(); diff --git a/app/portainer/views/auth/authController.js b/app/portainer/views/auth/authController.js index 90d5e85a2..3b18d600c 100644 --- a/app/portainer/views/auth/authController.js +++ b/app/portainer/views/auth/authController.js @@ -1,6 +1,6 @@ angular.module('portainer.app') -.controller('AuthenticationController', ['$scope', '$state', '$transition$', '$sanitize', 'Authentication', 'UserService', 'EndpointService', 'StateManager', 'Notifications', 'SettingsService', -function ($scope, $state, $transition$, $sanitize, Authentication, UserService, EndpointService, StateManager, Notifications, SettingsService) { +.controller('AuthenticationController', ['$q', '$scope', '$state', '$transition$', '$sanitize', 'Authentication', 'UserService', 'EndpointService', 'StateManager', 'Notifications', 'SettingsService', +function ($q, $scope, $state, $transition$, $sanitize, Authentication, UserService, EndpointService, StateManager, Notifications, SettingsService) { $scope.logo = StateManager.getState().application.logo; @@ -13,6 +13,31 @@ function ($scope, $state, $transition$, $sanitize, Authentication, UserService, AuthenticationError: '' }; + $scope.authenticateUser = function() { + var username = $scope.formValues.Username; + var password = $scope.formValues.Password; + + Authentication.login(username, password) + .then(function success() { + checkForEndpoints(); + }) + .catch(function error() { + SettingsService.publicSettings() + .then(function success(settings) { + if (settings.AuthenticationMethod === 1) { + return Authentication.login($sanitize(username), $sanitize(password)); + } + return $q.reject(); + }) + .then(function success() { + $state.go('portainer.updatePassword', { password: $sanitize(password) }); + }) + .catch(function error() { + $scope.state.AuthenticationError = 'Invalid credentials'; + }); + }); + }; + function unauthenticatedFlow() { EndpointService.endpoints() .then(function success(endpoints) { @@ -39,35 +64,22 @@ function ($scope, $state, $transition$, $sanitize, Authentication, UserService, }); } - $scope.authenticateUser = function() { - var username = $scope.formValues.Username; - var password = $scope.formValues.Password; - - SettingsService.publicSettings() - .then(function success(data) { - var settings = data; - if (settings.AuthenticationMethod === 1) { - username = $sanitize(username); - password = $sanitize(password); - } - return Authentication.login(username, password); - }) - .then(function success() { - return EndpointService.endpoints(); - }) + function checkForEndpoints() { + EndpointService.endpoints() .then(function success(data) { var endpoints = data; var userDetails = Authentication.getUserDetails(); + if (endpoints.length === 0 && userDetails.role === 1) { $state.go('portainer.init.endpoint'); } else { $state.go('portainer.home'); } }) - .catch(function error() { - $scope.state.AuthenticationError = 'Invalid credentials'; + .catch(function error(err) { + Notifications.error('Failure', err, 'Unable to retrieve endpoints'); }); - }; + } function initView() { if ($transition$.params().logout || $transition$.params().error) { diff --git a/app/portainer/views/init/admin/initAdminController.js b/app/portainer/views/init/admin/initAdminController.js index e43f8a0ec..569bb1491 100644 --- a/app/portainer/views/init/admin/initAdminController.js +++ b/app/portainer/views/init/admin/initAdminController.js @@ -1,6 +1,6 @@ angular.module('portainer.app') -.controller('InitAdminController', ['$scope', '$state', '$sanitize', 'Notifications', 'Authentication', 'StateManager', 'UserService', 'EndpointService', -function ($scope, $state, $sanitize, Notifications, Authentication, StateManager, UserService, EndpointService) { +.controller('InitAdminController', ['$scope', '$state', 'Notifications', 'Authentication', 'StateManager', 'UserService', 'EndpointService', +function ($scope, $state, Notifications, Authentication, StateManager, UserService, EndpointService) { $scope.logo = StateManager.getState().application.logo; @@ -15,8 +15,8 @@ function ($scope, $state, $sanitize, Notifications, Authentication, StateManager }; $scope.createAdminUser = function() { - var username = $sanitize($scope.formValues.Username); - var password = $sanitize($scope.formValues.Password); + var username = $scope.formValues.Username; + var password = $scope.formValues.Password; $scope.state.actionInProgress = true; UserService.initAdministrator(username, password) diff --git a/app/portainer/views/update-password/updatePassword.html b/app/portainer/views/update-password/updatePassword.html new file mode 100644 index 000000000..62c726a61 --- /dev/null +++ b/app/portainer/views/update-password/updatePassword.html @@ -0,0 +1,64 @@ +