1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-25 12:15:18 +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) {
$scope.login = function (model) {
g_authService.logIn(model.email, model.masterPassword, function () {
$state.go('tabs.current');
});
};
$scope.twoFactor = function (model) {

View File

@ -8,7 +8,7 @@
<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/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/bitArray.js"></script>

View File

@ -3,6 +3,7 @@
"version": "0.0.1",
"devDependencies": {
"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 _service = {}, _userProfile = null;
_service.logIn = function (email, masterPassword) {
return;
_service.logIn = function (email, masterPassword, callback) {
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;
};
_service.logOut = function (callback) {
if (!callback || typeof callback !== 'function') {
throw 'callback function required';
}
g_tokenService.clearToken(function () {
g_cryptoService.clearKey(function () {
_userProfile = null;
@ -19,6 +51,10 @@
};
_service.getUserProfile = function (callback) {
if (!callback || typeof callback !== 'function') {
throw 'callback function required';
}
if (!_userProfile) {
_service.setUserProfile(null, function () {
callback(_userProfile);
@ -29,6 +65,10 @@
};
_service.setUserProfile = function (profile, callback) {
if (!callback || typeof callback !== 'function') {
throw 'callback function required';
}
g_tokenService.getToken(function (token) {
if (!token) {
return;
@ -63,16 +103,24 @@
}
_service.isAuthenticated = function (callback) {
if (!callback || typeof callback !== 'function') {
throw 'callback function required';
}
callback(_service.getUserProfile(function (profile) {
return profile !== null && !profile.twoFactor;
}));
};
_service.isTwoFactorAuthenticated = function (callback) {
if (!callback || typeof callback !== 'function') {
throw 'callback function required';
}
callback(_service.getUserProfile(function (profile) {
return profile !== null && profile.twoFactor;
}));
};
return _service;
};
}();

View File

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

View File

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