factoring in backbone user obj
This commit is contained in:
Родитель
14d8e8ee31
Коммит
f216965a98
|
@ -1,56 +1,59 @@
|
|||
var CommandHandler = function(Messaging, CapturedCredentialStorage, Realms) {
|
||||
|
||||
function addLogin(message, sender) {
|
||||
var currentUser = Gombot.getCurrentUser();
|
||||
var notificationObj = message,
|
||||
tabID = sender.tab.id;
|
||||
// User.NeverAsk.checkForHostname(notificationObj.hostname, function(shouldAsk) {
|
||||
// Check to see if the user disabled password saving on this site
|
||||
if (neverSaveOnSites.indexOf(notificationObj.hostname) != -1) return;
|
||||
if (currentUser.get('disabledSites')[notificationObj.hostname]) return;
|
||||
notificationObj.type = 'password_observed';
|
||||
// Look for passwords in use on the current site
|
||||
getLoginsForSite(notificationObj.hostname,function(logins) {
|
||||
if (logins === undefined) logins = [];
|
||||
var loginsForSameUsername = logins.filter(
|
||||
function(l) { return l.username == notificationObj.username; }
|
||||
);
|
||||
if (loginsForSameUsername.length == 1) {
|
||||
// User already has a login saved for this site.
|
||||
|
||||
if (loginsForSameUsername[0].password == notificationObj.password) {
|
||||
// We're just logging into a site with an existing login. Bail.
|
||||
return;
|
||||
}
|
||||
else {
|
||||
// Prompt user to update password
|
||||
notificationObj.type = 'update_password';
|
||||
// If the existing login stored for this site was PIN locked,
|
||||
// make sure this new one will be also.
|
||||
notificationObj.pinLocked = logins[0].pinLocked;
|
||||
}
|
||||
}
|
||||
// Has the user signed up for a Gombot account?
|
||||
checkIfDidFirstRun(function(didFirstRun) {
|
||||
if (didFirstRun) {
|
||||
// Prompt the user to save the login
|
||||
displayInfobar({
|
||||
notify: true,
|
||||
tabID: tabID,
|
||||
notification: notificationObj
|
||||
});
|
||||
}
|
||||
else {
|
||||
// Browser not associated with Gombot account, offer
|
||||
// to create one/log in.
|
||||
displayInfobar({
|
||||
notify: true,
|
||||
tabID: tabID,
|
||||
notification: {
|
||||
type: 'signup_nag'
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
// TODO: Send new login to server
|
||||
var logins = currentUser.get('logins').filter(function(login) {
|
||||
return login.get('hostname') === notificationObj.hostname;
|
||||
});
|
||||
if (logins === undefined) logins = [];
|
||||
var loginsForSameUsername = logins.filter(
|
||||
function(l) { return l.username == notificationObj.username; }
|
||||
);
|
||||
if (loginsForSameUsername.length == 1) {
|
||||
// User already has a login saved for this site.
|
||||
|
||||
if (loginsForSameUsername[0].password == notificationObj.password) {
|
||||
// We're just logging into a site with an existing login. Bail.
|
||||
return;
|
||||
}
|
||||
else {
|
||||
// Prompt user to update password
|
||||
notificationObj.type = 'update_password';
|
||||
// If the existing login stored for this site was PIN locked,
|
||||
// make sure this new one will be also.
|
||||
notificationObj.pinLocked = logins[0].pinLocked;
|
||||
}
|
||||
}
|
||||
// Has the user signed up for a Gombot account?
|
||||
checkIfDidFirstRun(function(didFirstRun) {
|
||||
if (didFirstRun) {
|
||||
// Prompt the user to save the login
|
||||
displayInfobar({
|
||||
notify: true,
|
||||
tabID: tabID,
|
||||
notification: notificationObj
|
||||
});
|
||||
}
|
||||
else {
|
||||
// Browser not associated with Gombot account, offer
|
||||
// to create one/log in.
|
||||
displayInfobar({
|
||||
notify: true,
|
||||
tabID: tabID,
|
||||
notification: {
|
||||
type: 'signup_nag'
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
// TODO: Send new login to server
|
||||
|
||||
}
|
||||
|
||||
function observingPage(message, sender) {
|
||||
|
|
|
@ -33,6 +33,15 @@ Gombot.LoginCredential = LoginCredential(Backbone, _);
|
|||
Gombot.LoginCredentialCollection = LoginCredentialCollection(Backbone, _, Gombot.LoginCredential);
|
||||
Gombot.User = User(Backbone, _, Gombot.LoginCredentialCollection);
|
||||
|
||||
Gombot.getCurrentUser = function() {
|
||||
return this.currentUser;
|
||||
};
|
||||
|
||||
Gombot.setCurrentUser = function(user) {
|
||||
this.currentUser = user;
|
||||
}
|
||||
|
||||
|
||||
var usersStore = new Gombot.Storage("users", function() {
|
||||
Gombot.UserCollection = UserCollection(Backbone, _, Gombot.User, usersStore);
|
||||
initGombot();
|
||||
|
@ -49,82 +58,6 @@ function initGombot() {
|
|||
var showSignInPage = Gombot.users.size() > 0;
|
||||
startFirstRunFlow(showSignInPage);
|
||||
}});
|
||||
// Users.fetch({ success: function(collection, response, options) {
|
||||
// currentUser = collection
|
||||
// }});
|
||||
// Load blacklisted sites from localStorage
|
||||
// loadNeverSaveOnSites();
|
||||
// Load PIN lock state from localStorage
|
||||
// loadLoginsLock();
|
||||
// if (!User.firstRun.wasCompleted()) {
|
||||
// startFirstRunFlow();
|
||||
// }
|
||||
}
|
||||
|
||||
//
|
||||
// Content-to-chrome message handlers
|
||||
//
|
||||
|
||||
|
||||
// TODO: merge into command handlers
|
||||
var messageHandlers = {
|
||||
'add_login': function(message,tabID) {
|
||||
var notificationObj = message;
|
||||
// Check to see if the user disabled password saving on this site
|
||||
User.NeverAsk.checkForHostname(notificationObj.hostname, function(shouldAsk) {
|
||||
if (!shouldAsk) return;
|
||||
notificationObj.type = 'password_observed';
|
||||
notificationObj.hash = SHA1(notificationObj.password);
|
||||
// Look for passwords in use on the current site
|
||||
getLoginsForSite(notificationObj.hostname,function(logins) {
|
||||
if (logins === undefined) logins = [];
|
||||
var loginsForSameUsername = logins.filter(
|
||||
function(l) { return l.username == notificationObj.username; }
|
||||
);
|
||||
if (loginsForSameUsername.length == 1) {
|
||||
// User already has a login saved for this site.
|
||||
if (loginsForSameUsername[0].password == notificationObj.password) {
|
||||
// We're just logging into a site with an existing login. Bail.
|
||||
return;
|
||||
}
|
||||
else {
|
||||
// Prompt user to update password
|
||||
notificationObj.type = 'update_password';
|
||||
// If the existing login stored for this site was PIN locked,
|
||||
// make sure this new one will be also.
|
||||
notificationObj.pinLocked = logins[0].pinLocked;
|
||||
}
|
||||
}
|
||||
// Has the user signed up for a Gombot account?
|
||||
checkIfDidFirstRun(function(didFirstRun) {
|
||||
if (didFirstRun) {
|
||||
// Prompt the user to save the login
|
||||
displayInfobar({
|
||||
notify: true,
|
||||
tabID: tabID,
|
||||
notification: notificationObj
|
||||
});
|
||||
}
|
||||
else {
|
||||
// Browser not associated with Gombot account, offer
|
||||
// to create one/log in.
|
||||
displayInfobar({
|
||||
notify: true,
|
||||
tabID: tabID,
|
||||
notification: {
|
||||
type: 'signup_nag'
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
'validate_pin': function(message,tabID,sendResponse) {
|
||||
sendResponse({
|
||||
'is_valid': validatePIN(message.pin)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -26,7 +26,8 @@ var User = function(Backbone, _, LoginCredentialCollection) {
|
|||
version: USER_DATA_VERSIONS[USER_DATA_VERSIONS.length-1],
|
||||
pin: null,
|
||||
logins: null,
|
||||
email: ""
|
||||
email: "",
|
||||
disabledSites: {}
|
||||
},
|
||||
|
||||
initialize: function() {
|
||||
|
|
|
@ -42,11 +42,12 @@ $(document).ready(function() {
|
|||
'email': email,
|
||||
'pin': pin
|
||||
});
|
||||
// Copy authKey/cryptKey to user object
|
||||
user.keys = client.keys;
|
||||
userCollection.add(user);
|
||||
user.save(null,{
|
||||
success: function() {
|
||||
// Copy authKey/cryptKey to user object
|
||||
user.keys = client.keys;
|
||||
Gombot.setCurrentUser(user);
|
||||
window.location = '/pages/first_run/success.html';
|
||||
}
|
||||
});
|
||||
|
|
|
@ -30,6 +30,7 @@ $(document).ready(function() {
|
|||
});
|
||||
if (user) {
|
||||
user.keys = client.keys;
|
||||
Gombot.setCurrentUser(user);
|
||||
window.location = 'success.html';
|
||||
}
|
||||
else {
|
||||
|
|
Загрузка…
Ссылка в новой задаче