mirror of
https://github.com/moparisthebest/mail
synced 2024-11-29 12:22:22 -05:00
login and logout work
This commit is contained in:
parent
71d6d6c799
commit
e26a8df294
@ -15,20 +15,14 @@
|
|||||||
initialize: function() {},
|
initialize: function() {},
|
||||||
|
|
||||||
login: function() {
|
login: function() {
|
||||||
// init email dao and dependencies
|
var loginView = new app.view.LoginView();
|
||||||
this.emailDao = null;
|
|
||||||
|
|
||||||
var loginView = new app.view.LoginView({
|
|
||||||
dao: this.emailDao
|
|
||||||
});
|
|
||||||
this.changePage(loginView);
|
this.changePage(loginView);
|
||||||
},
|
},
|
||||||
|
|
||||||
compose: function(userId, folder, messageId) {
|
compose: function(userId, folder, messageId) {
|
||||||
var composeView = new app.view.ComposeView({
|
var composeView = new app.view.ComposeView({
|
||||||
folder: folder,
|
folder: folder,
|
||||||
messageId: decodeURIComponent(messageId),
|
messageId: decodeURIComponent(messageId)
|
||||||
dao: this.emailDao
|
|
||||||
});
|
});
|
||||||
this.changePage(composeView);
|
this.changePage(composeView);
|
||||||
},
|
},
|
||||||
@ -44,8 +38,7 @@
|
|||||||
var self = this;
|
var self = this;
|
||||||
var messageListView = new app.view.MessageListView({
|
var messageListView = new app.view.MessageListView({
|
||||||
account: userId,
|
account: userId,
|
||||||
folder: folder,
|
folder: folder
|
||||||
dao: this.emailDao
|
|
||||||
});
|
});
|
||||||
self.changePage(messageListView);
|
self.changePage(messageListView);
|
||||||
messageListView.loadItems();
|
messageListView.loadItems();
|
||||||
@ -54,8 +47,7 @@
|
|||||||
read: function(userId, folder, messageId) {
|
read: function(userId, folder, messageId) {
|
||||||
var readView = new app.view.ReadView({
|
var readView = new app.view.ReadView({
|
||||||
folder: folder,
|
folder: folder,
|
||||||
messageId: decodeURIComponent(messageId),
|
messageId: decodeURIComponent(messageId)
|
||||||
dao: this.emailDao
|
|
||||||
});
|
});
|
||||||
this.changePage(readView);
|
this.changePage(readView);
|
||||||
readView.renderBody(true);
|
readView.renderBody(true);
|
||||||
|
@ -22,8 +22,10 @@
|
|||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
console.log('sandbox loaded');
|
console.log('sandbox loaded');
|
||||||
|
|
||||||
|
// set listener for event from main window
|
||||||
window.onmessage = function(e) {
|
window.onmessage = function(e) {
|
||||||
app.util.tpl.templates = e.data;
|
if (e.data.cmd === 'init') {
|
||||||
|
app.util.tpl.templates = e.data.args;
|
||||||
|
|
||||||
// remember references to main window
|
// remember references to main window
|
||||||
window.mainWindow = e.source;
|
window.mainWindow = e.source;
|
||||||
@ -31,6 +33,7 @@
|
|||||||
|
|
||||||
var router = new app.Router();
|
var router = new app.Router();
|
||||||
Backbone.history.start();
|
Backbone.history.start();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -3,12 +3,11 @@
|
|||||||
|
|
||||||
app.view.LoginView = Backbone.View.extend({
|
app.view.LoginView = Backbone.View.extend({
|
||||||
|
|
||||||
initialize: function(args) {
|
initialize: function() {
|
||||||
this.template = _.template(app.util.tpl.get('login'));
|
this.template = _.template(app.util.tpl.get('login'));
|
||||||
this.dao = args.dao;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function(eventName) {
|
render: function() {
|
||||||
var self = this,
|
var self = this,
|
||||||
page = $(this.el);
|
page = $(this.el);
|
||||||
|
|
||||||
@ -27,13 +26,6 @@
|
|||||||
userId = page.find('#userId').val(),
|
userId = page.find('#userId').val(),
|
||||||
password = page.find('#password').val();
|
password = page.find('#password').val();
|
||||||
|
|
||||||
var account = new app.model.Account({
|
|
||||||
emailAddress: userId,
|
|
||||||
symKeySize: app.config.symKeySize,
|
|
||||||
symIvSize: app.config.symIvSize,
|
|
||||||
asymKeySize: app.config.asymKeySize
|
|
||||||
});
|
|
||||||
|
|
||||||
// show loading msg during init
|
// show loading msg during init
|
||||||
$.mobile.loading('show', {
|
$.mobile.loading('show', {
|
||||||
text: 'Unlocking...',
|
text: 'Unlocking...',
|
||||||
@ -41,20 +33,29 @@
|
|||||||
theme: 'c'
|
theme: 'c'
|
||||||
});
|
});
|
||||||
|
|
||||||
window.location = '#accounts/test@example.com/folders';
|
// set listener for event from main window
|
||||||
|
window.onmessage = function(e) {
|
||||||
|
if (e.data.cmd === 'login') {
|
||||||
|
var err = e.data.args.err;
|
||||||
|
|
||||||
|
$.mobile.loading('hide');
|
||||||
|
if (err) {
|
||||||
|
window.alert(err.errMsg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
window.location = '#accounts/' + userId + '/folders';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// send message to main window
|
||||||
window.mainWindow.postMessage({
|
window.mainWindow.postMessage({
|
||||||
cmd: 'hello back from sandbox'
|
cmd: 'login',
|
||||||
|
args: {
|
||||||
|
userId: userId,
|
||||||
|
password: password
|
||||||
|
}
|
||||||
}, window.mainWindowOrigin);
|
}, window.mainWindowOrigin);
|
||||||
|
|
||||||
// this.dao.init(account, password, function(err) {
|
|
||||||
// $.mobile.loading('hide');
|
|
||||||
// if (err) {
|
|
||||||
// window.alert(err.errMsg);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// window.location = '#accounts/' + account.get('emailAddress') + '/folders';
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
(function() {
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var emailDao; // local variable for main DAO
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Template Loader. Used to asynchronously load templates located in separate .html files
|
* The Template Loader. Used to asynchronously load templates located in separate .html files
|
||||||
*/
|
*/
|
||||||
@ -62,16 +64,61 @@
|
|||||||
'messagelist',
|
'messagelist',
|
||||||
'messagelistitem',
|
'messagelistitem',
|
||||||
'read'
|
'read'
|
||||||
], function() {
|
], startApp);
|
||||||
// set listener for events from sandbox
|
|
||||||
window.onmessage = function(e) {
|
|
||||||
console.log(e.data);
|
|
||||||
};
|
|
||||||
// init sandbox ui
|
|
||||||
var sandbox = document.getElementById('sandboxFrame').contentWindow;
|
|
||||||
sandbox.postMessage(app.util.tpl.templates, '*');
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function startApp() {
|
||||||
|
// init email dao and dependencies
|
||||||
|
initDAO();
|
||||||
|
|
||||||
|
// sandboxed ui in iframe
|
||||||
|
var sandbox = document.getElementById('sandboxFrame').contentWindow;
|
||||||
|
|
||||||
|
// set listener for events from sandbox
|
||||||
|
window.onmessage = function(e) {
|
||||||
|
var cmd = e.data.cmd;
|
||||||
|
var args = e.data.args;
|
||||||
|
|
||||||
|
if (cmd === 'login') {
|
||||||
|
// login user
|
||||||
|
login(args.userId, args.password, function(err) {
|
||||||
|
sandbox.postMessage({
|
||||||
|
cmd: 'login',
|
||||||
|
args: {
|
||||||
|
err: err
|
||||||
|
}
|
||||||
|
}, '*');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// init sandbox ui
|
||||||
|
sandbox.postMessage({
|
||||||
|
cmd: 'init',
|
||||||
|
args: app.util.tpl.templates
|
||||||
|
}, '*');
|
||||||
|
}
|
||||||
|
|
||||||
|
function initDAO() {
|
||||||
|
var util = new cryptoLib.Util(window, uuid);
|
||||||
|
var crypto = new app.crypto.Crypto(window, util);
|
||||||
|
var cloudstorage = new app.dao.CloudStorage(window, $);
|
||||||
|
var jsonDao = new app.dao.LawnchairDAO(Lawnchair);
|
||||||
|
var devicestorage = new app.dao.DeviceStorage(util, crypto, jsonDao, null);
|
||||||
|
var keychain = new app.dao.KeychainDAO(jsonDao, cloudstorage);
|
||||||
|
emailDao = new app.dao.EmailDAO(jsonDao, crypto, devicestorage, cloudstorage, util, keychain);
|
||||||
|
}
|
||||||
|
|
||||||
|
function login(userId, password, callback) {
|
||||||
|
var account = new app.model.Account({
|
||||||
|
emailAddress: userId,
|
||||||
|
symKeySize: app.config.symKeySize,
|
||||||
|
symIvSize: app.config.symIvSize,
|
||||||
|
asymKeySize: app.config.asymKeySize
|
||||||
|
});
|
||||||
|
|
||||||
|
emailDao.init(account, password, callback);
|
||||||
|
}
|
||||||
|
|
||||||
}());
|
}());
|
@ -1,5 +1,5 @@
|
|||||||
<div data-role="header" data-position="fixed">
|
<div data-role="header" data-position="fixed">
|
||||||
<input type="button" id="backBtn" data-icon="arrow-l" value="Logout" class="ui-btn-left">
|
<a href="#" data-role="button" data-icon="arrow-l" data-iconpos="left" class="ui-btn-left">Logout</a>
|
||||||
<h1><%- account %></h1>
|
<h1><%- account %></h1>
|
||||||
</div><!-- /header -->
|
</div><!-- /header -->
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user