This repository was archived by the owner on Dec 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathstormpath.view-model.js
More file actions
52 lines (42 loc) · 1.44 KB
/
Copy pathstormpath.view-model.js
File metadata and controls
52 lines (42 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
(function () {
'use strict';
function ViewModelService($http, $verifyResponse, STORMPATH_CONFIG) {
this.$http = $http;
this.$verifyResponse = $verifyResponse;
this.STORMPATH_CONFIG = STORMPATH_CONFIG;
}
ViewModelService.prototype.getLoginModel = function getLoginModel() {
var self = this;
return this.$http.get(this.STORMPATH_CONFIG.getUrl('AUTHENTICATION_ENDPOINT'), {
headers: {
'Accept': 'application/json'
}
}).then(function (response) {
var responseStatus = self.$verifyResponse(response);
if (!responseStatus.valid) {
throw responseStatus.error;
}
return response.data;
});
};
ViewModelService.prototype.getRegisterModel = function getRegisterModel() {
var self = this;
return this.$http.get(this.STORMPATH_CONFIG.getUrl('REGISTER_URI'), {
headers: {
'Accept': 'application/json'
}
}).then(function (response) {
var responseStatus = self.$verifyResponse(response);
if (!responseStatus.valid) {
throw responseStatus.error;
}
return response.data;
});
};
angular.module('stormpath.viewModelService', ['stormpath.util'])
.provider('$viewModel', function () {
this.$get = ['$http', '$verifyResponse', 'STORMPATH_CONFIG', function viewModelFactory($http, $verifyResponse, STORMPATH_CONFIG) {
return new ViewModelService($http, $verifyResponse, STORMPATH_CONFIG);
}];
});
}());