Node.js based forum software built for the modern web
added email to registration fields, email existence check
Julian Lamf975105176ac
diff --git a/.gitignore b/.gitignoreindex 81ff636051..81dff4b4a9 100644--- a/.gitignore+++ b/.gitignore@@ -5,4 +5,4 @@npm-debug.lognode_modules/sftp-config.json-public/config.json+public/config.json\ No newline at end of filediff --git a/public/src/templates.js b/public/src/templates.jsindex a62094fc8f..5e1c11f0a6 100644--- a/public/src/templates.js+++ b/public/src/templates.js@@ -13,7 +13,7 @@ function loadTemplates(templatesToLoad) {}function templates_init() {- loadTemplates(['register', 'home', 'login']);+ loadTemplates(['register', 'home', 'login', 'reset']);}templates_init();\ No newline at end of filediff --git a/public/templates/login.tpl b/public/templates/login.tplindex 28b4f86eec..85e3ddf419 100644--- a/public/templates/login.tpl+++ b/public/templates/login.tpl@@ -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> + <a href="/reset">Forgot Password?</a></div><script type="text/javascript">(function() {diff --git a/public/templates/register.tpl b/public/templates/register.tplindex 848dee5532..d4176eb6e5 100644--- a/public/templates/register.tpl+++ b/public/templates/register.tpl@@ -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>\ No newline at end of filediff --git a/src/templates.js b/src/templates.jsindex 13dcd694cb..39576a5bef 100644--- a/src/templates.js+++ b/src/templates.js@@ -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));\ No newline at end of filediff --git a/src/user.js b/src/user.jsindex d19c4321d8..bb399ddff2 100644--- a/src/user.js+++ b/src/user.js@@ -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));\ No newline at end of filediff --git a/src/webserver.js b/src/webserver.jsindex dbbb65ff4f..b131c19330 100644--- a/src/webserver.js+++ b/src/webserver.js@@ -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']);diff --git a/src/websockets.js b/src/websockets.jsindex 521f76702c..ea3486d18a 100644--- a/src/websockets.js+++ b/src/websockets.js@@ -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));