1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-24 16:49:26 +01:00

move some values to constants for better sharing

This commit is contained in:
Kyle Spearrin 2017-04-10 18:55:18 -04:00
parent 58df3e692b
commit cf22ea2b78
9 changed files with 70 additions and 58 deletions

View File

@ -1,6 +1,5 @@
{
"appSettings": {
"rememberedEmailCookieName": "bit.rememberedEmail",
"apiUri": "http://localhost:4000"
}
}

View File

@ -2,10 +2,10 @@ angular
.module('bit.accounts')
.controller('accountsLoginController', function ($scope, $rootScope, $cookies, apiService, cryptoService, authService,
$state, appSettings, $analytics) {
$state, constants, $analytics) {
$scope.state = $state;
var returnState = $state.params.returnState;
var rememberedEmail = $cookies.get(appSettings.rememberedEmailCookieName);
var rememberedEmail = $cookies.get(constants.rememberedEmailCookieName);
if (rememberedEmail || $state.params.email) {
$scope.model = {
email: $state.params.email ? $state.params.email : rememberedEmail,
@ -25,12 +25,12 @@ angular
cookieExpiration.setFullYear(cookieExpiration.getFullYear() + 10);
$cookies.put(
appSettings.rememberedEmailCookieName,
constants.rememberedEmailCookieName,
model.email,
{ expires: cookieExpiration });
}
else {
$cookies.remove(appSettings.rememberedEmailCookieName);
$cookies.remove(constants.rememberedEmailCookieName);
}
if (twoFactorProviders && twoFactorProviders.length > 0) {

40
src/app/constants.js Normal file
View File

@ -0,0 +1,40 @@
angular.module('bit')
.constant('constants', {
rememberedEmailCookieName: 'bit.rememberedEmail',
encType: {
AesCbc256_B64: 0,
AesCbc128_HmacSha256_B64: 1,
AesCbc256_HmacSha256_B64: 2,
RsaOaep_Sha256_B64: 3
},
plans: {
free: {
basePrice: 0,
noAdditionalSeats: true,
noPayment: true,
upgradeSortOrder: -1
},
personal: {
basePrice: 1,
annualBasePrice: 12,
baseSeats: 5,
seatPrice: 1,
annualSeatPrice: 12,
maxAdditionalSeats: 5,
annualPlanType: 'personalAnnually',
upgradeSortOrder: 1
},
teams: {
basePrice: 5,
annualBasePrice: 60,
monthlyBasePrice: 8,
baseSeats: 5,
seatPrice: 2,
annualSeatPrice: 24,
monthlySeatPrice: 2.5,
monthPlanType: 'teamsMonthly',
annualPlanType: 'teamsAnnually',
upgradeSortOrder: 2
}
}
});

View File

@ -5,13 +5,14 @@ angular
.directive('letterAvatar', function () {
// ref: http://stackoverflow.com/a/16348977/1090359
function stringToColor(str) {
var hash = 0;
for (var i = 0; i < str.length; i++) {
var hash = 0,
i = 0;
for (i = 0; i < str.length; i++) {
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
var color = '#';
for (var i = 0; i < 3; i++) {
for (i = 0; i < 3; i++) {
var value = (hash >> (i * 8)) & 0xFF;
color += ('00' + value.toString(16)).substr(-2);
}

View File

@ -76,6 +76,8 @@
$scope.loading = false;
$scope.noSubscription = org.PlanType === 0;
var i = 0;
$scope.plan = {
name: org.Plan,
type: org.PlanType,
@ -103,7 +105,7 @@
if (org.Subscription && org.Subscription.Items) {
$scope.subscription.items = [];
for (var i = 0; i < org.Subscription.Items.length; i++) {
for (i = 0; i < org.Subscription.Items.length; i++) {
$scope.subscription.items.push({
amount: org.Subscription.Items[i].Amount,
name: org.Subscription.Items[i].Name,
@ -123,7 +125,7 @@
}
var charges = [];
for (var i = 0; i < org.Charges.length; i++) {
for (i = 0; i < org.Charges.length; i++) {
charges.push({
date: org.Charges[i].CreatedDate,
paymentSource: org.Charges[i].PaymentSource ? org.Charges[i].PaymentSource.Description : '-',

View File

@ -1,19 +1,13 @@
angular
.module('bit.services')
.factory('cryptoService', function ($sessionStorage) {
.factory('cryptoService', function ($sessionStorage, constants) {
var _service = {},
_key,
_b64Key,
_privateKey,
_publicKey,
_orgKeys,
_encType = {
AesCbc256_B64: 0,
AesCbc128_HmacSha256_B64: 1,
AesCbc256_HmacSha256_B64: 2,
RsaOaep_Sha256_B64: 3
};
_orgKeys;
_service.setKey = function (key) {
_key = key;
@ -261,11 +255,11 @@ angular
var encKey, encType;
if (false) {
encKey = _service.getEncKey(key);
encType = _encType.AesCbc128_HmacSha256_B64;
encType = constants.encType.AesCbc128_HmacSha256_B64;
}
else {
encKey = key || _service.getKey();
encType = _encType.AesCbc256_B64;
encType = constants.encType.AesCbc256_B64;
}
plainValueEncoding = plainValueEncoding || 'utf8';
@ -281,7 +275,8 @@ angular
var ct = forge.util.encode64(ctBytes);
var cipherString = iv + '|' + ct;
if (encType === _encType.AesCbc128_HmacSha256_B64 || encType === _encType.AesCbc256_HmacSha256_B64) {
if (encType === constants.encType.AesCbc128_HmacSha256_B64 ||
encType === constants.encType.AesCbc256_HmacSha256_B64) {
var mac = computeMac(ctBytes, ivBytes);
cipherString = cipherString + '|' + mac;
}
@ -304,7 +299,7 @@ angular
var encryptedBytes = publicKey.encrypt(plainValue, 'RSA-OAEP', {
md: forge.md.sha256.create()
});
return _encType.RsaOaep_Sha256_B64 + '.' + forge.util.encode64(encryptedBytes);
return constants.encType.RsaOaep_Sha256_B64 + '.' + forge.util.encode64(encryptedBytes);
};
_service.decrypt = function (encValue, key, outputEncoding) {
@ -324,26 +319,26 @@ angular
}
}
else {
encType = _encType.AesCbc256_B64;
encType = constants.encType.AesCbc256_B64;
encPieces = encValue.split('|');
}
switch (encType) {
case _encType.AesCbc128_HmacSha256_B64:
case constants.encType.AesCbc128_HmacSha256_B64:
if (encPieces.length !== 3) {
return null;
}
doMacCheck = true;
encKey = _service.getEncKey(key);
break;
case _encType.AesCbc256_HmacSha256_B64:
case constants.encType.AesCbc256_HmacSha256_B64:
if (encPieces.length !== 3) {
return null;
}
doMacCheck = true;
encKey = _service.getEncKey(key);
break;
case _encType.AesCbc256_B64:
case constants.encType.AesCbc256_B64:
if (encPieces.length !== 2) {
return null;
}
@ -395,7 +390,7 @@ angular
encPiece;
if (headerPieces.length === 1) {
encType = _encType.RsaOaep_Sha256_B64;
encType = constants.encType.RsaOaep_Sha256_B64;
encPiece = headerPieces[0];
}
else if (headerPieces.length === 2) {
@ -408,7 +403,7 @@ angular
}
}
if (encType !== _encType.RsaOaep_Sha256_B64) {
if (encType !== constants.encType.RsaOaep_Sha256_B64) {
return null;
}

View File

@ -1,2 +1,2 @@
angular.module("bit")
.constant("appSettings", {"rememberedEmailCookieName":"bit.rememberedEmail","apiUri":"https://api.bitwarden.com","version":"1.9.1","environment":"Production"});
.constant("appSettings", {"apiUri":"https://api.bitwarden.com","version":"1.9.1","environment":"Production"});

View File

@ -2,34 +2,8 @@
.module('bit.settings')
.controller('settingsCreateOrganizationController', function ($scope, $state, apiService, cryptoService,
toastr, $analytics, authService, stripe) {
$scope.plans = {
free: {
basePrice: 0,
noAdditionalSeats: true,
noPayment: true
},
personal: {
basePrice: 1,
annualBasePrice: 12,
baseSeats: 5,
seatPrice: 1,
annualSeatPrice: 12,
maxAdditionalSeats: 5,
annualPlanType: 'personalAnnually'
},
teams: {
basePrice: 5,
annualBasePrice: 60,
monthlyBasePrice: 8,
baseSeats: 5,
seatPrice: 2,
annualSeatPrice: 24,
monthlySeatPrice: 2.5,
monthPlanType: 'teamsMonthly',
annualPlanType: 'teamsAnnually'
}
};
toastr, $analytics, authService, stripe, constants) {
$scope.plans = constants.plans;
$scope.model = {
plan: 'free',
@ -57,7 +31,7 @@
$scope.changedBusiness = function () {
if ($scope.model.ownedBusiness) {
$scope.model.plan = 'teams'
$scope.model.plan = 'teams';
}
};

View File

@ -78,6 +78,7 @@
<script src="app/app.js"></script>
<script src="app/settings.js"></script>
<script src="app/constants.js"></script>
<script src="app/config.js"></script>
<script src="app/apiInterceptor.js"></script>