diff --git a/nodejs/public/javascripts/safechat.js b/nodejs/public/javascripts/safechat.js index f8586dc..f1bde7a 100644 --- a/nodejs/public/javascripts/safechat.js +++ b/nodejs/public/javascripts/safechat.js @@ -46,7 +46,7 @@ function SafeChat() { /// @class Crypto cryptographic functions /** @param view is of class SafeChat.View */ - function Crypto(view) { + function Crypto(controller) { /// cache client's key from local strorage var k = null @@ -72,18 +72,18 @@ function SafeChat() { /// create New User function createuser(user, email, pwd) { - view.notice("generating keys") + controller.notice("generating keys") openpgp.generateKey({ numBits: 4096, userIds: [{name: user, email: email}], passphrase: pwd }).then(function(keyPair) { - view.success("keys generated") + controller.success("keys generated") localStorage.key = keyPair.privateKeyArmored k = keyPair.key }).catch(function(e) { console.log(e) - view.fatal("generating key pairs failed") + controller.fatal("generating key pairs failed") }) } @@ -409,8 +409,22 @@ function SafeChat() { function Controller(view) { var db = new Database() + var crypto = new Crypto(this) var communication = new Communication(this) var users = new Users() + + /// @name error handling + /// @{ + + this.fatal = view.fatal + this.error = view.error + this.warning = view.warning + this.notice = view.notice + + /// @} + + /// @name signals from server + /// @{ function fail(msg) { console.log('rcv-> fail('+msg+')') @@ -445,12 +459,7 @@ function SafeChat() { this.disconnect = view.disconnected this.error = view.disconnected - function login() { - } - - function user(usr) { - if (usr.exists) db.adduser - } + // @} function initBrowser() { window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB @@ -460,7 +469,17 @@ function SafeChat() { return window.indexedDB && window.crypto.getRandomValues && Storage } + function register() { + + } + + function login() { + if (!crypto.key()) register() + else password() + } + function run() { + login() } function start() {