aboutsummaryrefslogtreecommitdiffstats
path: root/alias-angular/app/js
diff options
context:
space:
mode:
Diffstat (limited to 'alias-angular/app/js')
-rw-r--r--alias-angular/app/js/controllers.js86
1 files changed, 78 insertions, 8 deletions
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() {