mirror of
https://github.com/moparisthebest/kaiwa
synced 2024-11-15 22:05:09 -05:00
Add very basic login page
This commit is contained in:
parent
3ec2805cd9
commit
5c6655e7be
@ -31,24 +31,16 @@ module.exports = {
|
|||||||
new Router();
|
new Router();
|
||||||
app.history = Backbone.history;
|
app.history = Backbone.history;
|
||||||
|
|
||||||
if (!localStorage.config) {
|
|
||||||
return app.navigate('signin');
|
|
||||||
}
|
|
||||||
|
|
||||||
app.view = new MainView({
|
app.view = new MainView({
|
||||||
model: me,
|
model: me,
|
||||||
el: document.body
|
el: document.body
|
||||||
});
|
});
|
||||||
app.view.render();
|
app.view.render();
|
||||||
|
|
||||||
var rosterVer = localStorage.rosterVersion;
|
var client = window.client = app.client = XMPP.createClient({
|
||||||
var config = JSON.parse(localStorage.config);
|
rosterVer: localStorage.rosterVersion || undefined
|
||||||
|
});
|
||||||
config.rosterVer = rosterVer;
|
|
||||||
|
|
||||||
var client = window.client = app.client = XMPP.createClient(config);
|
|
||||||
xmppEventHandlers(client, app);
|
xmppEventHandlers(client, app);
|
||||||
client.connect();
|
|
||||||
|
|
||||||
// we have what we need, we can now start our router and show the appropriate page
|
// we have what we need, we can now start our router and show the appropriate page
|
||||||
app.history.start({pushState: true, root: '/'});
|
app.history.start({pushState: true, root: '/'});
|
||||||
|
@ -4,50 +4,16 @@
|
|||||||
var crypto = XMPP.crypto;
|
var crypto = XMPP.crypto;
|
||||||
|
|
||||||
var _ = require('underscore');
|
var _ = require('underscore');
|
||||||
|
var log = require('andlog');
|
||||||
var Contact = require('../models/contact');
|
var Contact = require('../models/contact');
|
||||||
var Resource = require('../models/resource');
|
var Resource = require('../models/resource');
|
||||||
var Message = require('../models/message');
|
var Message = require('../models/message');
|
||||||
|
|
||||||
|
|
||||||
function logScroll() {
|
|
||||||
window.scrollTo(0, document.body.scrollHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
function log(name, data) {
|
|
||||||
var container = document.getElementById('log');
|
|
||||||
var logEntry = document.createElement('div'),
|
|
||||||
header = document.createElement('h2'),
|
|
||||||
entry = document.createElement('p'),
|
|
||||||
altEntry = document.createElement('p');
|
|
||||||
|
|
||||||
header.textContent = name;
|
|
||||||
logEntry.appendChild(header);
|
|
||||||
|
|
||||||
if (data && data.toJSON) {
|
|
||||||
var codeJSON = document.createElement('code');
|
|
||||||
codeJSON.textContent = JSON.stringify(data.toJSON());
|
|
||||||
|
|
||||||
altEntry.appendChild(codeJSON);
|
|
||||||
logEntry.appendChild(altEntry);
|
|
||||||
logEntry.appendChild(document.createElement('hr'));
|
|
||||||
}
|
|
||||||
|
|
||||||
var codeData = document.createElement('code');
|
|
||||||
codeData.textContent = data;
|
|
||||||
entry.appendChild(codeData);
|
|
||||||
logEntry.appendChild(entry);
|
|
||||||
|
|
||||||
if (container) {
|
|
||||||
container.appendChild(logEntry);
|
|
||||||
_.throttle(logScroll, 300);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = function (client, app) {
|
module.exports = function (client, app) {
|
||||||
|
|
||||||
client.on('*', function (name, data) {
|
client.on('*', function (name, data) {
|
||||||
log(name, data);
|
log.debug(name, data);
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on('session:started', function (jid) {
|
client.on('session:started', function (jid) {
|
||||||
@ -157,13 +123,14 @@ module.exports = function (client, app) {
|
|||||||
message.cid = msg.id;
|
message.cid = msg.id;
|
||||||
message.set(msg);
|
message.set(msg);
|
||||||
|
|
||||||
if (msg.archived) {
|
//if (msg.archived) {
|
||||||
msg.archived.forEach(function (archived) {
|
// msg.archived.forEach(function (archived) {
|
||||||
if (me.isMe(archived.by)) {
|
// if (me.isMe(archived.by)) {
|
||||||
message.id = archived.id;
|
// message.id = archived.id;
|
||||||
}
|
// message.cid = msg.id;
|
||||||
});
|
// }
|
||||||
}
|
// });
|
||||||
|
//}
|
||||||
|
|
||||||
contact.messages.add(message);
|
contact.messages.add(message);
|
||||||
if (!contact.lockedResource) {
|
if (!contact.lockedResource) {
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -18,6 +18,7 @@ module.exports = StrictModel.extend({
|
|||||||
this.setAvatar(attrs.avatarID);
|
this.setAvatar(attrs.avatarID);
|
||||||
|
|
||||||
this.resources.bind('add remove reset change', this.resourceChange, this);
|
this.resources.bind('add remove reset change', this.resourceChange, this);
|
||||||
|
this.bind('change:lockedResource', this.fetchTimezone, this);
|
||||||
},
|
},
|
||||||
type: 'contact',
|
type: 'contact',
|
||||||
props: {
|
props: {
|
||||||
@ -46,13 +47,20 @@ module.exports = StrictModel.extend({
|
|||||||
return this.offlineStatus;
|
return this.offlineStatus;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
lockedJID: {
|
formattedTZO: {
|
||||||
deps: ['jid', 'lockedResource'],
|
deps: ['timezoneOffset', 'displayName'],
|
||||||
fn: function () {
|
fn: function () {
|
||||||
if (this.lockedResource) {
|
if (this.timezoneOffset !== undefined) {
|
||||||
return this.jid + '/' + this.lockedResource;
|
var localTZO = (new Date()).getTimezoneOffset();
|
||||||
|
var diff = Math.abs(localTZO - this.timezoneOffset) / 60;
|
||||||
|
if (diff === 0) {
|
||||||
|
return this.displayName + ' is in the same timezone as you';
|
||||||
|
}
|
||||||
|
var dir = (localTZO > this.timezoneOffset) ? 'ahead' : 'behind';
|
||||||
|
return this.displayName + ' is ' + diff + 'hrs ' + dir + ' you';
|
||||||
|
} else {
|
||||||
|
return '';
|
||||||
}
|
}
|
||||||
return this.jid;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -64,7 +72,8 @@ module.exports = StrictModel.extend({
|
|||||||
show: ['string', true, 'offline'],
|
show: ['string', true, 'offline'],
|
||||||
chatState: ['string', true, 'gone'],
|
chatState: ['string', true, 'gone'],
|
||||||
lockedResource: 'string',
|
lockedResource: 'string',
|
||||||
lastSentMessage: 'object'
|
lastSentMessage: 'object',
|
||||||
|
timezoneOffset: ['number', false, 0]
|
||||||
},
|
},
|
||||||
collections: {
|
collections: {
|
||||||
resources: Resources,
|
resources: Resources,
|
||||||
@ -127,9 +136,23 @@ module.exports = StrictModel.extend({
|
|||||||
this.show = 'offline';
|
this.show = 'offline';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
fetchTimezone: function () {
|
||||||
|
var self = this;
|
||||||
|
app.whenConnected(function () {
|
||||||
|
if (self.lockedResource) {
|
||||||
|
client.getTime(self.lockedResource, function (err, res) {
|
||||||
|
if (err) return;
|
||||||
|
console.log('RECV' + res.time.tzo);
|
||||||
|
console.log('RECV UTC' + res.time.utc);
|
||||||
|
self.timezoneOffset = res.time.tzo;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
self.timezoneOffset = undefined;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
fetchHistory: function () {
|
fetchHistory: function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
app.whenConnected(function () {
|
app.whenConnected(function () {
|
||||||
client.getHistory({
|
client.getHistory({
|
||||||
with: self.jid,
|
with: self.jid,
|
||||||
|
@ -12,6 +12,7 @@ module.exports = BasePage.extend({
|
|||||||
template: templates.pages.chat,
|
template: templates.pages.chat,
|
||||||
initialize: function (spec) {
|
initialize: function (spec) {
|
||||||
this.editMode = false;
|
this.editMode = false;
|
||||||
|
this.model.fetchTimezone();
|
||||||
this.model.fetchHistory();
|
this.model.fetchHistory();
|
||||||
this.render();
|
this.render();
|
||||||
},
|
},
|
||||||
@ -23,7 +24,8 @@ module.exports = BasePage.extend({
|
|||||||
avatar: 'header .avatar'
|
avatar: 'header .avatar'
|
||||||
},
|
},
|
||||||
textBindings: {
|
textBindings: {
|
||||||
name: 'header .name'
|
displayName: 'header .name',
|
||||||
|
formattedTZO: 'header #tzo'
|
||||||
},
|
},
|
||||||
render: function () {
|
render: function () {
|
||||||
this.renderAndBind();
|
this.renderAndBind();
|
||||||
@ -60,7 +62,7 @@ module.exports = BasePage.extend({
|
|||||||
|
|
||||||
if (val) {
|
if (val) {
|
||||||
message = {
|
message = {
|
||||||
to: this.model.lockedJID,
|
to: this.model.lockedResource || this.model.jid,
|
||||||
type: 'chat',
|
type: 'chat',
|
||||||
body: val,
|
body: val,
|
||||||
chatState: 'active'
|
chatState: 'active'
|
||||||
|
@ -3,16 +3,11 @@
|
|||||||
|
|
||||||
var BasePage = require('./base');
|
var BasePage = require('./base');
|
||||||
var templates = require('../templates');
|
var templates = require('../templates');
|
||||||
var ContactListItem = require('../views/contactListItem');
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = BasePage.extend({
|
module.exports = BasePage.extend({
|
||||||
template: templates.pages.main,
|
template: templates.pages.main,
|
||||||
initialize: function (spec) {
|
initialize: function (spec) {
|
||||||
this.render();
|
|
||||||
},
|
|
||||||
render: function () {
|
|
||||||
this.renderAndBind();
|
this.renderAndBind();
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
44
clientapp/pages/signin.js
Normal file
44
clientapp/pages/signin.js
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/*global app, client*/
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var BasePage = require('./base');
|
||||||
|
var templates = require('../templates');
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = BasePage.extend({
|
||||||
|
template: templates.pages.signin,
|
||||||
|
events: {
|
||||||
|
'submit #loginForm form': 'login'
|
||||||
|
},
|
||||||
|
initialize: function (spec) {
|
||||||
|
this.renderAndBind();
|
||||||
|
},
|
||||||
|
login: function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
var jid = this.$('#jid').val();
|
||||||
|
var password = this.$('#password').val();
|
||||||
|
var wsURL = this.$('#wsURL').val();
|
||||||
|
|
||||||
|
client.connect({
|
||||||
|
jid: jid,
|
||||||
|
server: jid.slice(jid.indexOf('@') + 1),
|
||||||
|
wsURL: wsURL,
|
||||||
|
credentials: {
|
||||||
|
password: password
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
client.once('auth:success', 'signin', function () {
|
||||||
|
client.releaseGroup('signin');
|
||||||
|
app.navigate('/');
|
||||||
|
});
|
||||||
|
|
||||||
|
client.once('auth:failed', 'signin', function () {
|
||||||
|
client.releaseGroup('signin');
|
||||||
|
console.log('Failed Auth');
|
||||||
|
});
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
@ -2,16 +2,23 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var Backbone = require('backbone');
|
var Backbone = require('backbone');
|
||||||
|
var SigninPage = require('./pages/signin');
|
||||||
var MainPage = require('./pages/main');
|
var MainPage = require('./pages/main');
|
||||||
var ChatPage = require('./pages/chat');
|
var ChatPage = require('./pages/chat');
|
||||||
|
|
||||||
|
|
||||||
module.exports = Backbone.Router.extend({
|
module.exports = Backbone.Router.extend({
|
||||||
routes: {
|
routes: {
|
||||||
'': 'main',
|
'': 'signin',
|
||||||
|
'signin': 'signin',
|
||||||
'chat/:jid': 'chat'
|
'chat/:jid': 'chat'
|
||||||
},
|
},
|
||||||
// ------- ROUTE HANDLERS ---------
|
// ------- ROUTE HANDLERS ---------
|
||||||
|
signin: function () {
|
||||||
|
app.renderPage(new SigninPage({
|
||||||
|
model: me
|
||||||
|
}));
|
||||||
|
},
|
||||||
main: function () {
|
main: function () {
|
||||||
app.renderPage(new MainPage({
|
app.renderPage(new MainPage({
|
||||||
model: me
|
model: me
|
||||||
|
@ -62,7 +62,7 @@ exports.includes.message = function anonymous(locals) {
|
|||||||
exports.pages.chat = function anonymous(locals) {
|
exports.pages.chat = function anonymous(locals) {
|
||||||
var buf = [];
|
var buf = [];
|
||||||
with (locals || {}) {
|
with (locals || {}) {
|
||||||
buf.push('<section class="page chat"><header class="contactInfo"><img width="30" height="30" class="avatar"/><h1 class="name"></h1></header><ul id="conversation"></ul><div id="chatInput"><form><textarea id="chatBuffer" name="chatInput" type="text" placeholder="Send a message..." autocomplete="off"></textarea></form></div></section>');
|
buf.push('<section class="page chat"><header class="contactInfo"><img width="30" height="30" class="avatar"/><h1 class="name"></h1><div id="tzo"></div></header><ul id="conversation"></ul><div id="chatInput"><form><textarea id="chatBuffer" name="chatInput" type="text" placeholder="Send a message..." autocomplete="off"></textarea></form></div></section>');
|
||||||
}
|
}
|
||||||
return buf.join("");
|
return buf.join("");
|
||||||
};
|
};
|
||||||
@ -71,7 +71,16 @@ exports.pages.chat = function anonymous(locals) {
|
|||||||
exports.pages.main = function anonymous(locals) {
|
exports.pages.main = function anonymous(locals) {
|
||||||
var buf = [];
|
var buf = [];
|
||||||
with (locals || {}) {
|
with (locals || {}) {
|
||||||
buf.push('<section class="page main"><div id="log"><h2>Event Log</h2></div></section>');
|
buf.push('<section class="page main"></section>');
|
||||||
|
}
|
||||||
|
return buf.join("");
|
||||||
|
};
|
||||||
|
|
||||||
|
// signin.jade compiled template
|
||||||
|
exports.pages.signin = function anonymous(locals) {
|
||||||
|
var buf = [];
|
||||||
|
with (locals || {}) {
|
||||||
|
buf.push('<section class="page signin"><div id="loginForm"><form><label>JID:<input type="text" id="jid" placeholder="you@aweso.me"/></label><label>Password:<input type="password" id="password"/></label><label>WebSocket URL:<input type="text" id="wsURL" placeholder="wss://aweso.me:5281/xmpp-websocket"/></label><input type="submit" value="Connect"/></form></div></section>');
|
||||||
}
|
}
|
||||||
return buf.join("");
|
return buf.join("");
|
||||||
};
|
};
|
||||||
|
@ -2,6 +2,7 @@ section.page.chat
|
|||||||
header.contactInfo
|
header.contactInfo
|
||||||
img.avatar(width=30, height=30)
|
img.avatar(width=30, height=30)
|
||||||
h1.name
|
h1.name
|
||||||
|
#tzo
|
||||||
ul#conversation
|
ul#conversation
|
||||||
div#chatInput
|
div#chatInput
|
||||||
form
|
form
|
||||||
|
@ -1,3 +1 @@
|
|||||||
section.page.main
|
section.page.main
|
||||||
#log
|
|
||||||
h2 Event Log
|
|
||||||
|
10
clientapp/templates/pages/signin.jade
Normal file
10
clientapp/templates/pages/signin.jade
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
section.page.signin
|
||||||
|
div#loginForm
|
||||||
|
form
|
||||||
|
label JID:
|
||||||
|
input(type="text", id="jid", placeholder="you@aweso.me")
|
||||||
|
label Password:
|
||||||
|
input(type="password", id="password")
|
||||||
|
label WebSocket URL:
|
||||||
|
input(type="text", id="wsURL", placeholder="wss://aweso.me:5281/xmpp-websocket")
|
||||||
|
input(type="submit", value="Connect")
|
@ -8,10 +8,26 @@ var ContactListItem = require('../views/contactListItem');
|
|||||||
|
|
||||||
module.exports = StrictView.extend({
|
module.exports = StrictView.extend({
|
||||||
template: templates.body,
|
template: templates.body,
|
||||||
|
events: {
|
||||||
|
'click a[href]': 'handleLinkClick'
|
||||||
|
},
|
||||||
render: function () {
|
render: function () {
|
||||||
$('head').append(templates.head());
|
$('head').append(templates.head());
|
||||||
this.renderAndBind();
|
this.renderAndBind();
|
||||||
this.renderCollection(me.contacts, ContactListItem, this.$('#contactList'));
|
this.renderCollection(me.contacts, ContactListItem, this.$('#contactList'));
|
||||||
return this;
|
return this;
|
||||||
|
},
|
||||||
|
handleLinkClick: function (e) {
|
||||||
|
console.log(e);
|
||||||
|
var t = $(e.target);
|
||||||
|
var aEl = t.is('a') ? t[0] : t.closest('a')[0];
|
||||||
|
var local = window.location.host === aEl.host;
|
||||||
|
var path = aEl.pathname.slice(1);
|
||||||
|
|
||||||
|
if (local) {
|
||||||
|
e.preventDefault();
|
||||||
|
app.navigate(path);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
"semi-static": "0.0.4",
|
"semi-static": "0.0.4",
|
||||||
"sound-effect-manager": "0.0.5",
|
"sound-effect-manager": "0.0.5",
|
||||||
"strictmodel": "0.1.1",
|
"strictmodel": "0.1.1",
|
||||||
"strictview": "1.0.0",
|
"strictview": "1.0.2",
|
||||||
"templatizer": "0.1.2",
|
"templatizer": "0.1.2",
|
||||||
"underscore": "1.5.1"
|
"underscore": "1.5.1"
|
||||||
},
|
},
|
||||||
|
@ -264,3 +264,10 @@ html, body {
|
|||||||
#chatBuffer.editing {
|
#chatBuffer.editing {
|
||||||
background-color: yellow;
|
background-color: yellow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#loginForm {
|
||||||
|
margin: 50px;
|
||||||
|
}
|
||||||
|
#loginForm label {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user