send device type header

This commit is contained in:
Kyle Spearrin 2017-12-18 13:37:06 -05:00
parent f54884eb79
commit 8d6a96074d
5 changed files with 68 additions and 3 deletions

View File

@ -1,9 +1,13 @@
angular
.module('bit')
.factory('apiInterceptor', function ($injector, $q, toastr) {
.factory('apiInterceptor', function ($injector, $q, toastr, appSettings, utilsService) {
return {
request: function (config) {
if (config.url.indexOf(appSettings.apiUri + '/') > -1) {
config.headers['Device-Type'] = utilsService.getDeviceType();
}
return config;
},
response: function (response) {

View File

@ -39,6 +39,16 @@ angular.module('bit')
hidden: 1,
boolean: 2
},
deviceType: {
chrome: 9,
firefox: 10,
opera: 11,
edge: 12,
ie: 13,
unknown: 14,
safari: 17,
vivaldi: 18
},
eventType: {
User_LoggedIn: 1000,
User_ChangedPassword: 1001,

View File

@ -1,7 +1,7 @@
angular
.module('bit.services')
.factory('apiService', function ($resource, tokenService, appSettings, $httpParamSerializer) {
.factory('apiService', function ($resource, tokenService, appSettings, $httpParamSerializer, utilsService) {
var _service = {},
_apiUri = appSettings.apiUri,
_identityUri = appSettings.identityUri;
@ -190,7 +190,10 @@
token: {
url: _identityUri + '/connect/token',
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8' },
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
'Device-Type': utilsService.getDeviceType()
},
transformRequest: transformUrlEncoded,
skipAuthorization: true,
params: {}

View File

@ -0,0 +1,47 @@
angular
.module('bit.services')
.factory('utilsService', function (constants) {
var _service = {};
var _browserCache;
_service.getDeviceType = function (token) {
if (_browserCache) {
return _browserCache;
}
if (navigator.userAgent.indexOf(' Vivaldi/') >= 0) {
_browserCache = constants.deviceType.vivaldi;
}
else if (!!window.chrome && !!window.chrome.webstore) {
_browserCache = constants.deviceType.chrome;
}
else if (typeof InstallTrigger !== 'undefined') {
_browserCache = constants.deviceType.firefox;
}
else if ((!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0) {
_browserCache = constants.deviceType.firefox;
}
else if (/constructor/i.test(window.HTMLElement) ||
safariCheck(!window['safari'] || (typeof safari !== 'undefined' && safari.pushNotification))) {
_browserCache = constants.deviceType.opera;
}
else if (!!document.documentMode) {
_browserCache = constants.deviceType.ie;
}
else if (!!window.StyleMedia) {
_browserCache = constants.deviceType.edge;
}
else {
_browserCache = constants.deviceType.unknown;
}
return _browserCache;
};
function safariCheck(p) {
return p.toString() === '[object SafariRemoteNotification]';
}
return _service;
});

View File

@ -147,6 +147,7 @@
<script src="app/services/passwordService.js"></script>
<script src="app/services/importService.js"></script>
<script src="app/services/eventService.js"></script>
<script src="app/services/utilsService.js"></script>
<script src="app/global/globalModule.js"></script>
<script src="app/global/mainController.js"></script>