1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-01 13:13:36 +01:00

Few fixes to services and login

This commit is contained in:
Kyle Spearrin 2016-09-02 01:20:41 -04:00
parent 88c1c4b3dd
commit 8fafe2bd6d
6 changed files with 72 additions and 9 deletions

View File

@ -3,7 +3,9 @@
.controller('accountsLoginController', function ($scope, $state) { .controller('accountsLoginController', function ($scope, $state) {
$scope.login = function (model) { $scope.login = function (model) {
g_authService.logIn(model.email, model.masterPassword, function () {
$state.go('tabs.current'); $state.go('tabs.current');
});
}; };
$scope.twoFactor = function (model) { $scope.twoFactor = function (model) {

View File

@ -8,7 +8,7 @@
<link rel="stylesheet" href="../node_modules/ionic-framework-v1/css/ionic.css"> <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/ionic.bundle.js"></script>
<script src="../node_modules/sjcl/core/sjcl.js"></script> <script src="../node_modules/sjcl/sjcl.js"></script>
<script src="../node_modules/sjcl/core/cbc.js"></script> <script src="../node_modules/sjcl/core/cbc.js"></script>
<script src="../node_modules/sjcl/core/bitArray.js"></script> <script src="../node_modules/sjcl/core/bitArray.js"></script>

View File

@ -3,6 +3,7 @@
"version": "0.0.1", "version": "0.0.1",
"devDependencies": { "devDependencies": {
"ionic-framework-v1": "1.3.1", "ionic-framework-v1": "1.3.1",
"sjcl": "1.0.3" "sjcl": "1.0.3",
"angular-jwt": "0.0.9"
} }
} }

View File

@ -1,15 +1,47 @@
var g_authService = function () { var g_authService = function () {
var _service = {}, _userProfile = null; var _service = {}, _userProfile = null;
_service.logIn = function (email, masterPassword) { _service.logIn = function (email, masterPassword, callback) {
return; if (!callback || typeof callback !== 'function') {
throw 'callback function required';
}
var key = g_cryptoService.makeKey(masterPassword, email);
var request = {
email: email,
masterPasswordHash: g_cryptoService.hashPassword(masterPassword, key)
}; };
_service.logInTwoFactor = function (code, provider) { var response = {
Token: "",
Profile: {
}
};
g_tokenService.setToken(response.Token, function () {
g_cryptoService.setKey(key, function () {
_service.setUserProfile(response.Profile, function () {
callback();
});
});
});
};
_service.logInTwoFactor = function (code, provider, callback) {
if (!callback || typeof callback !== 'function') {
throw 'callback function required';
}
return; return;
}; };
_service.logOut = function (callback) { _service.logOut = function (callback) {
if (!callback || typeof callback !== 'function') {
throw 'callback function required';
}
g_tokenService.clearToken(function () { g_tokenService.clearToken(function () {
g_cryptoService.clearKey(function () { g_cryptoService.clearKey(function () {
_userProfile = null; _userProfile = null;
@ -19,6 +51,10 @@
}; };
_service.getUserProfile = function (callback) { _service.getUserProfile = function (callback) {
if (!callback || typeof callback !== 'function') {
throw 'callback function required';
}
if (!_userProfile) { if (!_userProfile) {
_service.setUserProfile(null, function () { _service.setUserProfile(null, function () {
callback(_userProfile); callback(_userProfile);
@ -29,6 +65,10 @@
}; };
_service.setUserProfile = function (profile, callback) { _service.setUserProfile = function (profile, callback) {
if (!callback || typeof callback !== 'function') {
throw 'callback function required';
}
g_tokenService.getToken(function (token) { g_tokenService.getToken(function (token) {
if (!token) { if (!token) {
return; return;
@ -63,16 +103,24 @@
} }
_service.isAuthenticated = function (callback) { _service.isAuthenticated = function (callback) {
if (!callback || typeof callback !== 'function') {
throw 'callback function required';
}
callback(_service.getUserProfile(function (profile) { callback(_service.getUserProfile(function (profile) {
return profile !== null && !profile.twoFactor; return profile !== null && !profile.twoFactor;
})); }));
}; };
_service.isTwoFactorAuthenticated = function (callback) { _service.isTwoFactorAuthenticated = function (callback) {
if (!callback || typeof callback !== 'function') {
throw 'callback function required';
}
callback(_service.getUserProfile(function (profile) { callback(_service.getUserProfile(function (profile) {
return profile !== null && profile.twoFactor; return profile !== null && profile.twoFactor;
})); }));
}; };
return _service; return _service;
}; }();

View File

@ -125,4 +125,4 @@
}; };
return _service; return _service;
}; }();

View File

@ -2,6 +2,10 @@
var _service = {}, _token; var _service = {}, _token;
_service.setToken = function (token, callback) { _service.setToken = function (token, callback) {
if (!callback || typeof callback !== 'function') {
throw 'callback function required';
}
_token = token; _token = token;
chrome.storage.local.set({ chrome.storage.local.set({
'authBearer': token 'authBearer': token
@ -11,6 +15,10 @@
}; };
_service.getToken = function (callback) { _service.getToken = function (callback) {
if (!callback || typeof callback !== 'function') {
throw 'callback function required';
}
if (_token) { if (_token) {
return callback(_token); return callback(_token);
} }
@ -25,6 +33,10 @@
}; };
_service.clearToken = function (callback) { _service.clearToken = function (callback) {
if (!callback || typeof callback !== 'function') {
throw 'callback function required';
}
_token = null; _token = null;
chrome.storage.local.remove('authBearer', function () { chrome.storage.local.remove('authBearer', function () {
callback(); callback();
@ -32,4 +44,4 @@
}; };
return _service; return _service;
}; }();