Add users.findByUsername()
This commit is contained in:
parent
9af735d474
commit
dff9996fda
1 changed files with 23 additions and 0 deletions
|
@ -61,6 +61,29 @@ module.exports.findByAccessToken = (accessToken, callback) => {
|
|||
});
|
||||
};
|
||||
|
||||
module.exports.findByUsername = (username, callback) => {
|
||||
db.getConnection((err, connection) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
connection.query('SELECT `id`, `username`, `email`, `access_token` FROM `users` WHERE `username`=? LIMIT 1', [username], (err, rows) => {
|
||||
connection.release();
|
||||
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (!rows.length) {
|
||||
return callback(null, false);
|
||||
}
|
||||
|
||||
let user = tools.convertKeys(rows[0]);
|
||||
return callback(null, user);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Fetches user by username and password
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue