diff --git a/app/index.html b/app/index.html index 2e37f37..d01a052 100644 --- a/app/index.html +++ b/app/index.html @@ -109,6 +109,8 @@ + + diff --git a/app/scripts/app.js b/app/scripts/app.js index f85b998..e53ef35 100644 --- a/app/scripts/app.js +++ b/app/scripts/app.js @@ -46,6 +46,11 @@ angular.module('FlyveMDM', [ templateUrl: 'views/invitationlogs.html', controller: 'InvitationLogsCtrl' }) + .state('account_validation', { + url: '/account/{id:int}/validation/{hash:[0-9a-f]{64}}', + templateUrl: 'views/accountvalidation.html', + controller: 'AccountValidationCtrl' + }) .state('device', { url: "/admin/devices/{id:int}", templateUrl: 'views/device.html', diff --git a/app/scripts/controllers/accountvalidation.js b/app/scripts/controllers/accountvalidation.js new file mode 100644 index 0000000..be16da7 --- /dev/null +++ b/app/scripts/controllers/accountvalidation.js @@ -0,0 +1,26 @@ +'use strict'; +/** + * @ngdoc function + * @name FlyveMDM.controller:AccountValidationCtrl + * @description + * # AccountValidationCtrl + * Controller of the FlyveMDM + */ +angular.module('FlyveMDM') + .controller('AccountValidationCtrl', function ($scope, AuthProvider, AccountFac, Notifications, $state, $stateParams) { + $scope.lock_submit = false; + $scope.show_login = false; + $scope.validateAccount = function () { + $scope.lock_submit = true; + AccountFac.validateAccount($stateParams.id, $stateParams.hash) + .then(function () { + Notifications.done("Account validated"); + $scope.show_login = true; + }, function () { + $scope.lock_submit = false; + }); + }; + $scope.goToLogin = function () { + $state.go('login'); + }; + }); diff --git a/app/scripts/services/account.js b/app/scripts/services/account.js new file mode 100644 index 0000000..855f7be --- /dev/null +++ b/app/scripts/services/account.js @@ -0,0 +1,41 @@ +'use strict'; + +/** + * @ngdoc service + * @name FlyveMDM.AccountFac + * @description + * # AccountFac + * Factory in the FlyveMDM. + */ +angular.module('FlyveMDM') + .factory('AccountFac', function (GLPI_API_URL, PluginObjectNames, AuthProvider, $q, $http) { + // Service logic + // Public API here + return { + validateAccount: function (id, hash) { + var defer = $q.defer(); + AuthProvider.getTempSessionToken().then(function (temp_session_token) { + $http({ + method: 'PUT', + url: GLPI_API_URL + PluginObjectNames.AccountValidation, + data: { + input: { + id: id, + _validate: hash + } + }, + headers: { + 'Session-Token': temp_session_token + } + }).then(function (response) { + defer.resolve(response.data); + }, function () { + defer.reject(); + }); + }, function () { + defer.reject(); + }); + return defer.promise; + } + }; + }); diff --git a/app/scripts/services/auth.js b/app/scripts/services/auth.js index a9bbb85..96f0c7b 100644 --- a/app/scripts/services/auth.js +++ b/app/scripts/services/auth.js @@ -76,6 +76,21 @@ angular.module('FlyveMDM') }); return deferred.promise; }; + AuthProvider.prototype.getTempSessionToken = function () { + var tempSessionDeferred = $q.defer(); + $http({ + url: GLPI_API_URL + GlpiObjectNames.InitSession, + method: 'GET', + headers: { + 'Authorization': 'user_token ' + USER_TOKEN + } + }).then(function (response) { + tempSessionDeferred.resolve(response.data.session_token); + }, function () { + tempSessionDeferred.reject(); + }); + return tempSessionDeferred.promise; + }; /* * User registration method, which returns * a promise, which will resolve if the @@ -88,22 +103,7 @@ angular.module('FlyveMDM') // This anonymous function helps retrieve a temporary // session_token with the api_key in order so it is // possible to register an user in the flyvemdm interface. - var getTempSessionToken = function () { - var tempSessionDeferred = $q.defer(); - $http({ - url: GLPI_API_URL + GlpiObjectNames.InitSession, - method: 'GET', - headers: { - 'Authorization': 'user_token ' + USER_TOKEN - } - }).then(function (response) { - tempSessionDeferred.resolve(response.data.session_token); - }, function () { - tempSessionDeferred.reject(); - }); - return tempSessionDeferred.promise; - }; - getTempSessionToken().then(function (temp_session_token) { + this.getTempSessionToken().then(function (temp_session_token) { var request = $http({ method: 'POST', url: GLPI_API_URL + PluginObjectNames.User, diff --git a/app/scripts/services/pluginobjectnames.js b/app/scripts/services/pluginobjectnames.js index 0c809d4..148b035 100644 --- a/app/scripts/services/pluginobjectnames.js +++ b/app/scripts/services/pluginobjectnames.js @@ -21,5 +21,6 @@ angular.module('FlyveMDM') Policy: "/PluginStorkmdmPolicy", PolicyCategory: "/PluginStorkmdmPolicyCategory", User: "/PluginStorkmdmUser", - WellknownPath: "/PluginStorkmdmWellknownPath" + WellknownPath: "/PluginStorkmdmWellknownPath", + AccountValidation: "/PluginStorkmdmAccountvalidation" }); diff --git a/app/styles/_viewport.sass b/app/styles/_viewport.sass index c63c88a..4050558 100644 --- a/app/styles/_viewport.sass +++ b/app/styles/_viewport.sass @@ -29,7 +29,7 @@ viewport display: block width: 100% padding-left: $nav-full-width - padding-bottom: 16px + /*padding-bottom: 16px*/ @include nav-when-small padding-left: $nav-mini-width body.nav-invisible & diff --git a/app/views/accountvalidation.html b/app/views/accountvalidation.html new file mode 100644 index 0000000..fd9f032 --- /dev/null +++ b/app/views/accountvalidation.html @@ -0,0 +1,16 @@ +
+
+ +
+ +
+

A solution powered by

+ Flyve Logo +
+
\ No newline at end of file