mirror of https://gitgud.io/fatchan/jschan.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.1 KiB
49 lines
1.1 KiB
|
|
'use strict';
|
|
|
|
const Mongo = require(__dirname+'/db.js')
|
|
, db = Mongo.client.db('jschan').collection('accounts')
|
|
, bcrypt = require('bcrypt');
|
|
|
|
module.exports = {
|
|
|
|
findOne: (username) => {
|
|
return db.findOne({ '_id': username });
|
|
},
|
|
|
|
insertOne: async (username, password, authLevel) => {
|
|
/* auth levels
|
|
3: site admin/owner -- all permissions e.g. post/board/board config management
|
|
2: global mod -- delete posts anywhere
|
|
1: regular user -- permissions for boards they own or were given moderator on
|
|
on user-created boards (planned feature), only owner can delete board or change board settings
|
|
assigned moderators can delete posts.
|
|
*/
|
|
|
|
// hash the password
|
|
const passwordHash = await bcrypt.hash(password, 12);
|
|
|
|
//add to db
|
|
return db.insertOne({
|
|
'_id': username,
|
|
'passwordHash': passwordHash,
|
|
'authLevel': authLevel,
|
|
});
|
|
},
|
|
|
|
promoteUser: (username, newlevel) => {
|
|
//increase users auth level
|
|
return db.updateOne({
|
|
'_id': username
|
|
}, {
|
|
'$set': {
|
|
'authLevel': newlevel
|
|
}
|
|
})
|
|
},
|
|
|
|
deleteAll: () => {
|
|
return db.deleteMany({});
|
|
},
|
|
|
|
}
|
|
|