mirror of
https://github.com/bitwarden/browser
synced 2025-12-18 01:03:35 +00:00
refactor custom env urls, cleanup bg script a bit
This commit is contained in:
@@ -2,20 +2,17 @@
|
||||
.module('bit.accounts')
|
||||
|
||||
.controller('accountsLoginTwoFactorController', function ($scope, $state, authService, toastr, utilsService, SweetAlert,
|
||||
$analytics, i18nService, $stateParams, $filter, constantsService, $timeout, $window, cryptoService, apiService) {
|
||||
$analytics, i18nService, $stateParams, $filter, constantsService, $timeout, $window, cryptoService, apiService,
|
||||
environmentService) {
|
||||
$scope.i18n = i18nService;
|
||||
utilsService.initListSectionItemListeners($(document), angular);
|
||||
|
||||
var customWebVaultUrl = null;
|
||||
var storedBaseUrl = $window.localStorage.getItem(constantsService.baseUrlKey);
|
||||
if (storedBaseUrl) {
|
||||
customWebVaultUrl = storedBaseUrl;
|
||||
if (environmentService.baseUrl) {
|
||||
customWebVaultUrl = environmentService.baseUrl;
|
||||
}
|
||||
else {
|
||||
var storedWebVaultUrl = $window.localStorage.getItem(constantsService.webVaultUrlKey);
|
||||
if (storedWebVaultUrl) {
|
||||
customWebVaultUrl = storedWebVaultUrl;
|
||||
}
|
||||
else if (environmentService.webVaultUrl) {
|
||||
customWebVaultUrl = environmentService.webVaultUrl;
|
||||
}
|
||||
|
||||
var u2f = new U2f(customWebVaultUrl, function (data) {
|
||||
|
||||
@@ -48,4 +48,7 @@
|
||||
})
|
||||
.factory('totpService', function () {
|
||||
return chrome.extension.getBackgroundPage().bg_totpService;
|
||||
})
|
||||
.factory('environmentService', function () {
|
||||
return chrome.extension.getBackgroundPage().bg_environmentService;
|
||||
});
|
||||
|
||||
@@ -1,60 +1,34 @@
|
||||
angular
|
||||
.module('bit.settings')
|
||||
|
||||
.controller('settingsEnvironmentController', function ($scope, i18nService, $analytics, constantsService, utilsService,
|
||||
$window, apiService, toastr) {
|
||||
.controller('settingsEnvironmentController', function ($scope, i18nService, $analytics, utilsService,
|
||||
environmentService, toastr, $timeout) {
|
||||
$scope.i18n = i18nService;
|
||||
|
||||
utilsService.initListSectionItemListeners($(document), angular);
|
||||
|
||||
$scope.baseUrl = $window.localStorage.getItem(constantsService.baseUrlKey) || '';
|
||||
$scope.webVaultUrl = $window.localStorage.getItem(constantsService.webVaultUrlKey) || '';
|
||||
$scope.apiUrl = $window.localStorage.getItem(constantsService.apiUrlKey) || '';
|
||||
$scope.identityUrl = $window.localStorage.getItem(constantsService.identityUrlKey) || '';
|
||||
$scope.baseUrl = environmentService.baseUrl || '';
|
||||
$scope.webVaultUrl = environmentService.webVaultUrl || '';
|
||||
$scope.apiUrl = environmentService.apiUrl || '';
|
||||
$scope.identityUrl = environmentService.identityUrl || '';
|
||||
|
||||
$scope.save = function () {
|
||||
if ($scope.baseUrl && $scope.baseUrl !== '') {
|
||||
$scope.baseUrl = formatUrl($scope.baseUrl);
|
||||
$window.localStorage.setItem(constantsService.baseUrlKey, $scope.baseUrl);
|
||||
}
|
||||
else {
|
||||
$window.localStorage.removeItem(constantsService.baseUrlKey);
|
||||
}
|
||||
environmentService.setUrls({
|
||||
base: $scope.baseUrl,
|
||||
api: $scope.apiUrl,
|
||||
identity: $scope.identityUrl,
|
||||
webVault: $scope.webVaultUrl
|
||||
}, function (resUrls) {
|
||||
$timeout(function () {
|
||||
// re-set urls since service can change them, ex: prefixing https://
|
||||
$scope.baseUrl = resUrls.base;
|
||||
$scope.apiUrl = resUrls.api;
|
||||
$scope.identityUrl = resUrls.identity;
|
||||
$scope.webVaultUrl = resUrls.webVault;
|
||||
|
||||
if ($scope.webVaultUrl && $scope.webVaultUrl !== '') {
|
||||
$scope.webVaultUrl = formatUrl($scope.webVaultUrl);
|
||||
$window.localStorage.setItem(constantsService.webVaultUrlKey, $scope.webVaultUrl);
|
||||
}
|
||||
else {
|
||||
$window.localStorage.removeItem(constantsService.webVaultUrlKey);
|
||||
}
|
||||
|
||||
if ($scope.apiUrl && $scope.apiUrl !== '') {
|
||||
$scope.apiUrl = formatUrl($scope.apiUrl);
|
||||
$window.localStorage.setItem(constantsService.apiUrlKey, $scope.apiUrl);
|
||||
}
|
||||
else {
|
||||
$window.localStorage.removeItem(constantsService.apiUrlKey);
|
||||
}
|
||||
|
||||
if ($scope.identityUrl && $scope.identityUrl !== '') {
|
||||
$scope.identityUrl = formatUrl($scope.identityUrl);
|
||||
$window.localStorage.setItem(constantsService.identityUrlKey, $scope.identityUrl);
|
||||
}
|
||||
else {
|
||||
$window.localStorage.removeItem(constantsService.identityUrlKey);
|
||||
}
|
||||
|
||||
apiService.setUrls();
|
||||
$analytics.eventTrack('Set Environment URLs');
|
||||
toastr.success(i18nService.environmentSaved);
|
||||
$analytics.eventTrack('Set Environment URLs');
|
||||
toastr.success(i18nService.environmentSaved);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
function formatUrl(url) {
|
||||
url = url.replace(/\/+$/g, '');
|
||||
if (!url.startsWith("http://") && !url.startsWith('https://')) {
|
||||
url = 'https://' + url;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user