mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-31 19:15:58 +01:00
added login, fixed gitignore
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -4,6 +4,4 @@
|
|||||||
|
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
node_modules/
|
node_modules/
|
||||||
!/node_modules/
|
|
||||||
!src/node_modules/
|
|
||||||
sftp-config.json
|
sftp-config.json
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function templates_init() {
|
function templates_init() {
|
||||||
loadTemplates(['register', 'home']);
|
loadTemplates(['register', 'home', 'login']);
|
||||||
}
|
}
|
||||||
|
|
||||||
templates_init();
|
templates_init();
|
||||||
@@ -113,7 +113,7 @@
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<script>
|
<script>
|
||||||
var socket = io.connect('http://198.58.101.18:8081');
|
var socket = io.connect('http://198.199.80.41:8081');
|
||||||
|
|
||||||
socket.on('event:connect', function(data) {
|
socket.on('event:connect', function(data) {
|
||||||
|
|
||||||
@@ -131,6 +131,7 @@
|
|||||||
<ul class="nav">
|
<ul class="nav">
|
||||||
<li class="active"><a href="/">Home</a></li>
|
<li class="active"><a href="/">Home</a></li>
|
||||||
<li><a href="/register">Register</a></li>
|
<li><a href="/register">Register</a></li>
|
||||||
|
<li><a href="/login">Login</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
36
public/templates/login.tpl
Normal file
36
public/templates/login.tpl
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<h1>Login</h1>
|
||||||
|
<div class="well">
|
||||||
|
<div class="alert alert-error" id="error" style="display:none">
|
||||||
|
<button type="button" class="close" data-dismiss="alert">×</button>
|
||||||
|
<strong>Failed Login Attempt</strong> <p></p>
|
||||||
|
</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>
|
||||||
|
</div>
|
||||||
|
<script type="text/javascript">
|
||||||
|
(function() {
|
||||||
|
var username = document.getElementById('username'),
|
||||||
|
password = document.getElementById('password'),
|
||||||
|
login = document.getElementById('login'),
|
||||||
|
error = document.getElementById('error');
|
||||||
|
|
||||||
|
login.onclick = function() {
|
||||||
|
socket.emit('user.login', {
|
||||||
|
username: username.value,
|
||||||
|
password: password.value
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
socket.on('user.login', function(data) {
|
||||||
|
console.log(data);
|
||||||
|
if (data.status === 0) {
|
||||||
|
jQuery('#error').show(50);
|
||||||
|
jQuery('#error p').html(data.message);
|
||||||
|
} else {
|
||||||
|
alert('success');
|
||||||
|
jQuery('#error').hide(50);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}());
|
||||||
|
</script>
|
||||||
@@ -19,10 +19,13 @@
|
|||||||
</script>
|
</script>
|
||||||
<!-- END Forum Info Template -->
|
<!-- END Forum Info Template -->
|
||||||
<!-- START Register Template -->
|
<!-- START Register Template -->
|
||||||
|
|
||||||
<h1>Register</h1>
|
<h1>Register</h1>
|
||||||
Username: <input type="text" placeholder="Enter Username" id="username" /> <span id="username-notify" class="label label-success"></span> <br />
|
<div class="well">
|
||||||
Password: <input type="password" placeholder="Enter Password" id="password" /><br />
|
<label>Username</label><input type="text" placeholder="Enter Username" id="username" /> <span id="username-notify" class="label label-success"></span> <br />
|
||||||
<button id="register" type="submit">Register Now</button>
|
<label>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">
|
<script type="text/javascript">
|
||||||
(function() {
|
(function() {
|
||||||
var username = document.getElementById('username'),
|
var username = document.getElementById('username'),
|
||||||
|
|||||||
@@ -7,17 +7,15 @@ var fs = require('fs');
|
|||||||
function loadTemplates(templatesToLoad) {
|
function loadTemplates(templatesToLoad) {
|
||||||
for (var t in templatesToLoad) {
|
for (var t in templatesToLoad) {
|
||||||
(function(template) {
|
(function(template) {
|
||||||
console.log(global.configuration.ROOT_DIRECTORY);
|
|
||||||
fs.readFile(global.configuration.ROOT_DIRECTORY + '/public/templates/' + template + '.tpl', function(err, html) {
|
fs.readFile(global.configuration.ROOT_DIRECTORY + '/public/templates/' + template + '.tpl', function(err, html) {
|
||||||
global.templates[template] = html;
|
global.templates[template] = html;
|
||||||
console.log(html);
|
|
||||||
});
|
});
|
||||||
}(templatesToLoad[t]));
|
}(templatesToLoad[t]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Templates.init = function() {
|
Templates.init = function() {
|
||||||
loadTemplates(['header', 'footer', 'register', 'home']);
|
loadTemplates(['header', 'footer', 'register', 'home', 'login']);
|
||||||
}
|
}
|
||||||
|
|
||||||
}(exports));
|
}(exports));
|
||||||
38
src/user.js
38
src/user.js
@@ -3,15 +3,45 @@ var RDB = require('./redis.js');
|
|||||||
(function(User) {
|
(function(User) {
|
||||||
var current_uid;
|
var current_uid;
|
||||||
|
|
||||||
|
User.login = function(user) {
|
||||||
|
if (current_uid) {
|
||||||
|
return global.socket.emit('user.login', {'status': 0, 'message': 'User is already logged in.'});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user.username == null || user.password == null) {
|
||||||
|
return global.socket.emit('user.login', {'status': 0, 'message': 'Missing fields'});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
RDB.get('username:' + user.username + ':uid', function(uid) {
|
||||||
|
if (uid == null) {
|
||||||
|
return global.socket.emit('user.login', {'status': 0, 'message': 'Username does not exist.'});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
RDB.get('uid:' + uid + ':password', function(password) {
|
||||||
|
if (user.password != password) {
|
||||||
|
return global.socket.emit('user.login', {'status': 0, 'message': 'Incorrect username / password combination.'});
|
||||||
|
} else {
|
||||||
|
console.log('in');
|
||||||
|
return global.socket.emit('user.login', {'status': 1, 'message': 'Logged in!'});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
User.create = function(username, password) {
|
User.create = function(username, password) {
|
||||||
if (current_uid) {
|
if (current_uid) {
|
||||||
global.socket.emit('user.create', {'status': 0, 'message': 'Only anonymous users can register a new account.'});
|
return; global.socket.emit('user.create', {'status': 0, 'message': 'Only anonymous users can register a new account.'});
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (username == null || password == null) {
|
if (username == null || password == null) {
|
||||||
global.socket.emit('user.create', {'status': 0, 'message': 'Missing fields'});
|
return; global.socket.emit('user.create', {'status': 0, 'message': 'Missing fields'});
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,13 @@ var express = require('express'),
|
|||||||
res.end(body);
|
res.end(body);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
app.get('/register', function(req, res) {
|
app.get('/register', function(req, res) {
|
||||||
var body = templates['header'] + templates['register'] + templates['footer'];
|
var body = templates['header'] + templates['register'] + templates['footer'];
|
||||||
|
|||||||
@@ -37,6 +37,10 @@ var SocketIO = require('socket.io').listen(8081);
|
|||||||
socket.on('user.latest', function(data) {
|
socket.on('user.latest', function(data) {
|
||||||
modules.user.latest(data);
|
modules.user.latest(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on('user.login', function(data) {
|
||||||
|
modules.user.login(data);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
}(SocketIO));
|
}(SocketIO));
|
||||||
|
|||||||
Reference in New Issue
Block a user