mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-24 01:10:31 +01:00
socketing for reset page - started on emailer
This commit is contained in:
@@ -45,7 +45,11 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
username.onkeyup = function() {
|
username.onkeyup = function() {
|
||||||
socket.emit('user.exists', {username: username.value});
|
if (username.value.length > 2) socket.emit('user.exists', {username: username.value});
|
||||||
|
else {
|
||||||
|
username_notify.innerHTML = 'Username too short';
|
||||||
|
username_notify.className = 'label label-important';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
emailEl.addEventListener('change', function() {
|
emailEl.addEventListener('change', function() {
|
||||||
console.log('checking email existance');
|
console.log('checking email existance');
|
||||||
|
|||||||
@@ -1,24 +1,35 @@
|
|||||||
<h1>Reset Password</h1>
|
<h1>Reset Password</h1>
|
||||||
<div class="well">
|
<div class="well">
|
||||||
<div class="alert alert-success" id="success" style="display:none">
|
<div class="alert alert-success" id="success" style="display:none">
|
||||||
<button type="button" class="close" data-dismiss="alert">×</button>
|
<button type="button" class="close" data-dismiss="alert">×</button>
|
||||||
<strong>Password Reset Sent</strong>
|
<strong>Password Reset Sent</strong>
|
||||||
<p>An email has been dispatched to <span id="reset-email"></span> with instructions on setting a new password.</p>
|
<p></p>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="alert" id="error" style="display:none">
|
||||||
|
<button type="button" class="close" data-dismiss="alert">×</button>
|
||||||
|
<strong>Invalid Email!</strong>
|
||||||
|
<p>The email you put in (<span id="invalid-email"></span>) is not registered with us. Please try again.</p>
|
||||||
|
</div>
|
||||||
<label>Email Address</label><input type="text" placeholder="Enter Email Address" id="email" /><br />
|
<label>Email Address</label><input type="text" placeholder="Enter Email Address" id="email" /><br />
|
||||||
<button class="btn btn-primary" id="login" type="submit">Reset Password</button>
|
<button class="btn btn-primary" id="reset" type="submit">Reset Password</button>
|
||||||
</div>
|
</div>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
(function() {
|
(function() {
|
||||||
/*socket.on('user.login', function(data) {
|
socket.on('user.send_reset', function(data) {
|
||||||
console.log(data);
|
var inputEl = document.getElementById('email'),
|
||||||
if (data.status === 0) {
|
submitEl = document.getElementById('reset'),
|
||||||
jQuery('#error').show(50);
|
invalidEl = document.getElementById('invalid-email');
|
||||||
jQuery('#error p').html(data.message);
|
|
||||||
|
if (data.status === 'ok') {
|
||||||
|
jQuery('#error').hide();
|
||||||
|
jQuery('#success').show();
|
||||||
|
jQuery('#success p').html('An email has been dispatched to "' + data.email + '" with instructions on setting a new password.');
|
||||||
|
inputEl.value = '';
|
||||||
} else {
|
} else {
|
||||||
alert('success');
|
jQuery('#success').hide();
|
||||||
jQuery('#error').hide(50);
|
jQuery('#error').show();
|
||||||
|
invalidEl.innerHTML = data.email;
|
||||||
}
|
}
|
||||||
});*/
|
});
|
||||||
}());
|
}());
|
||||||
</script>
|
</script>
|
||||||
23
src/user.js
23
src/user.js
@@ -95,12 +95,31 @@ var RDB = require('./redis.js');
|
|||||||
RDB.get('username:' + username + ':uid', callback);
|
RDB.get('username:' + username + ':uid', callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
User.send_reset = function(email) {
|
||||||
|
User.email.exists(email, function(exists) {
|
||||||
|
if (exists) {
|
||||||
|
global.socket.emit('user.send_reset', {
|
||||||
|
status: "ok",
|
||||||
|
message: "code-sent",
|
||||||
|
email: email
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
global.socket.emit('user.send_reset', {
|
||||||
|
status: "error",
|
||||||
|
message: "invalid-email",
|
||||||
|
email: email
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
User.email = {
|
User.email = {
|
||||||
exists: function(email) {
|
exists: function(email, callback) {
|
||||||
RDB.get('email:' + email, function(exists) {
|
RDB.get('email:' + email, function(exists) {
|
||||||
console.log('email:' + email, exists);
|
console.log('email:' + email, exists);
|
||||||
exists = !!exists;
|
exists = !!exists;
|
||||||
global.socket.emit('user.email.exists', { exists: exists });
|
if (typeof callback !== 'function') global.socket.emit('user.email.exists', { exists: exists });
|
||||||
|
else callback(exists);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,10 +29,9 @@ var express = require('express'),
|
|||||||
app.use(express.favicon());
|
app.use(express.favicon());
|
||||||
app.use(express.bodyParser());
|
app.use(express.bodyParser());
|
||||||
app.use(express.cookieParser());
|
app.use(express.cookieParser());
|
||||||
app.use(express.logger({ format: '\x1b[1m:method\x1b[0m \x1b[33m:url\x1b[0m :response-time ms' }));
|
// app.use(express.logger({ format: '\x1b[1m:method\x1b[0m \x1b[33m:url\x1b[0m :response-time ms' }));
|
||||||
app.use(express.methodOverride());
|
// app.use(express.methodOverride());
|
||||||
app.use(express.static(global.configuration.ROOT_DIRECTORY + '/public'));
|
app.use(express.static(global.configuration.ROOT_DIRECTORY + '/public'));
|
||||||
app.set('mailOptions', config.mailer);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ var SocketIO = require('socket.io').listen(global.server);
|
|||||||
socket.emit('event:connect', {status: 1});
|
socket.emit('event:connect', {status: 1});
|
||||||
|
|
||||||
// BEGIN: API calls (todo: organize)
|
// BEGIN: API calls (todo: organize)
|
||||||
|
// julian: :^)
|
||||||
socket.on('user.create', function(data) {
|
socket.on('user.create', function(data) {
|
||||||
modules.user.create(data.username, data.password, data.email);
|
modules.user.create(data.username, data.password, data.email);
|
||||||
});
|
});
|
||||||
@@ -45,6 +46,10 @@ var SocketIO = require('socket.io').listen(global.server);
|
|||||||
socket.on('user.email.exists', function(data) {
|
socket.on('user.email.exists', function(data) {
|
||||||
modules.user.email.exists(data.email);
|
modules.user.email.exists(data.email);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on('user.send_reset', function(data) {
|
||||||
|
modules.user.send_reset(data.email);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
}(SocketIO));
|
}(SocketIO));
|
||||||
|
|||||||
Reference in New Issue
Block a user