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