commit
1b4eeab7ea
@ -1,8 +1,8 @@
|
|||||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||||
body { font: 13px Helvetica, Arial; }
|
body { font: 13px Helvetica, Arial; }
|
||||||
form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; }
|
#chatForm { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; }
|
||||||
form input { border: 0; padding: 10px; width: 90%; margin-right: .5%; }
|
#chatForm input { border: 0; padding: 10px; width: 90%; margin-right: .5%; }
|
||||||
form button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; }
|
#chatForm button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; }
|
||||||
#messages { list-style-type: none; margin: 0; padding: 0; }
|
#messages { list-style-type: none; margin: 0; padding: 0; }
|
||||||
#messages li { padding: 5px 10px; }
|
#messages li { padding: 5px 10px; }
|
||||||
#messages li:nth-child(odd) { background: #eee; }
|
#messages li:nth-child(odd) { background: #eee; }
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
extends layout
|
extends layout
|
||||||
|
|
||||||
block content
|
block content
|
||||||
script(src="https://cdn.auth0.com/js/lock-9.2.min.js")
|
script(src="https://cdn.auth0.com/js/lock/10.0/lock.min.js")
|
||||||
script(src="/socket.io/socket.io.js")
|
script(src="/socket.io/socket.io.js")
|
||||||
script(src="http://code.jquery.com/jquery-1.12.4.js")
|
script(src="http://code.jquery.com/jquery-1.12.4.js")
|
||||||
|
|
||||||
@ -10,7 +10,7 @@ block content
|
|||||||
button.btn Login
|
button.btn Login
|
||||||
div#chat
|
div#chat
|
||||||
ul#messages
|
ul#messages
|
||||||
form(action="")
|
form(id="chatForm" action="")
|
||||||
input(id="m" autocomplete="off")
|
input(id="m" autocomplete="off")
|
||||||
button.btn Send
|
button.btn Send
|
||||||
|
|
||||||
@ -18,30 +18,36 @@ block content
|
|||||||
var userProfile;
|
var userProfile;
|
||||||
var userToken;
|
var userToken;
|
||||||
var lock = new Auth0Lock('#{env.AUTH0_CLIENT_ID}', '#{env.AUTH0_DOMAIN}');
|
var lock = new Auth0Lock('#{env.AUTH0_CLIENT_ID}', '#{env.AUTH0_DOMAIN}');
|
||||||
var hash = lock.parseHash();
|
var id_token = localStorage.getItem('id_token');
|
||||||
$('#chat').hide();
|
$('#chat').hide();
|
||||||
$('#login button').click(function (e) {
|
$('#login button').click(function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
lock.show();
|
lock.show();
|
||||||
});
|
});
|
||||||
|
|
||||||
if (hash) {
|
lock.on('authenticated', function(authResult) {
|
||||||
if (hash.error) {
|
lock.getProfile(authResult.idToken, function(error, profile) {
|
||||||
console.log("There was an error logging in", hash.error);
|
if (error) {
|
||||||
}
|
// Handle error
|
||||||
else {
|
return;
|
||||||
lock.getProfile(hash.id_token, function (err, profile) {
|
}
|
||||||
if (err) {
|
console.log('connected and authenticated');
|
||||||
console.log('Cannot get user', err);
|
localStorage.setItem('id_token', authResult.idToken);
|
||||||
return;
|
localStorage.setItem('profile', JSON.stringify(profile));
|
||||||
}
|
userProfile = profile;
|
||||||
console.log('connected and authenticated');
|
id_token = authResult.idToken;
|
||||||
userProfile = profile;
|
openChat();
|
||||||
localStorage.setItem('userToken', hash.id_token);
|
});
|
||||||
userToken = hash.id_token;
|
});
|
||||||
openChat();
|
|
||||||
});
|
if (id_token) {
|
||||||
}
|
lock.getProfile(id_token, function (err, profile) {
|
||||||
|
if (err) {
|
||||||
|
return alert('There was an error getting the profile: ' + err.message);
|
||||||
|
}
|
||||||
|
userProfile = profile;
|
||||||
|
openChat();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function openChat() {
|
function openChat() {
|
||||||
@ -49,7 +55,7 @@ block content
|
|||||||
socket
|
socket
|
||||||
.on('connect', function (msg) {
|
.on('connect', function (msg) {
|
||||||
console.log("connected");
|
console.log("connected");
|
||||||
socket.emit('authenticate', {token: userToken}); // send the jwt
|
socket.emit('authenticate', {token: id_token}); // send the jwt
|
||||||
})
|
})
|
||||||
.on('authenticated', function () {
|
.on('authenticated', function () {
|
||||||
//Do
|
//Do
|
||||||
|
Reference in New Issue
Block a user