1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-11 14:48:46 +01:00
bitwarden-browser/src/app/config.js

329 lines
13 KiB
JavaScript
Raw Normal View History

2015-12-09 04:35:05 +01:00
angular
.module('bit')
2017-03-22 04:05:14 +01:00
.config(function ($stateProvider, $urlRouterProvider, $httpProvider, jwtInterceptorProvider, jwtOptionsProvider,
2017-05-08 20:45:14 +02:00
$uibTooltipProvider, toastrConfig, $locationProvider, $qProvider, stripeProvider, appSettings) {
2017-03-22 04:05:14 +01:00
$qProvider.errorOnUnhandledRejections(false);
$locationProvider.hashPrefix('');
jwtOptionsProvider.config({
2017-05-07 03:32:51 +02:00
urlParam: 'access_token3',
2017-07-05 21:36:40 +02:00
whiteListedDomains: ['api.bitwarden.com', 'preview-api.bitwarden.com', 'localhost', '192.168.1.4']
2017-03-22 04:05:14 +01:00
});
2017-01-28 22:09:38 +01:00
var refreshPromise;
2017-05-08 20:45:14 +02:00
jwtInterceptorProvider.tokenGetter = /*@ngInject*/ function (options, tokenService, authService) {
2017-03-22 04:05:14 +01:00
if (options.url.indexOf(appSettings.apiUri) !== 0) {
return;
2015-12-09 04:35:05 +01:00
}
2017-01-28 22:09:38 +01:00
if (refreshPromise) {
return refreshPromise;
}
var token = tokenService.getToken();
if (!token) {
return;
}
2017-01-28 22:09:38 +01:00
if (!tokenService.tokenNeedsRefresh(token)) {
return token;
}
refreshPromise = authService.refreshAccessToken().then(function (newToken) {
2017-01-28 22:09:38 +01:00
refreshPromise = null;
return newToken || token;
2017-01-28 22:09:38 +01:00
});
return refreshPromise;
2015-12-09 04:35:05 +01:00
};
2017-05-08 20:45:14 +02:00
stripeProvider.setPublishableKey(appSettings.stripeKey);
2017-04-04 16:14:54 +02:00
2015-12-09 04:35:05 +01:00
angular.extend(toastrConfig, {
closeButton: true,
progressBar: true,
showMethod: 'slideDown',
target: '.toast-target'
});
$uibTooltipProvider.options({
2017-01-05 04:23:21 +01:00
popupDelay: 600,
appendToBody: true
2015-12-09 04:35:05 +01:00
});
if ($httpProvider.defaults.headers.post) {
$httpProvider.defaults.headers.post = {};
2015-12-09 04:35:05 +01:00
}
$httpProvider.defaults.headers.post['Content-Type'] = 'text/plain; charset=utf-8';
2015-12-09 04:35:05 +01:00
$httpProvider.interceptors.push('apiInterceptor');
$httpProvider.interceptors.push('jwtInterceptor');
$urlRouterProvider.otherwise('/');
$stateProvider
2017-03-22 04:05:14 +01:00
// Backend
2015-12-09 04:35:05 +01:00
.state('backend', {
templateUrl: 'app/views/backendLayout.html',
abstract: true,
data: {
authorize: true
}
})
.state('backend.user', {
templateUrl: 'app/views/userLayout.html',
abstract: true
})
.state('backend.user.vault', {
url: '^/vault',
2015-12-09 04:35:05 +01:00
templateUrl: 'app/vault/views/vault.html',
controller: 'vaultController',
2017-06-05 16:38:37 +02:00
data: {
pageTitle: 'My Vault',
controlSidebar: true
},
2017-04-21 20:24:24 +02:00
params: {
refreshFromServer: false
}
2015-12-09 04:35:05 +01:00
})
.state('backend.user.shared', {
url: '^/shared',
templateUrl: 'app/vault/views/vaultShared.html',
controller: 'vaultSharedController',
data: { pageTitle: 'Shared' }
2017-03-24 04:01:22 +01:00
})
.state('backend.user.settings', {
2015-12-09 04:35:05 +01:00
url: '^/settings',
templateUrl: 'app/settings/views/settings.html',
controller: 'settingsController',
data: { pageTitle: 'Settings' }
})
.state('backend.user.settingsDomains', {
url: '^/settings/domains',
templateUrl: 'app/settings/views/settingsDomains.html',
controller: 'settingsDomainsController',
data: { pageTitle: 'Domain Settings' }
})
2017-06-19 21:29:33 +02:00
.state('backend.user.settingsTwoStep', {
url: '^/settings/two-step',
templateUrl: 'app/settings/views/settingsTwoStep.html',
controller: 'settingsTwoStepController',
data: { pageTitle: 'Two-step Login' }
})
.state('backend.user.settingsCreateOrg', {
url: '^/settings/create-organization',
templateUrl: 'app/settings/views/settingsCreateOrganization.html',
controller: 'settingsCreateOrganizationController',
data: { pageTitle: 'Create Organization' }
})
.state('backend.user.settingsBilling', {
url: '^/settings/billing',
templateUrl: 'app/settings/views/settingsBilling.html',
controller: 'settingsBillingController',
data: { pageTitle: 'Billing' }
})
.state('backend.user.settingsPremium', {
url: '^/settings/premium',
templateUrl: 'app/settings/views/settingsPremium.html',
controller: 'settingsPremiumController',
data: { pageTitle: 'Go Premium' }
})
.state('backend.user.tools', {
2015-12-09 04:35:05 +01:00
url: '^/tools',
templateUrl: 'app/tools/views/tools.html',
controller: 'toolsController',
data: { pageTitle: 'Tools' }
})
2017-05-26 00:22:19 +02:00
.state('backend.user.reportsBreach', {
2017-05-25 23:41:29 +02:00
url: '^/reports/breach',
2017-05-26 00:22:19 +02:00
templateUrl: 'app/reports/views/reportsBreach.html',
controller: 'reportsBreachController',
2017-05-25 23:41:29 +02:00
data: { pageTitle: 'Data Breach Report' }
})
2017-04-13 16:09:19 +02:00
.state('backend.user.apps', {
url: '^/apps',
templateUrl: 'app/views/apps.html',
controller: 'appsController',
data: { pageTitle: 'Get the Apps' }
})
.state('backend.org', {
templateUrl: 'app/views/organizationLayout.html',
abstract: true
})
.state('backend.org.dashboard', {
2017-03-04 03:53:02 +01:00
url: '^/organization/:orgId',
templateUrl: 'app/organization/views/organizationDashboard.html',
controller: 'organizationDashboardController',
2017-04-06 19:10:43 +02:00
data: { pageTitle: 'Organization Dashboard' }
2017-03-04 03:53:02 +01:00
})
.state('backend.org.people', {
url: '/organization/:orgId/people',
templateUrl: 'app/organization/views/organizationPeople.html',
controller: 'organizationPeopleController',
2017-04-06 19:10:43 +02:00
data: { pageTitle: 'Organization People' }
2017-03-07 05:01:08 +01:00
})
2017-04-27 15:33:12 +02:00
.state('backend.org.collections', {
url: '/organization/:orgId/collections',
templateUrl: 'app/organization/views/organizationCollections.html',
controller: 'organizationCollectionsController',
data: { pageTitle: 'Organization Collections' }
2017-04-06 19:10:43 +02:00
})
.state('backend.org.settings', {
url: '/organization/:orgId/settings',
templateUrl: 'app/organization/views/organizationSettings.html',
controller: 'organizationSettingsController',
data: { pageTitle: 'Organization Settings' }
})
2017-04-06 19:13:54 +02:00
.state('backend.org.billing', {
url: '/organization/:orgId/billing',
templateUrl: 'app/organization/views/organizationBilling.html',
controller: 'organizationBillingController',
data: { pageTitle: 'Organization Billing' }
})
2017-04-17 23:01:12 +02:00
.state('backend.org.vault', {
url: '/organization/:orgId/vault',
templateUrl: 'app/organization/views/organizationVault.html',
controller: 'organizationVaultController',
data: { pageTitle: 'Organization Vault' }
})
2017-04-20 22:31:52 +02:00
.state('backend.org.groups', {
url: '/organization/:orgId/groups',
templateUrl: 'app/organization/views/organizationGroups.html',
controller: 'organizationGroupsController',
data: { pageTitle: 'Organization Groups' }
})
2015-12-09 04:35:05 +01:00
2017-03-22 04:05:14 +01:00
// Frontend
2015-12-09 04:35:05 +01:00
.state('frontend', {
templateUrl: 'app/views/frontendLayout.html',
abstract: true,
data: {
authorize: false
}
})
.state('frontend.login', {
templateUrl: 'app/accounts/views/accountsLogin.html',
controller: 'accountsLoginController',
params: {
2017-03-29 03:16:44 +02:00
returnState: null,
email: null
},
2015-12-09 04:35:05 +01:00
data: {
bodyClass: 'login-page'
}
})
.state('frontend.login.info', {
url: '^/?org',
2015-12-09 04:35:05 +01:00
templateUrl: 'app/accounts/views/accountsLoginInfo.html',
data: {
pageTitle: 'Log In'
}
})
.state('frontend.login.twoFactor', {
2017-06-24 23:15:36 +02:00
url: '^/two-step',
2015-12-09 04:35:05 +01:00
templateUrl: 'app/accounts/views/accountsLoginTwoFactor.html',
data: {
2017-06-24 23:15:36 +02:00
pageTitle: 'Log In (Two-step)'
2015-12-09 04:35:05 +01:00
}
})
.state('frontend.logout', {
url: '^/logout',
controller: 'accountsLogoutController',
data: {
authorize: true
}
})
.state('frontend.passwordHint', {
url: '^/password-hint',
templateUrl: 'app/accounts/views/accountsPasswordHint.html',
controller: 'accountsPasswordHintController',
data: {
pageTitle: 'Master Password Hint',
bodyClass: 'login-page'
}
})
2016-11-15 05:31:54 +01:00
.state('frontend.recover', {
url: '^/recover',
templateUrl: 'app/accounts/views/accountsRecover.html',
controller: 'accountsRecoverController',
data: {
pageTitle: 'Recover Account',
bodyClass: 'login-page'
}
})
2015-12-09 04:35:05 +01:00
.state('frontend.register', {
url: '^/register?org',
2015-12-09 04:35:05 +01:00
templateUrl: 'app/accounts/views/accountsRegister.html',
controller: 'accountsRegisterController',
params: {
2017-03-29 03:16:44 +02:00
returnState: null,
email: null
},
2015-12-09 04:35:05 +01:00
data: {
pageTitle: 'Register',
bodyClass: 'register-page'
}
})
.state('frontend.organizationAccept', {
2017-03-30 02:58:27 +02:00
url: '^/accept-organization?organizationId&organizationUserId&token&email&organizationName',
templateUrl: 'app/accounts/views/accountsOrganizationAccept.html',
controller: 'accountsOrganizationAcceptController',
data: {
pageTitle: 'Accept Organization Invite',
bodyClass: 'login-page',
skipAuthorize: true
}
2017-07-05 21:36:40 +02:00
})
.state('frontend.verifyEmail', {
url: '^/verify-email?userId&token',
templateUrl: 'app/accounts/views/accountsVerifyEmail.html',
controller: 'accountsVerifyEmailController',
data: {
pageTitle: 'Verifying Email',
bodyClass: 'login-page',
skipAuthorize: true
}
2015-12-09 04:35:05 +01:00
});
})
2017-02-24 01:32:34 +01:00
.run(function ($rootScope, authService, $state) {
$rootScope.$on('$stateChangeSuccess', function () {
$('html, body').animate({ scrollTop: 0 }, 200);
});
2015-12-09 04:35:05 +01:00
$rootScope.$on('$stateChangeStart', function (event, toState, toParams) {
if (!toState.data || !toState.data.authorize) {
if (toState.data && toState.data.skipAuthorize) {
return;
2015-12-09 04:35:05 +01:00
}
if (!authService.isAuthenticated()) {
return;
}
event.preventDefault();
$state.go('backend.user.vault');
2017-03-28 03:55:39 +02:00
return;
2015-12-09 04:35:05 +01:00
}
if (!authService.isAuthenticated()) {
2015-12-09 04:35:05 +01:00
event.preventDefault();
authService.logOut();
$state.go('frontend.login.info');
2017-03-28 03:55:39 +02:00
return;
}
// user is guaranteed to be authenticated becuase of previous check
if (toState.name.indexOf('backend.org.') > -1 && toParams.orgId) {
// clear vault rootScope when visiting org admin section
$rootScope.vaultLogins = $rootScope.vaultFolders = null;
2017-03-28 03:55:39 +02:00
authService.getUserProfile().then(function (profile) {
var orgs = profile.organizations;
if (!orgs || !(toParams.orgId in orgs) || orgs[toParams.orgId].status !== 2 ||
orgs[toParams.orgId].type === 2) {
event.preventDefault();
$state.go('backend.user.vault');
}
});
2015-12-09 04:35:05 +01:00
}
});
});