Skip to content
This repository has been archived by the owner on May 30, 2018. It is now read-only.

Commit

Permalink
feat(email): add validate account page
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Salas Bastidas committed Jan 20, 2017
1 parent 05ad49c commit 2f49dcb
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 18 deletions.
2 changes: 2 additions & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@
<script src="scripts/services/about.js"></script>
<script src="scripts/services/entityconfig.js"></script>
<script src="scripts/controllers/contact.js"></script>
<script src="scripts/services/account.js"></script>
<script src="scripts/controllers/accountvalidation.js"></script>
<!-- endbuild -->
<script src="config.js"></script>
</body>
Expand Down
5 changes: 5 additions & 0 deletions app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
26 changes: 26 additions & 0 deletions app/scripts/controllers/accountvalidation.js
Original file line number Diff line number Diff line change
@@ -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');
};
});
41 changes: 41 additions & 0 deletions app/scripts/services/account.js
Original file line number Diff line number Diff line change
@@ -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;
}
};
});
32 changes: 16 additions & 16 deletions app/scripts/services/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion app/scripts/services/pluginobjectnames.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ angular.module('FlyveMDM')
Policy: "/PluginStorkmdmPolicy",
PolicyCategory: "/PluginStorkmdmPolicyCategory",
User: "/PluginStorkmdmUser",
WellknownPath: "/PluginStorkmdmWellknownPath"
WellknownPath: "/PluginStorkmdmWellknownPath",
AccountValidation: "/PluginStorkmdmAccountvalidation"
});
2 changes: 1 addition & 1 deletion app/styles/_viewport.sass
Original file line number Diff line number Diff line change
Expand Up @@ -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 &
Expand Down
16 changes: 16 additions & 0 deletions app/views/accountvalidation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<section class="login-page">
<div class="container" layout="column" layout-padding="" layout-wrap="" layout-fill="" ng-cloak="">
<md-card class="login-card">
<img ng-src="images/logo-flyve-login.png" class="md-card-image" alt="Flyve MDM Logo">
<md-card-actions layout="row" layout-align="center center">
<md-button ng-click="goToLogin($event)" ng-if="show_login">Login page</md-button>
<md-button class="md-raised md-primary" ng-click="validateAccount($event)" ng-disabled="lock_submit" ng-if="!show_login">Validate account</md-button>
</md-card-actions>
</md-card>
</div>

<div class="md-body-1 layout-margin foo" layout="row" layout-align="end center">
<p>A solution powered by</p>
<a href="http://teclib-edition.com/en/" target=_blank title="Teclib'' Web Site"><img src="images/logo-teclib-blanc-1-2.png" alt="Flyve Logo" height="24"></a>
</div>
</section>

0 comments on commit 2f49dcb

Please sign in to comment.