mirror of
https://github.com/moparisthebest/kaiwa
synced 2024-12-23 16:18:48 -05:00
Add apps oauth login, handle connection errors
This commit is contained in:
parent
baf25a6bc8
commit
53950d9320
@ -50,6 +50,7 @@ module.exports = {
|
||||
self.api.connect();
|
||||
|
||||
self.api.once('session:started', function () {
|
||||
app.hasConnected = true;
|
||||
cb();
|
||||
});
|
||||
},
|
||||
|
@ -80,6 +80,9 @@ module.exports = function (client, app) {
|
||||
|
||||
client.on('disconnected', function () {
|
||||
me.connected = false;
|
||||
if (!app.hasConnected) {
|
||||
window.location = '/login';
|
||||
}
|
||||
});
|
||||
|
||||
client.on('auth:failed', function () {
|
||||
|
@ -4979,19 +4979,31 @@ WSConnection.prototype.connect = function (opts) {
|
||||
self.parser = new DOMParser();
|
||||
self.serializer = new XMLSerializer();
|
||||
|
||||
self.conn = new WebSocket(opts.wsURL, 'xmpp');
|
||||
try {
|
||||
self.conn = new WebSocket(opts.wsURL, 'xmpp');
|
||||
self.conn.onerror = function (e) {
|
||||
e.preventDefault();
|
||||
console.log(e);
|
||||
self.emit('disconnected', self);
|
||||
return false;
|
||||
};
|
||||
|
||||
self.conn.onopen = function () {
|
||||
self.emit('connected', self);
|
||||
};
|
||||
self.conn.onclose = function () {
|
||||
self.emit('disconnected', self);
|
||||
};
|
||||
|
||||
self.conn.onclose = function () {
|
||||
self.emit('disconnected', self);
|
||||
};
|
||||
self.conn.onopen = function () {
|
||||
self.emit('connected', self);
|
||||
};
|
||||
|
||||
self.conn.onmessage = function (wsMsg) {
|
||||
self.emit('raw:incoming', wsMsg.data);
|
||||
};
|
||||
self.conn.onmessage = function (wsMsg) {
|
||||
self.emit('raw:incoming', wsMsg.data);
|
||||
};
|
||||
} catch (e) {
|
||||
console.log('Caught exception');
|
||||
return self.emit('disconnected', self);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
WSConnection.prototype.disconnect = function () {
|
||||
|
@ -1,10 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>OTalk</title>
|
||||
<link rel="stylesheet" type="text/css" href="#{cssFileName}" />
|
||||
<script src="#{jsFileName}"></script>
|
||||
</head>
|
||||
<body>
|
||||
<p>Connecting</p>
|
||||
<body class="aux">
|
||||
<header>
|
||||
<img id="logo" src="/logo.png" alt="OTalk" />
|
||||
</header>
|
||||
<section id="loginbox" class="content">
|
||||
<h2>Connecting...</h2>
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -16,6 +16,7 @@ module.exports = HumanView.extend({
|
||||
},
|
||||
render: function () {
|
||||
$('head').append(templates.head());
|
||||
$('body').removeClass('aux');
|
||||
this.renderAndBind();
|
||||
this.renderCollection(me.contacts, ContactListItem, this.$('#contactList'));
|
||||
return this;
|
||||
|
30
public/oauthLogin.js
Normal file
30
public/oauthLogin.js
Normal file
@ -0,0 +1,30 @@
|
||||
var parts = window.location.hash.slice(1).split('&');
|
||||
|
||||
parts.forEach(function (value) {
|
||||
if (value.substr(0, 12) === "access_token") {
|
||||
var token = value.substr(13);
|
||||
$.ajax({
|
||||
type: 'get',
|
||||
url: 'https://api.andbang.com/me',
|
||||
dataType: 'json',
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + token
|
||||
},
|
||||
success: function (user) {
|
||||
localStorage.config = JSON.stringify({
|
||||
jid: user.username.toLowerCase() + "@otalk.im",
|
||||
server: "otalk.im",
|
||||
wsURL: "wss://otalk.im/xmpp-websocket",
|
||||
credentials: {
|
||||
username: user.username.toLowerCase(),
|
||||
password: token
|
||||
}
|
||||
});
|
||||
window.location = '/';
|
||||
},
|
||||
error: function () {
|
||||
window.location = '/logout';
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
@ -40,6 +40,7 @@ nav.main {
|
||||
margin: 0px;
|
||||
text-align: center;
|
||||
box-sizing: border-box;
|
||||
-moz-box-sizing: border-box;
|
||||
position: fixed;
|
||||
bottom: 0px;
|
||||
left: 0px;
|
||||
@ -64,6 +65,7 @@ nav.main a {
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
box-sizing: border-box;
|
||||
-moz-box-sizing: border-box;
|
||||
}
|
||||
|
||||
#contactList {
|
||||
@ -186,6 +188,7 @@ nav.main a {
|
||||
#conversation {
|
||||
background: #ecf0f2;
|
||||
box-sizing: border-box;
|
||||
-moz-box-sizing: border-box;
|
||||
bottom: 0;
|
||||
margin: 0;
|
||||
padding-bottom: 30px;
|
||||
@ -363,12 +366,13 @@ nav.main a {
|
||||
border: 1px solid #eeeeee;
|
||||
color: #2e2d2d;
|
||||
box-sizing: border-box;
|
||||
-moz-box-sizing: border-box;
|
||||
}
|
||||
#loginbox input:focus {
|
||||
border: 1px solid #a7d9eb;
|
||||
outline: 0px;
|
||||
}
|
||||
#loginbox button {
|
||||
#loginbox button, .andyetLogin {
|
||||
text-decoration: none;
|
||||
text-align: center;
|
||||
border-radius: 3px;
|
||||
@ -385,6 +389,11 @@ nav.main a {
|
||||
padding-bottom: 10px;
|
||||
border-bottom: 1px solid #f8f8f8
|
||||
}
|
||||
.andyetLogin {
|
||||
display: block;
|
||||
float: right;
|
||||
font-size: 14px;
|
||||
}
|
||||
.aux header {
|
||||
margin-top: 10%;
|
||||
text-align: center;
|
||||
|
@ -48,6 +48,12 @@ app.get('/login', function (req, res) {
|
||||
app.get('/logout', function (req, res) {
|
||||
res.render('logout');
|
||||
});
|
||||
app.get('/oauth/login', function (req, res) {
|
||||
res.redirect('https://apps.andyet.com/oauth/authorize?client_id=' + config.andyetAuth.id + '&response_type=token');
|
||||
});
|
||||
app.get('/oauth/callback', function (req, res) {
|
||||
res.render('oauthLogin');
|
||||
});
|
||||
|
||||
// serves app on every other url
|
||||
app.get('*', clientApp.html());
|
||||
|
@ -13,4 +13,5 @@ html
|
||||
block content
|
||||
|
||||
script(src='/zepto.js')
|
||||
script(src='//static.andyet.com/tag.js')
|
||||
block scripts
|
||||
|
@ -2,6 +2,7 @@ extends layout
|
||||
|
||||
block content
|
||||
section#loginbox.content
|
||||
a.andyetLogin(href="/oauth/login") have an &yet account?
|
||||
h2 Log in
|
||||
form
|
||||
.fieldContainer
|
||||
|
4
views/oauthLogin.jade
Normal file
4
views/oauthLogin.jade
Normal file
@ -0,0 +1,4 @@
|
||||
extends layout
|
||||
|
||||
block scripts
|
||||
script(src="/oauthLogin.js")
|
Loading…
Reference in New Issue
Block a user