mirror of
https://github.com/bitwarden/browser
synced 2025-12-20 18:23:31 +00:00
setup various pages and services
This commit is contained in:
23
src/popup/app/accounts/accountsLoginController.js
Normal file
23
src/popup/app/accounts/accountsLoginController.js
Normal file
@@ -0,0 +1,23 @@
|
||||
angular
|
||||
.module('bit.accounts')
|
||||
|
||||
.controller('accountsLoginController', function ($scope, $state, loginService, userService) {
|
||||
$scope.login = function (model) {
|
||||
$scope.loginPromise = loginService.logIn(model.email, model.masterPassword);
|
||||
|
||||
$scope.loginPromise.then(function () {
|
||||
userService.getUserProfile(function (profile) {
|
||||
if (profile.twoFactor) {
|
||||
$state.go('login.twoFactor');
|
||||
}
|
||||
else {
|
||||
$state.go('tabs.current');
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
$scope.twoFactor = function (model) {
|
||||
$state.go('tabs.current');
|
||||
};
|
||||
});
|
||||
2
src/popup/app/accounts/accountsModule.js
Normal file
2
src/popup/app/accounts/accountsModule.js
Normal file
@@ -0,0 +1,2 @@
|
||||
angular
|
||||
.module('bit.accounts', []);
|
||||
22
src/popup/app/accounts/views/accountsLogin.html
Normal file
22
src/popup/app/accounts/views/accountsLogin.html
Normal file
@@ -0,0 +1,22 @@
|
||||
<ion-view view-title="bitwarden">
|
||||
<ion-content>
|
||||
<div class="list">
|
||||
<label class="item item-input">
|
||||
<i class="icon ion-android-mail placeholder-icon"></i>
|
||||
<input type="text" placeholder="Email address" ng-model="model.email">
|
||||
</label>
|
||||
<label class="item item-input">
|
||||
<i class="icon ion-locked placeholder-icon"></i>
|
||||
<input type="password" placeholder="Master password" ng-model="model.masterPassword">
|
||||
</label>
|
||||
</div>
|
||||
<div class="padding">
|
||||
<button class="button button-block button-positive" ng-click="login(model)">
|
||||
Log In
|
||||
</button>
|
||||
<p class="text-center">
|
||||
<a href="#/hint">Get master password hint</a>
|
||||
</p>
|
||||
</div>
|
||||
</ion-content>
|
||||
</ion-view>
|
||||
7
src/popup/app/accounts/views/accountsLoginTwoFactor.html
Normal file
7
src/popup/app/accounts/views/accountsLoginTwoFactor.html
Normal file
@@ -0,0 +1,7 @@
|
||||
<ion-view view-title="bitwarden">
|
||||
<ion-content class="padding">
|
||||
<p>
|
||||
Some content for your login.
|
||||
</p>
|
||||
</ion-content>
|
||||
</ion-view>
|
||||
13
src/popup/app/app.js
Normal file
13
src/popup/app/app.js
Normal file
@@ -0,0 +1,13 @@
|
||||
angular
|
||||
.module('bit', [
|
||||
'ionic',
|
||||
'angular-jwt',
|
||||
|
||||
'bit.services',
|
||||
|
||||
'bit.accounts',
|
||||
'bit.current',
|
||||
'bit.vault',
|
||||
'bit.settings',
|
||||
'bit.tools'
|
||||
]);
|
||||
110
src/popup/app/config.js
Normal file
110
src/popup/app/config.js
Normal file
@@ -0,0 +1,110 @@
|
||||
angular
|
||||
.module('bit')
|
||||
|
||||
.config(function ($stateProvider, $urlRouterProvider, $httpProvider, jwtInterceptorProvider) {
|
||||
jwtInterceptorProvider.urlParam = 'access_token';
|
||||
jwtInterceptorProvider.tokenGetter = /*@ngInject*/ function (config, appSettings, tokenService) {
|
||||
if (config.url.indexOf(appSettings.apiUri) === 0) {
|
||||
tokenService.getToken(function (token) {
|
||||
return token;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
if ($httpProvider.defaults.headers.post) {
|
||||
$httpProvider.defaults.headers.post = {};
|
||||
}
|
||||
|
||||
$httpProvider.defaults.headers.post['Content-Type'] = 'text/plain; charset=utf-8';
|
||||
|
||||
//$httpProvider.interceptors.push('apiInterceptor');
|
||||
$httpProvider.interceptors.push('jwtInterceptor');
|
||||
|
||||
$urlRouterProvider.otherwise(function ($injector, $location) {
|
||||
var $state = $injector.get("$state");
|
||||
$state.go("login");
|
||||
});
|
||||
|
||||
$stateProvider
|
||||
.state('login', {
|
||||
url: "/login",
|
||||
controller: 'accountsLoginController',
|
||||
templateUrl: "app/accounts/views/accountsLogin.html",
|
||||
data: {
|
||||
authorize: false
|
||||
}
|
||||
})
|
||||
.state('login.twoFactor', {
|
||||
url: "/two-factor",
|
||||
controller: 'accountsLoginController',
|
||||
templateUrl: "app/accounts/views/accountsLoginTwoFactor.html"
|
||||
})
|
||||
|
||||
.state('tabs', {
|
||||
url: "/tab",
|
||||
abstract: true,
|
||||
templateUrl: "app/global/tabs.html",
|
||||
data: {
|
||||
authorize: true
|
||||
}
|
||||
})
|
||||
.state('tabs.current', {
|
||||
url: "/current",
|
||||
views: {
|
||||
'current-tab': {
|
||||
templateUrl: "app/current/views/current.html",
|
||||
controller: 'currentController'
|
||||
}
|
||||
}
|
||||
})
|
||||
.state('tabs.vault', {
|
||||
url: "/vault",
|
||||
views: {
|
||||
'vault-tab': {
|
||||
templateUrl: "app/vault/views/vault.html",
|
||||
controller: 'vaultController'
|
||||
}
|
||||
}
|
||||
})
|
||||
.state('tabs.settings', {
|
||||
url: "/settings",
|
||||
views: {
|
||||
'settings-tab': {
|
||||
templateUrl: "app/settings/views/settings.html",
|
||||
controller: 'settingsController'
|
||||
}
|
||||
}
|
||||
})
|
||||
.state('tabs.tools', {
|
||||
url: "/tools",
|
||||
views: {
|
||||
'tools-tab': {
|
||||
templateUrl: "app/tools/views/tools.html",
|
||||
controller: 'toolsController'
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
.run(function ($rootScope, userService, loginService, jwtHelper, tokenService, $state) {
|
||||
$rootScope.$on('$stateChangeStart', function (event, toState, toParams) {
|
||||
tokenService.getToken(function (token) {
|
||||
userService.isAuthenticated(function (isAuthenticated) {
|
||||
if (!toState.data || !toState.data.authorize) {
|
||||
if (isAuthenticated && !jwtHelper.isTokenExpired(token)) {
|
||||
event.preventDefault();
|
||||
$state.go('tabs.current');
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isAuthenticated || jwtHelper.isTokenExpired(token)) {
|
||||
event.preventDefault();
|
||||
loginService.logOut(function () {
|
||||
$state.go('login');
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
6
src/popup/app/current/currentController.js
Normal file
6
src/popup/app/current/currentController.js
Normal file
@@ -0,0 +1,6 @@
|
||||
angular
|
||||
.module('bit.current')
|
||||
|
||||
.controller('currentController', function ($scope) {
|
||||
|
||||
});
|
||||
2
src/popup/app/current/currentModule.js
Normal file
2
src/popup/app/current/currentModule.js
Normal file
@@ -0,0 +1,2 @@
|
||||
angular
|
||||
.module('bit.current', []);
|
||||
7
src/popup/app/current/views/current.html
Normal file
7
src/popup/app/current/views/current.html
Normal file
@@ -0,0 +1,7 @@
|
||||
<ion-view view-title="Current Sites">
|
||||
<ion-content class="padding">
|
||||
<p>
|
||||
Some content for your current sites.
|
||||
</p>
|
||||
</ion-content>
|
||||
</ion-view>
|
||||
14
src/popup/app/global/tabs.html
Normal file
14
src/popup/app/global/tabs.html
Normal file
@@ -0,0 +1,14 @@
|
||||
<ion-tabs class="tabs-icon-top tabs-positive">
|
||||
<ion-tab title="Current Sites" icon="ion-arrow-swap" ui-sref="tabs.current">
|
||||
<ion-nav-view name="current-tab"></ion-nav-view>
|
||||
</ion-tab>
|
||||
<ion-tab title="My Vault" icon="ion-android-lock" ui-sref="tabs.vault">
|
||||
<ion-nav-view name="vault-tab"></ion-nav-view>
|
||||
</ion-tab>
|
||||
<ion-tab title="Tools" icon="ion-settings" ui-sref="tabs.tools">
|
||||
<ion-nav-view name="tools-tab"></ion-nav-view>
|
||||
</ion-tab>
|
||||
<ion-tab title="Settings" icon="ion-gear-b" ui-sref="tabs.settings">
|
||||
<ion-nav-view name="settings-tab"></ion-nav-view>
|
||||
</ion-tab>
|
||||
</ion-tabs>
|
||||
53
src/popup/app/services/apiService.js
Normal file
53
src/popup/app/services/apiService.js
Normal file
@@ -0,0 +1,53 @@
|
||||
angular
|
||||
.module('bit.services')
|
||||
|
||||
.factory('apiService', function ($resource, appSettings) {
|
||||
var _service = {},
|
||||
_apiUri = appSettings.apiUri;
|
||||
|
||||
_service.sites = $resource(_apiUri + '/sites/:id', {}, {
|
||||
get: { method: 'GET', params: { id: '@id' } },
|
||||
list: { method: 'GET', params: {} },
|
||||
post: { method: 'POST', params: {} },
|
||||
put: { method: 'POST', params: { id: '@id' } },
|
||||
del: { url: _apiUri + '/sites/:id/delete', method: 'POST', params: { id: '@id' } }
|
||||
});
|
||||
|
||||
_service.folders = $resource(_apiUri + '/folders/:id', {}, {
|
||||
get: { method: 'GET', params: { id: '@id' } },
|
||||
list: { method: 'GET', params: {} },
|
||||
post: { method: 'POST', params: {} },
|
||||
put: { method: 'POST', params: { id: '@id' } },
|
||||
del: { url: _apiUri + '/folders/:id/delete', method: 'POST', params: { id: '@id' } }
|
||||
});
|
||||
|
||||
_service.ciphers = $resource(_apiUri + '/ciphers/:id', {}, {
|
||||
get: { method: 'GET', params: { id: '@id' } },
|
||||
list: { method: 'GET', params: {} },
|
||||
'import': { url: _apiUri + '/ciphers/import', method: 'POST', params: {} },
|
||||
favorite: { url: _apiUri + '/ciphers/:id/favorite', method: 'POST', params: { id: '@id' } },
|
||||
del: { url: _apiUri + '/ciphers/:id/delete', method: 'POST', params: { id: '@id' } }
|
||||
});
|
||||
|
||||
_service.accounts = $resource(_apiUri + '/accounts', {}, {
|
||||
register: { url: _apiUri + '/accounts/register', method: 'POST', params: {} },
|
||||
emailToken: { url: _apiUri + '/accounts/email-token', method: 'POST', params: {} },
|
||||
email: { url: _apiUri + '/accounts/email', method: 'POST', params: {} },
|
||||
putPassword: { url: _apiUri + '/accounts/password', method: 'POST', params: {} },
|
||||
getProfile: { url: _apiUri + '/accounts/profile', method: 'GET', params: {} },
|
||||
putProfile: { url: _apiUri + '/accounts/profile', method: 'POST', params: {} },
|
||||
getTwoFactor: { url: _apiUri + '/accounts/two-factor', method: 'GET', params: {} },
|
||||
putTwoFactor: { url: _apiUri + '/accounts/two-factor', method: 'POST', params: {} },
|
||||
postPasswordHint: { url: _apiUri + '/accounts/password-hint', method: 'POST', params: {} },
|
||||
putSecurityStamp: { url: _apiUri + '/accounts/security-stamp', method: 'POST', params: {} },
|
||||
'import': { url: _apiUri + '/accounts/import', method: 'POST', params: {} },
|
||||
postDelete: { url: _apiUri + '/accounts/delete', method: 'POST', params: {} }
|
||||
});
|
||||
|
||||
_service.auth = $resource(_apiUri + '/auth', {}, {
|
||||
token: { url: _apiUri + '/auth/token', method: 'POST', params: {} },
|
||||
tokenTwoFactor: { url: _apiUri + '/auth/token/two-factor', method: 'POST', params: {} }
|
||||
});
|
||||
|
||||
return _service;
|
||||
});
|
||||
12
src/popup/app/services/backgroundService.js
Normal file
12
src/popup/app/services/backgroundService.js
Normal file
@@ -0,0 +1,12 @@
|
||||
angular
|
||||
.module('bit.services')
|
||||
|
||||
.factory('tokenService', function () {
|
||||
return chrome.extension.getBackgroundPage().tokenService;
|
||||
})
|
||||
.factory('cryptoService', function () {
|
||||
return chrome.extension.getBackgroundPage().cryptoService;
|
||||
})
|
||||
.factory('userService', function () {
|
||||
return chrome.extension.getBackgroundPage().userService;
|
||||
});
|
||||
68
src/popup/app/services/loginService.js
Normal file
68
src/popup/app/services/loginService.js
Normal file
@@ -0,0 +1,68 @@
|
||||
angular
|
||||
.module('bit.services')
|
||||
|
||||
.factory('loginService', function (cryptoService, apiService, userService, tokenService, $q) {
|
||||
var _service = {};
|
||||
|
||||
_service.logIn = function (email, masterPassword) {
|
||||
var key = cryptoService.makeKey(masterPassword, email);
|
||||
|
||||
var request = {
|
||||
email: email,
|
||||
masterPasswordHash: cryptoService.hashPassword(masterPassword, key)
|
||||
};
|
||||
|
||||
var deferred = $q.defer();
|
||||
apiService.auth.token(request, function (response) {
|
||||
if (!response || !response.Token) {
|
||||
return;
|
||||
}
|
||||
|
||||
tokenService.setToken(response.Token, function () {
|
||||
cryptoService.setKey(key, function () {
|
||||
userService.setUserProfile(response.Profile, function () {
|
||||
deferred.resolve(response);
|
||||
});
|
||||
});
|
||||
});
|
||||
}, function (error) {
|
||||
deferred.reject(error);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
_service.logInTwoFactor = function (code, provider) {
|
||||
var request = {
|
||||
code: code,
|
||||
provider: provider
|
||||
};
|
||||
|
||||
var deferred = $q.defer();
|
||||
apiService.auth.tokenTwoFactor(request, function (response) {
|
||||
if (!response || !response.Token) {
|
||||
return;
|
||||
}
|
||||
|
||||
tokenService.setToken(response.Token, function () {
|
||||
userService.setUserProfile(response.Profile, function () {
|
||||
deferred.resolve(response);
|
||||
});
|
||||
});
|
||||
}, function (error) {
|
||||
deferred.reject(error);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
_service.logOut = function () {
|
||||
tokenService.clearToken(function () {
|
||||
cryptoService.clearKey(function () {
|
||||
userService.clearUserProfile();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
return _service;
|
||||
});
|
||||
2
src/popup/app/services/servicesModule.js
Normal file
2
src/popup/app/services/servicesModule.js
Normal file
@@ -0,0 +1,2 @@
|
||||
angular
|
||||
.module('bit.services', ['ngResource', 'angular-jwt']);
|
||||
2
src/popup/app/settings.js
Normal file
2
src/popup/app/settings.js
Normal file
@@ -0,0 +1,2 @@
|
||||
angular.module("bit")
|
||||
.constant("appSettings", { "rememberdEmailCookieName": "bit.rememberedEmail", "version": "0.0.1", "environment": "Development", "apiUri": "https://api.bitwarden.com" });
|
||||
6
src/popup/app/settings/settingsController.js
Normal file
6
src/popup/app/settings/settingsController.js
Normal file
@@ -0,0 +1,6 @@
|
||||
angular
|
||||
.module('bit.settings')
|
||||
|
||||
.controller('settingsController', function ($scope) {
|
||||
|
||||
});
|
||||
2
src/popup/app/settings/settingsModule.js
Normal file
2
src/popup/app/settings/settingsModule.js
Normal file
@@ -0,0 +1,2 @@
|
||||
angular
|
||||
.module('bit.settings', []);
|
||||
7
src/popup/app/settings/views/settings.html
Normal file
7
src/popup/app/settings/views/settings.html
Normal file
@@ -0,0 +1,7 @@
|
||||
<ion-view view-title="Settings">
|
||||
<ion-content class="padding">
|
||||
<p>
|
||||
Some content for your settings.
|
||||
</p>
|
||||
</ion-content>
|
||||
</ion-view>
|
||||
6
src/popup/app/tools/toolsController.js
Normal file
6
src/popup/app/tools/toolsController.js
Normal file
@@ -0,0 +1,6 @@
|
||||
angular
|
||||
.module('bit.tools')
|
||||
|
||||
.controller('toolsController', function ($scope) {
|
||||
|
||||
});
|
||||
2
src/popup/app/tools/toolsModule.js
Normal file
2
src/popup/app/tools/toolsModule.js
Normal file
@@ -0,0 +1,2 @@
|
||||
angular
|
||||
.module('bit.tools', []);
|
||||
7
src/popup/app/tools/views/tools.html
Normal file
7
src/popup/app/tools/views/tools.html
Normal file
@@ -0,0 +1,7 @@
|
||||
<ion-view view-title="Tools">
|
||||
<ion-content class="padding">
|
||||
<p>
|
||||
Some content for your tools.
|
||||
</p>
|
||||
</ion-content>
|
||||
</ion-view>
|
||||
6
src/popup/app/vault/vaultController.js
Normal file
6
src/popup/app/vault/vaultController.js
Normal file
@@ -0,0 +1,6 @@
|
||||
angular
|
||||
.module('bit.vault')
|
||||
|
||||
.controller('vaultController', function ($scope) {
|
||||
|
||||
});
|
||||
2
src/popup/app/vault/vaultModule.js
Normal file
2
src/popup/app/vault/vaultModule.js
Normal file
@@ -0,0 +1,2 @@
|
||||
angular
|
||||
.module('bit.vault', []);
|
||||
7
src/popup/app/vault/views/vault.html
Normal file
7
src/popup/app/vault/views/vault.html
Normal file
@@ -0,0 +1,7 @@
|
||||
<ion-view view-title="My Vault">
|
||||
<ion-content class="padding">
|
||||
<p>
|
||||
Some content for your vault.
|
||||
</p>
|
||||
</ion-content>
|
||||
</ion-view>
|
||||
51
src/popup/index.html
Normal file
51
src/popup/index.html
Normal file
@@ -0,0 +1,51 @@
|
||||
<html ng-app="bit">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
|
||||
|
||||
<title>bitwarden</title>
|
||||
|
||||
<link rel="stylesheet" href="../node_modules/ionic-framework-v1/css/ionic.css">
|
||||
<script src="../node_modules/ionic-framework-v1/js/ionic.bundle.js"></script>
|
||||
<script src="../node_modules/ionic-framework-v1/js/angular/angular-resource.js"></script>
|
||||
<script src="../node_modules/angular-jwt/dist/angular-jwt.js"></script>
|
||||
|
||||
<script src="app/app.js"></script>
|
||||
<script src="app/settings.js"></script>
|
||||
<script src="app/config.js"></script>
|
||||
|
||||
<script src="app/services/servicesModule.js"></script>
|
||||
<script src="app/services/backgroundService.js"></script>
|
||||
<script src="app/services/apiService.js"></script>
|
||||
<script src="app/services/loginService.js"></script>
|
||||
|
||||
<script src="app/accounts/accountsModule.js"></script>
|
||||
<script src="app/accounts/accountsLoginController.js"></script>
|
||||
|
||||
<script src="app/current/currentModule.js"></script>
|
||||
<script src="app/current/currentController.js"></script>
|
||||
|
||||
<script src="app/vault/vaultModule.js"></script>
|
||||
<script src="app/vault/vaultController.js"></script>
|
||||
|
||||
<script src="app/settings/settingsModule.js"></script>
|
||||
<script src="app/settings/settingsController.js"></script>
|
||||
|
||||
<script src="app/tools/toolsModule.js"></script>
|
||||
<script src="app/tools/toolsController.js"></script>
|
||||
|
||||
<style>
|
||||
body {
|
||||
width: 320px;
|
||||
height: 480px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<ion-nav-bar class="bar-positive">
|
||||
<ion-nav-back-button>
|
||||
</ion-nav-back-button>
|
||||
</ion-nav-bar>
|
||||
<ion-nav-view></ion-nav-view>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user