mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-14 01:45:47 +01:00
issue #891
This commit is contained in:
48
src/login.js
48
src/login.js
@@ -7,53 +7,5 @@ var user = require('./user'),
|
|||||||
|
|
||||||
(function(Login) {
|
(function(Login) {
|
||||||
|
|
||||||
Login.loginViaLocal = function(username, password, next) {
|
|
||||||
if (!username || !password) {
|
|
||||||
return next({
|
|
||||||
status: 'error',
|
|
||||||
message: 'invalid-user'
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
|
|
||||||
var userslug = utils.slugify(username);
|
|
||||||
|
|
||||||
user.getUidByUserslug(userslug, function(err, uid) {
|
|
||||||
|
|
||||||
if (err) {
|
|
||||||
return next(new Error('redis-error'));
|
|
||||||
} else if (uid == null) {
|
|
||||||
return next(new Error('invalid-user'));
|
|
||||||
}
|
|
||||||
|
|
||||||
user.getUserFields(uid, ['password', 'banned'], function(err, userData) {
|
|
||||||
if (err) return next(err);
|
|
||||||
|
|
||||||
if (userData.banned && parseInt(userData.banned, 10) === 1) {
|
|
||||||
return next({
|
|
||||||
status: "error",
|
|
||||||
message: "user-banned"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
bcrypt.compare(password, userData.password, function(err, res) {
|
|
||||||
if (err) {
|
|
||||||
winston.err(err.message);
|
|
||||||
next(new Error('bcrypt compare error'));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (res) {
|
|
||||||
next(null, {
|
|
||||||
user: {
|
|
||||||
uid: uid
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
next(new Error('invalid-password'));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}(exports));
|
}(exports));
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
(function(Auth) {
|
(function(Auth) {
|
||||||
var passport = require('passport'),
|
var passport = require('passport'),
|
||||||
passportLocal = require('passport-local').Strategy,
|
passportLocal = require('passport-local').Strategy,
|
||||||
login_strategies = [],
|
|
||||||
nconf = require('nconf'),
|
nconf = require('nconf'),
|
||||||
|
bcrypt = require('bcryptjs'),
|
||||||
|
winston = require('winston'),
|
||||||
|
|
||||||
meta = require('../meta'),
|
meta = require('../meta'),
|
||||||
user = require('../user'),
|
user = require('../user'),
|
||||||
plugins = require('../plugins'),
|
plugins = require('../plugins'),
|
||||||
winston = require('winston'),
|
utils = require('../../public/src/utils'),
|
||||||
login_module = require('./../login');
|
|
||||||
|
login_strategies = [];
|
||||||
|
|
||||||
passport.use(new passportLocal(function(user, password, next) {
|
passport.use(new passportLocal(function(user, password, next) {
|
||||||
login_module.loginViaLocal(user, password, function(err, login) {
|
Auth.login(user, password, function(err, login) {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
next(null, login.user);
|
next(null, login.user);
|
||||||
} else {
|
} else {
|
||||||
@@ -145,4 +148,53 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Auth.login = function(username, password, next) {
|
||||||
|
if (!username || !password) {
|
||||||
|
return next({
|
||||||
|
status: 'error',
|
||||||
|
message: 'invalid-user'
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
|
||||||
|
var userslug = utils.slugify(username);
|
||||||
|
|
||||||
|
user.getUidByUserslug(userslug, function(err, uid) {
|
||||||
|
if (err) {
|
||||||
|
return next(new Error('redis-error'));
|
||||||
|
} else if (uid == null) {
|
||||||
|
return next(new Error('invalid-user'));
|
||||||
|
}
|
||||||
|
|
||||||
|
user.getUserFields(uid, ['password', 'banned'], function(err, userData) {
|
||||||
|
if (err) return next(err);
|
||||||
|
|
||||||
|
if (userData.banned && parseInt(userData.banned, 10) === 1) {
|
||||||
|
return next({
|
||||||
|
status: "error",
|
||||||
|
message: "user-banned"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
bcrypt.compare(password, userData.password, function(err, res) {
|
||||||
|
if (err) {
|
||||||
|
winston.err(err.message);
|
||||||
|
next(new Error('bcrypt compare error'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (res) {
|
||||||
|
next(null, {
|
||||||
|
user: {
|
||||||
|
uid: uid
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
next(new Error('invalid-password'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}(exports));
|
}(exports));
|
||||||
Reference in New Issue
Block a user