Anton Shestakov <av6@dwimlabs.net>, Sat, 19 Mar 2016 02:25:43 +0800
register: working registration and vCard saving
coffee/register.coffee
Permissions: -rw-r--r--
domain = location.hostname conn = new Strophe.Connection "https://#{ location.host }/http-bind" onConnect = (status, error) -> when Strophe.Status.CONNECTING console.debug('Strophe is connecting.') when Strophe.Status.AUTHENTICATING console.debug('Strophe is authenticating.') when Strophe.Status.AUTHFAIL console.debug('Strophe failed to authenticate:', error) when Strophe.Status.ERROR console.debug('Strophe received an error:', error) when Strophe.Status.CONNFAIL console.debug('Strophe failed to connect:', error) when Strophe.Status.DISCONNECTING console.debug('Strophe is disconnecting.') when Strophe.Status.DISCONNECTED console.debug('Strophe is disconnected.') when Strophe.Status.CONNECTED console.debug('Strophe is connected.') console.info('My jid:', conn.jid) when Strophe.Status.REGISTER console.debug('Got registration prompt') when Strophe.Status.REGISTERED console.debug('Registered!') when Strophe.Status.CONFLICT console.debug('Contact already exists!') when Strophe.Status.NOTACCEPTABLE console.debug('Registration form not properly filled out.') when Strophe.Status.REGIFAIL console.debug('The Server does not support In-Band Registration') $vcard = $iq({type: 'set'}).c('vCard', {xmlns: Strophe.NS.VCARD}) $vcard.c('NICKNAME').t(data.nickname).up() $vcard.c('FN').t(data.fullname).up() bi = data.avatar.indexOf(b) type = data.avatar.substr(dl, bi - dl) binval = data.avatar.substr(bi + bl) console.debug('vcard is set!', arguments) console.warn('vcard is NOT set!', arguments) conn.sendIQ $vcard.tree(), okcb, failcb window.R = _.clone Backbone.Events register: (username, password) -> conn.register.fields.username = username conn.register.fields.password = password conn.register.connect domain, onConnect $('#register').on 'click', -> validation.unsetError($('#username, #password1, #password2')) ok &= validation.validateRequired($('#username'), true) ok &= validation.validatePasswords($('#password1'), $('#password2')) ok &= validation.validateRequired($('#password1')) ok &= validation.validateRequired($('#password2')) R.register $('#username').val().trim(), $('#password1').val() $('#save').on 'click', -> file = $('#avatar').get(0).files[0] reader = new FileReader() fullname: $('#fullname').val() nickname: $('#nickname').val() reader.readAsDataURL(file) fullname: $('#fullname').val() nickname: $('#nickname').val() $('[data-step="registration"]').removeClass 'uk-hidden' $('[data-step="registration"]').addClass 'uk-hidden' $('[data-msg="r/closed"]').removeClass 'uk-hidden' validation.setError $('#username'), 'A user with this username already exists.' $('[data-msg="r/failed"]').removeClass 'uk-hidden' $('#nickname').val $('#username').val() $('[data-step="vcard"]').removeClass 'uk-hidden' $('[data-step="vcard"]').addClass 'uk-hidden' $('[data-msg="v/failed"]').removeClass 'uk-hidden'