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() {},
|
||||
|
||||
login: function() {
|
||||
// init email dao and dependencies
|
||||
this.emailDao = null;
|
||||
|
||||
var loginView = new app.view.LoginView({
|
||||
dao: this.emailDao
|
||||
});
|
||||
var loginView = new app.view.LoginView();
|
||||
this.changePage(loginView);
|
||||
},
|
||||
|
||||
compose: function(userId, folder, messageId) {
|
||||
var composeView = new app.view.ComposeView({
|
||||
folder: folder,
|
||||
messageId: decodeURIComponent(messageId),
|
||||
dao: this.emailDao
|
||||
messageId: decodeURIComponent(messageId)
|
||||
});
|
||||
this.changePage(composeView);
|
||||
},
|
||||
@ -44,8 +38,7 @@
|
||||
var self = this;
|
||||
var messageListView = new app.view.MessageListView({
|
||||
account: userId,
|
||||
folder: folder,
|
||||
dao: this.emailDao
|
||||
folder: folder
|
||||
});
|
||||
self.changePage(messageListView);
|
||||
messageListView.loadItems();
|
||||
@ -54,8 +47,7 @@
|
||||
read: function(userId, folder, messageId) {
|
||||
var readView = new app.view.ReadView({
|
||||
folder: folder,
|
||||
messageId: decodeURIComponent(messageId),
|
||||
dao: this.emailDao
|
||||
messageId: decodeURIComponent(messageId)
|
||||
});
|
||||
this.changePage(readView);
|
||||
readView.renderBody(true);
|
||||
|
@ -22,8 +22,10 @@
|
||||
$(document).ready(function() {
|
||||
console.log('sandbox loaded');
|
||||
|
||||
// set listener for event from main window
|
||||
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
|
||||
window.mainWindow = e.source;
|
||||
@ -31,6 +33,7 @@
|
||||
|
||||
var router = new app.Router();
|
||||
Backbone.history.start();
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
|
@ -3,12 +3,11 @@
|
||||
|
||||
app.view.LoginView = Backbone.View.extend({
|
||||
|
||||
initialize: function(args) {
|
||||
initialize: function() {
|
||||
this.template = _.template(app.util.tpl.get('login'));
|
||||
this.dao = args.dao;
|
||||
},
|
||||
|
||||
render: function(eventName) {
|
||||
render: function() {
|
||||
var self = this,
|
||||
page = $(this.el);
|
||||
|
||||
@ -27,13 +26,6 @@
|
||||
userId = page.find('#userId').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
|
||||
$.mobile.loading('show', {
|
||||
text: 'Unlocking...',
|
||||
@ -41,20 +33,29 @@
|
||||
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({
|
||||
cmd: 'hello back from sandbox'
|
||||
cmd: 'login',
|
||||
args: {
|
||||
userId: userId,
|
||||
password: password
|
||||
}
|
||||
}, 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() {
|
||||
'use strict';
|
||||
|
||||
var emailDao; // local variable for main DAO
|
||||
|
||||
/**
|
||||
* The Template Loader. Used to asynchronously load templates located in separate .html files
|
||||
*/
|
||||
@ -62,16 +64,61 @@
|
||||
'messagelist',
|
||||
'messagelistitem',
|
||||
'read'
|
||||
], function() {
|
||||
// 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, '*');
|
||||
});
|
||||
], startApp);
|
||||
}
|
||||
});
|
||||
|
||||
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">
|
||||
<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>
|
||||
</div><!-- /header -->
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user