13:ba58d75904e4
Anton Shestakov <av6@dwimlabs.net>, Sat, 19 Mar 2016 10:46:01 +0800
provision: service checks

next change 14:8f8eddb3b264
previous change 11:082343e93ae6

js/register.js

Permissions: -rw-r--r--

Other formats: Feeds:
// Generated by CoffeeScript 1.10.0
(function() {
var conn, domain, onConnect, savevCard;
domain = location.hostname;
conn = new Strophe.Connection("https://" + location.host + "/http-bind");
onConnect = function(status, error) {
switch (status) {
case Strophe.Status.CONNECTING:
return console.debug('Strophe is connecting.');
case Strophe.Status.AUTHENTICATING:
return console.debug('Strophe is authenticating.');
case Strophe.Status.AUTHFAIL:
return console.debug('Strophe failed to authenticate:', error);
case Strophe.Status.ERROR:
return console.debug('Strophe received an error:', error);
case Strophe.Status.CONNFAIL:
return console.debug('Strophe failed to connect:', error);
case Strophe.Status.DISCONNECTING:
return console.debug('Strophe is disconnecting.');
case Strophe.Status.DISCONNECTED:
return console.debug('Strophe is disconnected.');
case Strophe.Status.CONNECTED:
console.debug('Strophe is connected.');
console.info('My jid:', conn.jid);
return R.trigger('v/start');
case Strophe.Status.REGISTER:
console.debug('Got registration prompt');
return R.trigger('r/start');
case Strophe.Status.REGISTERED:
console.debug('Registered!');
R.trigger('r/done');
return conn.authenticate();
case Strophe.Status.CONFLICT:
console.debug('Contact already exists!');
return R.trigger('r/conflict');
case Strophe.Status.NOTACCEPTABLE:
console.debug('Registration form not properly filled out.');
return R.trigger('r/failed');
case Strophe.Status.REGIFAIL:
console.debug('The Server does not support In-Band Registration');
return R.trigger('r/closed');
}
};
savevCard = function(data) {
var $vcard, b, bi, binval, bl, d, dl, failcb, okcb, type;
$vcard = $iq({
type: 'set'
}).c('vCard', {
xmlns: Strophe.NS.VCARD
});
if (data.nickname) {
$vcard.c('NICKNAME').t(data.nickname).up();
}
if (data.fullname) {
$vcard.c('FN').t(data.fullname).up();
}
if (data.avatar) {
b = ';base64,';
d = 'data:';
dl = d.length;
bl = b.length;
bi = data.avatar.indexOf(b);
type = data.avatar.substr(dl, bi - dl);
binval = data.avatar.substr(bi + bl);
$vcard.c('PHOTO').c('TYPE').t(type).up().c('BINVAL').t(binval);
}
okcb = function() {
console.debug('vcard is set!', arguments);
return R.trigger('v/done');
};
failcb = function() {
console.warn('vcard is NOT set!', arguments);
return R.trigger('v/failed');
};
return conn.sendIQ($vcard.tree(), okcb, failcb);
};
window.R = _.clone(Backbone.Events);
_(R).extend({
register: function(username, password) {
conn.register.fields.username = username;
conn.register.fields.password = password;
return conn.register.submit();
},
savevCard: savevCard
});
conn.register.connect(domain, onConnect);
$('#register').on('click', function() {
var ok;
ok = true;
validation.unsetError($('#username, #password1, #password2'));
ok &= validation.validateRequired($('#username'), true);
ok &= validation.validatePasswords($('#password1'), $('#password2'));
ok &= validation.validateRequired($('#password1'));
ok &= validation.validateRequired($('#password2'));
if (ok) {
return R.register($('#username').val().trim(), $('#password1').val());
}
});
$('#save').on('click', function() {
var file, reader;
file = $('#avatar').get(0).files[0];
if (file) {
reader = new FileReader();
reader.onloadend = function() {
return R.savevCard({
fullname: $('#fullname').val(),
nickname: $('#nickname').val(),
avatar: this.result
});
};
return reader.readAsDataURL(file);
} else {
return R.savevCard({
fullname: $('#fullname').val(),
nickname: $('#nickname').val()
});
}
});
R.on('r/start', function() {
return $('[data-step="registration"]').removeClass('uk-hidden');
});
R.on('r/done', function() {
return $('[data-step="registration"]').addClass('uk-hidden');
});
R.on('r/closed', function() {
return $('[data-msg="r/closed"]').removeClass('uk-hidden');
});
R.on('r/conflict', function() {
return validation.setError($('#username'), 'A user with this username already exists.');
});
R.on('r/failed', function() {
return $('[data-msg="r/failed"]').removeClass('uk-hidden');
});
R.on('v/start', function() {
$('#nickname').val($('#username').val());
return $('[data-step="vcard"]').removeClass('uk-hidden');
});
R.on('v/done', function() {
$('[data-step="vcard"]').addClass('uk-hidden');
return location.href = '/';
});
R.on('v/failed', function() {
return $('[data-msg="v/failed"]').removeClass('uk-hidden');
});
}).call(this);
//# sourceMappingURL=register.js.map