Download:
child 12:f2a6139f2b42
parent 10:2e916f200943
11:082343e93ae6
Anton Shestakov <av6@dwimlabs.net>, Sat, 19 Mar 2016 02:25:43 +0800
register: working registration and vCard saving

7 файлов изменено, 469 вставок(+), 1 удалений(-) [+]
coffee/register.coffee file | annotate | diff | comparison | revisions
coffee/ui/validation.coffee file | annotate | diff | comparison | revisions
js/register.js file | annotate | diff | comparison | revisions
js/register.js.map file | annotate | diff | comparison | revisions
js/ui/validation.js file | annotate | diff | comparison | revisions
js/ui/validation.js.map file | annotate | diff | comparison | revisions
register.html file | annotate | diff | comparison | revisions
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/coffee/register.coffee Sat Mar 19 02:25:43 2016 +0800
@@ -0,0 +1,160 @@
+domain = location.hostname
+conn = new Strophe.Connection "https://#{ location.host }/http-bind"
+
+
+onConnect = (status, error) ->
+ switch status
+ 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)
+ R.trigger 'v/start'
+
+ when Strophe.Status.REGISTER
+ console.debug('Got registration prompt')
+ R.trigger 'r/start'
+
+ when Strophe.Status.REGISTERED
+ console.debug('Registered!')
+ R.trigger 'r/done'
+ conn.authenticate()
+
+ when Strophe.Status.CONFLICT
+ console.debug('Contact already exists!')
+ R.trigger 'r/conflict'
+
+ when Strophe.Status.NOTACCEPTABLE
+ console.debug('Registration form not properly filled out.')
+ R.trigger 'r/failed'
+
+ when Strophe.Status.REGIFAIL
+ console.debug('The Server does not support In-Band Registration')
+ R.trigger 'r/closed'
+
+
+savevCard = (data) ->
+ $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 = ->
+ console.debug('vcard is set!', arguments)
+ R.trigger 'v/done'
+
+ failcb = ->
+ console.warn('vcard is NOT set!', arguments)
+ R.trigger 'v/failed'
+
+ conn.sendIQ $vcard.tree(), okcb, failcb
+
+
+window.R = _.clone Backbone.Events
+
+
+_(R).extend
+ register: (username, password) ->
+ conn.register.fields.username = username
+ conn.register.fields.password = password
+ conn.register.submit()
+ savevCard: savevCard
+
+
+conn.register.connect domain, onConnect
+
+
+$('#register').on 'click', ->
+ 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
+ R.register $('#username').val().trim(), $('#password1').val()
+
+
+$('#save').on 'click', ->
+ file = $('#avatar').get(0).files[0]
+ if file
+ reader = new FileReader()
+ reader.onloadend = ->
+ R.savevCard
+ fullname: $('#fullname').val()
+ nickname: $('#nickname').val()
+ avatar: @result
+ reader.readAsDataURL(file)
+ else
+ R.savevCard
+ fullname: $('#fullname').val()
+ nickname: $('#nickname').val()
+
+
+R.on 'r/start', ->
+ $('[data-step="registration"]').removeClass 'uk-hidden'
+
+
+R.on 'r/done', ->
+ $('[data-step="registration"]').addClass 'uk-hidden'
+
+
+R.on 'r/closed', ->
+ $('[data-msg="r/closed"]').removeClass 'uk-hidden'
+
+
+R.on 'r/conflict', ->
+ validation.setError $('#username'), 'A user with this username already exists.'
+
+
+R.on 'r/failed', ->
+ $('[data-msg="r/failed"]').removeClass 'uk-hidden'
+
+
+R.on 'v/start', ->
+ $('#nickname').val $('#username').val()
+ $('[data-step="vcard"]').removeClass 'uk-hidden'
+
+
+R.on 'v/done', ->
+ $('[data-step="vcard"]').addClass 'uk-hidden'
+ location.href = '/'
+
+
+R.on 'v/failed', ->
+ $('[data-msg="v/failed"]').removeClass 'uk-hidden'
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/coffee/ui/validation.coffee Sat Mar 19 02:25:43 2016 +0800
@@ -0,0 +1,30 @@
+class Validation
+ setError: ($field, message) ->
+ $el = $('<div class="uk-text-danger"></div>').text(message)
+ $field.addClass('uk-form-danger')
+ $field.after($el)
+
+ unsetError: ($field) ->
+ $field.removeClass('uk-form-danger').siblings('.uk-text-danger').remove()
+
+ validateRequired: (field, trim) ->
+ $field = $(field)
+ val = $field.val()
+ val = val.trim() if trim
+ if val is ''
+ @setError $field, 'This field is required.'
+ return false
+ else
+ return true
+
+ validatePasswords: (field1, field2) ->
+ $field1 = $(field1)
+ $field2 = $(field2)
+ if $field1.val() isnt $field2.val()
+ @setError $field2, 'Passwords must match.'
+ return false
+ else
+ return true
+
+
+window.validation = new Validation()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/js/register.js Sat Mar 19 02:25:43 2016 +0800
@@ -0,0 +1,165 @@
+// 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
--- /dev/null Thu Jan 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00:00 1970 +0000
+++ b/js/ui/validation.js Sat Mar 19 02:25:43 2016 +0800
@@ -0,0 +1,54 @@
+// Generated by CoffeeScript 1.10.0
+(function() {
+ var Validation;
+
+ Validation = (function() {
+ function Validation() {}
+
+ Validation.prototype.setError = function($field, message) {
+ var $el;
+ $el = $('<div class="uk-text-danger"></div>').text(message);
+ $field.addClass('uk-form-danger');
+ return $field.after($el);
+ };
+
+ Validation.prototype.unsetError = function($field) {
+ return $field.removeClass('uk-form-danger').siblings('.uk-text-danger').remove();
+ };
+
+ Validation.prototype.validateRequired = function(field, trim) {
+ var $field, val;
+ $field = $(field);
+ val = $field.val();
+ if (trim) {
+ val = val.trim();
+ }
+ if (val === '') {
+ this.setError($field, 'This field is required.');
+ return false;
+ } else {
+ return true;
+ }
+ };
+
+ Validation.prototype.validatePasswords = function(field1, field2) {
+ var $field1, $field2;
+ $field1 = $(field1);
+ $field2 = $(field2);
+ if ($field1.val() !== $field2.val()) {
+ this.setError($field2, 'Passwords must match.');
+ return false;
+ } else {
+ return true;
+ }
+ };
+
+ return Validation;
+
+ })();
+
+ window.validation = new Validation();
+
+}).call(this);
+
+//# sourceMappingURL=validation.js.map
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/js/ui/validation.js.map Sat Mar 19 02:25:43 2016 +0800
@@ -0,0 +1,10 @@
+{
+ "version": 3,
+ "file": "validation.js",
+ "sourceRoot": "../..",
+ "sources": [
+ "coffee/ui/validation.coffee"
+ ],
+ "names": [],
+ "mappings": ";AAAA;AAAA,MAAA;;EAAM;;;yBACJ,QAAA,GAAU,SAAC,MAAD,EAAS,OAAT;AACR,UAAA;MAAA,GAAA,GAAM,CAAA,CAAE,oCAAF,CAAuC,CAAC,IAAxC,CAA6C,OAA7C;MACN,MAAM,CAAC,QAAP,CAAgB,gBAAhB;aACA,MAAM,CAAC,KAAP,CAAa,GAAb;IAHQ;;yBAKV,UAAA,GAAY,SAAC,MAAD;aACV,MAAM,CAAC,WAAP,CAAmB,gBAAnB,CAAoC,CAAC,QAArC,CAA8C,iBAA9C,CAAgE,CAAC,MAAjE,CAAA;IADU;;yBAGZ,gBAAA,GAAkB,SAAC,KAAD,EAAQ,IAAR;AAChB,UAAA;MAAA,MAAA,GAAS,CAAA,CAAE,KAAF;MACT,GAAA,GAAM,MAAM,CAAC,GAAP,CAAA;MACN,IAAoB,IAApB;QAAA,GAAA,GAAM,GAAG,CAAC,IAAJ,CAAA,EAAN;;MACA,IAAG,GAAA,KAAO,EAAV;QACE,IAAC,CAAA,QAAD,CAAU,MAAV,EAAkB,yBAAlB;AACA,eAAO,MAFT;OAAA,MAAA;AAIE,eAAO,KAJT;;IAJgB;;yBAUlB,iBAAA,GAAmB,SAAC,MAAD,EAAS,MAAT;AACjB,UAAA;MAAA,OAAA,GAAU,CAAA,CAAE,MAAF;MACV,OAAA,GAAU,CAAA,CAAE,MAAF;MACV,IAAG,OAAO,CAAC,GAAR,CAAA,CAAA,KAAmB,OAAO,CAAC,GAAR,CAAA,CAAtB;QACE,IAAC,CAAA,QAAD,CAAU,OAAV,EAAmB,uBAAnB;AACA,eAAO,MAFT;OAAA,MAAA;AAIE,eAAO,KAJT;;IAHiB;;;;;;EAUrB,MAAM,CAAC,UAAP,GAAwB,IAAA,UAAA,CAAA;AA7BxB"
+}
\ No newline at end of file
--- a/register.html Sat Mar 19 01:59:07 2016 +0800
+++ b/register.html Sat Mar 19 02:25:43 2016 +0800
@@ -8,7 +8,12 @@
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/uikit/2.25.0/css/uikit.min.css">
<link rel="stylesheet" href="/css/tram-im.css">
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.2.3/backbone-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/uikit/2.25.0/js/uikit.min.js"></script>
+ <script src="/vendor/strophejs/strophe.min.js"></script>
+ <script src="/vendor/strophejs-plugins/register/strophe.register.js"></script>
+ <script src="/vendor/strophejs-plugins/vcard/strophe.vcard.js"></script>
</head>
<body>
<div class="smart-container">
@@ -21,7 +26,9 @@
$('[data-step="noscript"]').addClass('uk-hidden');
</script>
- <div class="uk-form uk-form-horizontal" data-step="registration">
+ <div class="uk-alert uk-alert-danger uk-hidden" data-msg="r/closed">Registration is closed at the moment.</div>
+
+ <div class="uk-form uk-form-horizontal uk-hidden" data-step="registration">
<div class="uk-form-row">
<label for="username" class="uk-form-label">Username</label>
<div class="uk-form-controls">
@@ -42,11 +49,43 @@
</div>
<div class="uk-form-row">
<div class="uk-form-controls">
+ <div class="uk-alert uk-alert-danger uk-hidden" data-msg="r/failed">Unspecified error, sorry.</div>
<button id="register" type="button" class="uk-button uk-button-primary">Register</button>
<a class="uk-float-right uk-button uk-button-link" href="/">Log in</a>
</div>
</div>
</div>
+
+ <div class="uk-form uk-form-horizontal uk-hidden" data-step="vcard">
+ <div class="uk-form-row">
+ <label for="fullname" class="uk-form-label">Full Name</label>
+ <div class="uk-form-controls">
+ <input id="fullname" class="uk-width-1-1" type="text" value="">
+ </div>
+ </div>
+ <div class="uk-form-row">
+ <label for="nickname" class="uk-form-label">Nickname</label>
+ <div class="uk-form-controls">
+ <input id="nickname" class="uk-width-1-1" type="text" value="">
+ </div>
+ </div>
+ <div class="uk-form-row">
+ <label for="avatar" class="uk-form-label">Avatar</label>
+ <div class="uk-form-controls">
+ <input id="avatar" type="file" accept="image/*" value="">
+ </div>
+ </div>
+ <div class="uk-form-row">
+ <div class="uk-form-controls">
+ <button id="save" class="uk-button uk-button-primary">Save</button>
+ </div>
+ </div>
+ </div>
+
+ <div class="uk-alert uk-alert-danger uk-hidden" data-msg="v/failed">Couldn't save the vCard.</div>
</div>
+
+ <script src='/js/ui/validation.js'></script>
+ <script src='/js/register.js'></script>
</body>
</html>