From 12bfb29d647c9750a0a773ed406f48e085099a01 Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Sun, 6 May 2012 19:20:30 -0400 Subject: tentative implementation of registration --- alias-angular/app/index.html | 2 +- alias-angular/app/js/controllers.js | 86 +++++++++++++++++++++++++++++++++---- 2 files changed, 79 insertions(+), 9 deletions(-) (limited to 'alias-angular') diff --git a/alias-angular/app/index.html b/alias-angular/app/index.html index 279018b..06f94e2 100644 --- a/alias-angular/app/index.html +++ b/alias-angular/app/index.html @@ -26,7 +26,7 @@
- {{self["jid"]}} + {{["jid"]}} diff --git a/alias-angular/app/js/controllers.js b/alias-angular/app/js/controllers.js index 979a4aa..732fcd3 100644 --- a/alias-angular/app/js/controllers.js +++ b/alias-angular/app/js/controllers.js @@ -2,12 +2,14 @@ /* App Controllers */ function ConnectCtl($scope, StropheSrv, $log, $rootScope) { - $rootScope.self = {jid: "", - status: 'offline' - }; + $rootScope.alias = {jid: "", + status: 'offline' + }; + $rootScope.is_connected = function () { return $rootScope.status == Strophe.Status.CONNECTED; }; + function connect_callback(status){ $rootScope.status = status; switch(status) { @@ -28,13 +30,80 @@ function ConnectCtl($scope, StropheSrv, $log, $rootScope) { $rootScope.$broadcast('connected', true); } }; + $scope.login = function () { StropheSrv.login($scope.username, $scope.password, connect_callback); - $rootScope.self["jid"] = $scope.username; + $rootScope.alias["jid"] = $scope.username; }; + $scope.disconnect = function() { StropheSrv.disconnect(); }; + + $scope.$on('connected', function() { + $scope.getRegister(); + }); + + $scope.getRegister = function() { + var init = $iq({to: server_component, type:'get'}); + init.c('query',{xmlns:'jabber:iq:register'}); + StropheSrv.sendIQ(init, onRegister); + }; + + function onRegister(iq) { + var form = $(iq).find('query x'); + if ($(iq).find('registered').length !== 0){ + // user is registered, get the info from the form + var pubkey = form.find('field[var="pubkey"] > value').text(); + var privkey = form.find('field[var="privkey"] > value').text(); + privkey = sjcl.decrypt($scope.password, privkey); + pubkey = JSON.parse(pubkey); + privkey = JSON.parse(privkey); + var rsa_key = new RSAKey(); + rsa_key.setPublic(pubkey.n, pubkey.e); + rsa_key.setPrivateEx(pubkey.n, pubkey.e, privkey.d, + privkey.p, privkey.q, privkey.dp, + privkey.dq, privkey.c); + $rootScope.alias.rsa_key = rsa_key; + }else{ + $scope.instructions = $(iq).find('instructions'); + $scope.form = form.xmppForm('render'); + $("#register").modal("show"); + } + }; + + function generate_key() { + var rsa_key = new RSAKey(); + rsa_key.generate(1024, "10001"); + var pubkey = { + n: rsa_key.n.toString(16), + e: rsa_key.e.toString(16) + }; + var privkey = { + d: rsa_key.d.toString(16), + p: rsa_key.p.toString(16), + q: rsa_key.q.toString(16), + dp: rsa_key.dmp1.toString(16), + dq: rsa_key.dmq1.toString(16), + c: rsa_key.coeff.toString(16) + }; + privkey = sjcl.encrypt($scope.password, JSON.stringify(privkey)); + $("#form-pubkey").val(JSON.stringify(pubkey)); + $("#form-privkey").val(privkey); + }; + + function send_registration() { + var pubkey = $('