auto create mpos worker

This commit is contained in:
k7 2014-04-21 16:09:37 +08:00
parent 566e44e03b
commit 882f779e20
1 changed files with 34 additions and 3 deletions

View File

@ -38,7 +38,7 @@ module.exports = function(logger, poolConfig){
connect(); connect();
this.handleAuth = function(workerName, password, authCallback){ this.handleAuth = function(workerName, password, authCallback){
connection.query( connection.query(
'SELECT password FROM pool_worker WHERE username = LOWER(?)', 'SELECT password FROM pool_worker WHERE username = LOWER(?)',
[workerName.toLowerCase()], [workerName.toLowerCase()],
@ -48,8 +48,39 @@ module.exports = function(logger, poolConfig){
JSON.stringify(err)); JSON.stringify(err));
authCallback(false); authCallback(false);
} }
else if (!result[0]) else if (!result[0]){
authCallback(false); if(mposConfig.autoCreateWorker){
var account = workerName.split('.')[0];
connection.query(
'SELECT username FROM accounts WHERE username = LOWER(?)',
[account.toLowerCase()],
function(err, result){
if (err){
logger.error(logIdentify, logComponent, 'Database error when authenticating account: ' +
JSON.stringify(err));
authCallback(false);
}else if(!result[0]){
authCallback(false);
}else{
connection.query(
"INSERT INTO `pool_worker` (`id`, `account_id`, `username`, `password`, `difficulty`, `monitor`) VALUES (NULL, ?, ?, '123', '0', '0');",
[result[0].id,workerName.toLowerCase()],
function(err, result){
if (err){
logger.error(logIdentify, logComponent, 'Database error when insert worker: ' +
JSON.stringify(err));
authCallback(false);
}else {
authCallback(true);
}
})
}
}
);
}else{
authCallback(false);
}
}
else if (mposConfig.stratumAuth === 'worker') else if (mposConfig.stratumAuth === 'worker')
authCallback(true); authCallback(true);
else if (result[0].password === password) else if (result[0].password === password)