diff options
| author | Guillaume Horel <guillaume.horel@gmail.com> | 2012-05-06 19:20:30 -0400 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@gmail.com> | 2012-05-06 19:20:30 -0400 |
| commit | 12bfb29d647c9750a0a773ed406f48e085099a01 (patch) | |
| tree | 7fa5e20696bcfecc7e832e801f2ff5b247d67a5c /alias-angular/app | |
| parent | 1d44809763e6c72d3d49a48f2b25ff0bdbaf92c7 (diff) | |
| download | alias-12bfb29d647c9750a0a773ed406f48e085099a01.tar.gz | |
tentative implementation of registration
Diffstat (limited to 'alias-angular/app')
| -rw-r--r-- | alias-angular/app/index.html | 2 | ||||
| -rw-r--r-- | alias-angular/app/js/controllers.js | 86 |
2 files changed, 79 insertions, 9 deletions
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 @@ <div class="btn-toolbar"> <div class="btn-group"> <a class="btn"> - <i class='{{self["status"]}} icon-user'></i> {{self["jid"]}} + <i class='{{alias["status"]}} icon-user'></i> {{["jid"]}} </a> <a class="btn dropdown-toggle" data-toggle="dropdown"> <span class="caret"></span> 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 = $('<value></value').text($("#form-pubkey").val()); + var privkey = $('<value></value').text($("#form-privkey").val()); + form.find('field[var="privkey"]').append(privkey); + form.find('field[var="pubkey"]').append(pubkey); + form.attr('type', 'submit'); + var reg = $iq({to: server_component, type:'set'}); + reg.c('query',{xmlns:'jabber:iq:register'}); + reg.cnode(form.get(0)); + StropheSrv.sendIQ(reg); + $("#register").modal("show"); + }; } ConnectCtl.$inject = ['$scope', 'StropheSrv', '$log', '$rootScope']; @@ -56,7 +125,7 @@ function RosterCtl($scope, StropheSrv, $log, $rootScope) { }); //make sure the roster is populated before sending presence request StropheSrv.send($pres()); - $rootScope.self["status"] = "chat"; + $rootScope.alias["status"] = "chat"; }; function onPresence(presence) { @@ -79,7 +148,7 @@ function RosterCtl($scope, StropheSrv, $log, $rootScope) { } } } - } + }; $scope.$on('connected', function() { StropheSrv.addHandler(onPresence, 'presence'); @@ -98,7 +167,7 @@ function RosterCtl($scope, StropheSrv, $log, $rootScope) { $scope.setStatus = function(status) { var pres = $pres().c("show", {}, status); StropheSrv.send(pres); - $rootScope.self["status"] = status; + $rootScope.alias["status"] = status; }; } @@ -154,8 +223,9 @@ function MsgCtl($scope, $log, StropheSrv, $rootScope) { $scope.sendMessage = function(message,to) { var msg = $msg({to: to, "type": "chat"}).c('body').t(message); - addMessage(to,$rootScope.self.jid,message); + addMessage(to,$rootScope.alias.jid, message); StropheSrv.send(msg); + msg=''; }; $scope.$on('connected', function() { |
