Permalink
Browse files

Added authentication verification and avatar picker

  • Loading branch information...
robrighter committed Jan 14, 2012
1 parent 854b167 commit 534ea0c935369c9c9de328144157ac9248d39945
Showing with 89 additions and 29 deletions.
  1. +23 −15 server.js
  2. +21 −4 static/css/style.css
  3. +45 −10 static/js/script.js
View
@@ -3,7 +3,7 @@ var connect = require('connect')
, express = require('express')
, io = require('Socket.io')
, easyoauth = require('easy-oauth')
- , port = (process.env.PORT || 8081);
+ , port = (process.env.PORT || 19606); //
var crypto = require('crypto');
@@ -61,10 +61,10 @@ io.sockets.on('connection', function(socket){
socket.on('talk_character', function(data){
if(keylookups.hasOwnProperty(data.requestkey)){
- //TODO: ADD STRIP TABS
+ //STRIP TAGs
var message = {
character: keylookups[data.requestkey],
- message: data.message,
+ message: data.message.replace(/<(?:.|\n)*?>/gm, ''), //strip the tags
}
socket.broadcast.emit('server_talk_character',message);
socket.emit('server_talk_character',message);
@@ -122,19 +122,27 @@ server.get('/ajax/characters', function(req,res){
})
server.post('/ajax/initiate-character', function(req,res){
- //todo: CHECK THE AUTH AND MAKE SURE THEY ARE OAUTH WITH THIS TWITTER HANDLE
- characters[req.body.handle] = {
- image: req.body.image,
- location: {
- x: 100,
- y: 100
+ req.authenticate(['oauth'], function(error, authenticated) {
+ if( authenticated ){
+ console.log('Authenticated users');
+ characters[req.body.handle] = {
+ image: req.body.image,
+ location: {
+ x: 100,
+ y: 100
+ }
+ };
+ console.log('GOT A NEW CHARACTER: ' + req.body.handle);
+ console.log(characters[req.body.handle]);
+ notifyClientsAboutNewCharacter(req.body.handle);
+ createHash(req.body.handle, function(hash){
+ res.send({ requestkey: hash });
+ });
+ }
+ else{
+ console.log('Not Authenticated user');
+ res.send({ error: 'Not authenticated'});
}
- };
- console.log('GOT A NEW CHARACTER: ' + req.body.handle);
- console.log(characters[req.body.handle]);
- notifyClientsAboutNewCharacter(req.body.handle);
- createHash(req.body.handle, function(hash){
- res.send({ requestkey: hash });
});
});
View
@@ -208,10 +208,10 @@ td { vertical-align: top; }
body {
background-color: #ccc;
- background-image:url(/images/logo.png);
- background-repeat:no-repeat;
- background-attachment:fixed;
- background-position:center;
+ background-image: url(/images/logo.png);
+ background-repeat: no-repeat;
+ background-attachment: fixed;
+ background-position: center;
}
#contactinfo{
@@ -335,6 +335,23 @@ body {
min-height: 45px;
}
+.sprite-picker-box {
+ overflow: hidden;
+}
+
+.sprite-picker-box h2 {
+ font-family: 'Squada One', cursive;
+ font-size: 18px;
+ color: rgb(136,130,130);
+}
+
+.sprite-picker {
+ width: 32px;
+ height: 48px;
+ cursor: pointer;
+ float: left;
+}
+
View
@@ -15,19 +15,46 @@ $(document).ready(function() {
var socket;
var requestkey = '';
+ var character_images = [
+ 'chinese_m1.png',
+ 'chiss1.png',
+ 'darthvader.png',
+ 'golbez.png',
+ 'indianajones.png',
+ 'japanese_f1.png',
+ 'lando.png',
+ 'mandalorian2.png',
+ 'marionravenwood.png',
+ 'pirate_m2.png',
+ 'princessleia.png',
+ 'rebelpilot.png',
+ 'steampunk_m1.png',
+ 'weddingguy02.png'
+ ]
+
//setup the oauth button
$('#oauthbutt').click(function(){
openEasyOAuthBox('twitter',function(oauth){
- //var oauth = {user: {username: 'robrighter'} };
- $.post("/ajax/initiate-character", {
- handle: oauth.user.username,
- image: '/images/sprites/weddingguy02.png'
- }, function(data){
- requestkey = data.requestkey;
- });
- setupTalkInterface(oauth.user.username);
- });
- });
+ var username = oauth.user.username;
+ $('#controlbox').slideUp('slow', function(){
+ $('#controlbox').html(makeSpritePickers());
+ $('#controlbox').slideDown('slow');
+ $('.sprite-picker').click(function(){
+ //var oauth = {user: {username: 'robrighter'} };
+ var that = this;
+ var spriteimageurl = $(that).css('background-image').replace('url(','').replace(')','');
+ $.post("/ajax/initiate-character", {
+ handle: username,
+ image: spriteimageurl,
+ }, function(data){
+ console.log(data);
+ requestkey = data.requestkey;
+ setupTalkInterface(username);
+ });//initiate character
+ }); //sprite picker click
+ }); //slide up callback
+ }); //Oauth box
+ }); //Oauth button click
//load up the characters
$.get('/ajax/characters', function(data) {
@@ -168,5 +195,13 @@ $(document).ready(function() {
console.log('CHARACTER: ' + sprite + " says: " + message);
}
+ function makeSpritePickers(){
+ return "<div class='sprite-picker-box'><h2>Choose your Avatar</h2>" +
+ _.map(character_images, makeSpritePicker).join('') + "</div>"
+ }
+ function makeSpritePicker(image){
+ return "<div class='sprite-picker' style='background-image: url(/images/sprites/" + image + ")'></div>";
+ }
+
});

0 comments on commit 534ea0c

Please sign in to comment.