Skip to content

Commit

Permalink
Merge pull request #9 from laurilehmijoki/registering-of-new-users
Browse files Browse the repository at this point in the history
Registering of new users
  • Loading branch information
Miki Leskinen committed Apr 23, 2012
2 parents dda9e5c + 67a1323 commit bafea9a
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 15 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ Usage

Run `node team-radar.js`

### Registering or updating users

It is possible to
* Update existing users
* Register new users

#### Curl

`curl -d "nick=test&gravatarUsername=gee" http://localhost:8085/users`

#### Web UI

Open `http://localhost:8085/`, insert a nickname and optionally Gravatar username and press the button.

### Radiator view

* open `http://localhost:8085/?radiator=true` (client is hidden)
Expand Down Expand Up @@ -59,7 +73,6 @@ You will need [Node.js](http://nodejs.org/) and [npm](http://npmjs.org/). Also s

npm install socket.io
npm install express
npm install yaml

I installed these in my home folder under `node_modules`. Node.js finds
them easily there.
Expand Down
15 changes: 15 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"userRowHeight": 200,
"users": {
"miki": {
"nick": "miki",
"gravatarUsername": "mileskin"
},
"jill": {
"nick": "jill"
},
"mrfoobar": {
"nick": "mrfoobar"
}
}
}
11 changes: 0 additions & 11 deletions config.yaml

This file was deleted.

7 changes: 7 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
<input class="moodUpdateInput" type="text" size="50" maxlength="200"/>
<input class="sendMoodUpdate" type="submit" value="Send mood update"/>
</form>
<form>
<label for="nickInput">Nick</label>
<input id="nickInput" type="text" size="20" maxlength="25"/>
<label for="gravatarUsernameInput">Gravatar username (optional)</label>
<input id="gravatarUsernameInput" type="text" size="20" maxlength="25"/>
<input class="registerNewUser" type="submit" value="Register or update user"/>
</form>
</div>
</script>
<script id="nickOption" type="text/html">
Expand Down
14 changes: 14 additions & 0 deletions static/js/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@
}
})
})
$('.client .registerNewUser').click(function(event) {
event.preventDefault()
var nick = $('.client #nickInput').val()
var gravatarUsername = $('.client #gravatarUsernameInput').val()
$.ajax({
type: 'post',
url: '/users',
async: false,
data: {
nick: nick,
gravatarUsername: gravatarUsername
}
})
})
}

function parseIndexAndMessageFrom(string, defaultIndex) {
Expand Down
12 changes: 12 additions & 0 deletions static/spec/team-radar-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ describe('team radar', function() {
})
})

describe('client for registering or updating users', function() {
it('has input for nick when not in radiator mode', function() {
expect($('.client #nickInput')).toExist()
expect($('.client #nickInput')).toBeVisible()
})

it('has input for Gravatar username when not in radiator mode', function() {
expect($('.client #gravatarUsernameInput')).toExist()
expect($('.client #gravatarUsernameInput')).toBeVisible()
})
})

describe('client for posting mood updates', function() {
beforeEach(function() {
specHelper.initContext()
Expand Down
27 changes: 24 additions & 3 deletions team-radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ var express = require('express')
var app = express.createServer()
var io = require('socket.io').listen(app)
var fs = require('fs')
var yaml = require('yaml')
var configFile = 'config.yaml'
var configFile = 'config.json'

app.use(express.static(__dirname + '/static'))
app.use(express.bodyParser())
Expand All @@ -15,7 +14,7 @@ app.get('/', function(req, res) {

app.get('/config', function(req, res) {
fs.readFile(configFile, function(err, fileContents) {
res.send(yaml.eval(fileContents.toString()))
res.send(JSON.parse(fileContents.toString()))
})
})

Expand All @@ -27,3 +26,25 @@ app.post('/moodUpdate', function(req, res) {
res.send('ok')
})

app.post('/users', function(req, res) {
var username = req.body.nick
var createNewUser = function() {
var gravatarUsername = req.body.gravatarUsername
var newUser = {}
newUser['nick'] = username
if (gravatarUsername) {
newUser['gravatarUsername'] = gravatarUsername
}
return newUser
}
fs.readFile(configFile, function(err, fileContents) {
var config = JSON.parse(fileContents.toString())
config.users[username] = createNewUser()
fs.writeFile(configFile, JSON.stringify(config, null, 2), function(error) {
if (error) {
console.log("writing to file failed")
}
})
})
res.send('ok')
})

0 comments on commit bafea9a

Please sign in to comment.