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() {
|
||||
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() {
|
||||
console.log('checking email existance');
|
||||
|
||||
@@ -3,22 +3,33 @@
|
||||
<div class="alert alert-success" id="success" style="display:none">
|
||||
<button type="button" class="close" data-dismiss="alert">×</button>
|
||||
<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 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 />
|
||||
<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>
|
||||
<script type="text/javascript">
|
||||
(function() {
|
||||
/*socket.on('user.login', function(data) {
|
||||
console.log(data);
|
||||
if (data.status === 0) {
|
||||
jQuery('#error').show(50);
|
||||
jQuery('#error p').html(data.message);
|
||||
socket.on('user.send_reset', function(data) {
|
||||
var inputEl = document.getElementById('email'),
|
||||
submitEl = document.getElementById('reset'),
|
||||
invalidEl = document.getElementById('invalid-email');
|
||||
|
||||
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 {
|
||||
alert('success');
|
||||
jQuery('#error').hide(50);
|
||||
jQuery('#success').hide();
|
||||
jQuery('#error').show();
|
||||
invalidEl.innerHTML = data.email;
|
||||
}
|
||||
});*/
|
||||
});
|
||||
}());
|
||||
</script>
|
||||
23
src/user.js
23
src/user.js
@@ -95,12 +95,31 @@ var RDB = require('./redis.js');
|
||||
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 = {
|
||||
exists: function(email) {
|
||||
exists: function(email, callback) {
|
||||
RDB.get('email:' + email, function(exists) {
|
||||
console.log('email:' + email, 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.bodyParser());
|
||||
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.methodOverride());
|
||||
// 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.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});
|
||||
|
||||
// BEGIN: API calls (todo: organize)
|
||||
// julian: :^)
|
||||
socket.on('user.create', function(data) {
|
||||
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) {
|
||||
modules.user.email.exists(data.email);
|
||||
});
|
||||
|
||||
socket.on('user.send_reset', function(data) {
|
||||
modules.user.send_reset(data.email);
|
||||
});
|
||||
});
|
||||
|
||||
}(SocketIO));
|
||||
|
||||
Reference in New Issue
Block a user