added email to registration fields, email existence check

v1.18.x
Julian Lam 12 years ago
parent d4d185ec4f
commit f975105176

2
.gitignore vendored

@ -5,4 +5,4 @@
npm-debug.log
node_modules/
sftp-config.json
public/config.json
public/config.json

@ -13,7 +13,7 @@ function loadTemplates(templatesToLoad) {
}
function templates_init() {
loadTemplates(['register', 'home', 'login']);
loadTemplates(['register', 'home', 'login', 'reset']);
}
templates_init();

@ -6,7 +6,8 @@
</div>
<label>Username</label><input type="text" placeholder="Enter Username" id="username" /><br />
<label>Password</label><input type="password" placeholder="Enter Password" id="password" /><br />
<button class="btn btn-primary" id="login" type="submit">Login</button>
<button class="btn btn-primary" id="login" type="submit">Login</button> &nbsp;
<a href="/reset">Forgot Password?</a>
</div>
<script type="text/javascript">
(function() {

@ -22,8 +22,9 @@
<h1>Register</h1>
<div class="well">
<label>Username</label><input type="text" placeholder="Enter Username" id="username" /> <span id="username-notify" class="label label-success"></span> <br />
<label>Password</label><input type="password" placeholder="Enter Password" id="password" /><br />
<label for="email">Email Address</label><input type="email" placeholder="Enter Email Address" id="email" /> <span id="email-notify" class="label label-important"></span> <br />
<label for="username">Username</label><input type="text" placeholder="Enter Username" id="username" /> <span id="username-notify" class="label label-success"></span> <br />
<label for="password">Password</label><input type="password" placeholder="Enter Password" id="password" /><br />
<button class="btn btn-primary" id="register" type="submit">Register Now</button>
</div>
<script type="text/javascript">
@ -31,18 +32,25 @@
var username = document.getElementById('username'),
password = document.getElementById('password'),
register = document.getElementById('register'),
username_notify = document.getElementById('username-notify');
emailEl = document.getElementById('email'),
username_notify = document.getElementById('username-notify'),
email_notify = document.getElementById('email-notify');
register.onclick = function() {
socket.emit('user.create', {
username: username.value,
password: password.value
password: password.value,
email: emailEl.value
});
};
username.onkeyup = function() {
socket.emit('user.exists', {username: username.value});
}
emailEl.addEventListener('change', function() {
console.log('checking email existance');
socket.emit('user.email.exists', { email: emailEl.value });
}, false);
socket.on('user.create', function(data) {
//console.log('user create: ' + data.status);
@ -56,5 +64,12 @@
username_notify.className = 'label label-success';
}
});
socket.on('user.email.exists', function(data) {
if (data.exists === true) {
email_notify.innerHTML = 'Email Address exists';
} else {
email_notify.innerHTML = '';
}
});
}());
</script>

@ -15,7 +15,7 @@ var fs = require('fs');
}
Templates.init = function() {
loadTemplates(['header', 'footer', 'register', 'home', 'login']);
loadTemplates(['header', 'footer', 'register', 'home', 'login', 'reset']);
}
}(exports));

@ -35,7 +35,7 @@ var RDB = require('./redis.js');
};
User.create = function(username, password) {
User.create = function(username, password, email) {
if (current_uid) {
return; global.socket.emit('user.create', {'status': 0, 'message': 'Only anonymous users can register a new account.'});
}
@ -54,6 +54,8 @@ var RDB = require('./redis.js');
RDB.set('username:' + username + ':uid', uid);
RDB.set('uid:' + uid + ':username', username);
RDB.set('uid:' + uid + ':password', password);
RDB.set('uid:' + uid + ':email', email);
RDB.set('email:' + email, uid);
RDB.incr('user:count', function(count) {
io.sockets.emit('user.count', {count: count});
@ -93,5 +95,13 @@ var RDB = require('./redis.js');
RDB.get('username:' + username + ':uid', callback);
};
User.email = {
exists: function(email) {
RDB.get('email:' + email, function(exists) {
console.log('email:' + email, exists);
exists = !!exists;
global.socket.emit('user.email.exists', { exists: exists });
});
}
}
}(exports));

@ -7,22 +7,17 @@ var express = require('express'),
(function(app) {
var templates = global.templates;
app.get('/test', function(req, res) {
var body = 'testing';
res.send(body);
});
app.get('/', function(req, res) {
console.log(templates['header']);
res.send(templates['header'] + templates['home'] + templates['footer']);
});
app.get('/login', function(req, res) {
var body = templates['header'] + templates['login'] + templates['footer'];
res.setHeader('Content-Type', 'text/html');
res.setHeader('Content-Length', body.length);
res.end(body);
res.send(templates['header'] + templates['login'] + templates['footer']);
});
app.get('/reset', function(req, res) {
res.send(templates['header'] + templates['reset'] + templates['footer']);
});
app.get('/register', function(req, res) {
res.send(templates['header'] + templates['register'] + templates['footer']);

@ -23,7 +23,7 @@ var SocketIO = require('socket.io').listen(global.server);
// BEGIN: API calls (todo: organize)
socket.on('user.create', function(data) {
modules.user.create(data.username, data.password);
modules.user.create(data.username, data.password, data.email);
});
socket.on('user.exists', function(data) {
@ -40,7 +40,11 @@ var SocketIO = require('socket.io').listen(global.server);
socket.on('user.login', function(data) {
modules.user.login(data);
});
});
socket.on('user.email.exists', function(data) {
modules.user.email.exists(data.email);
});
});
}(SocketIO));

Loading…
Cancel
Save