-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddusers.js
37 lines (35 loc) · 1.35 KB
/
addusers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const r = require('rethinkdb');
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
// TODO run expirements
// 1. Figure out if perms are all no by default or if they have to be set
// 2. Attempt to recreate table not found crashing
// 3. Implement things like user deletion
rl.question('Do you want to (a)dd a user (d)elete a user, or (c)reate a workspace?', choice => {
switch(choice) {
case "a"
rl.question('Admin password (if one specified otherwise leave blank)', admin_password => {
r.connect( {host:'localhost', port: 28015, user: "admin", password: admin_password}, function(err, conn) {
rl.question('New user username: ', new_username => {
rl.question('New user password: ', new_password => {
r.db('rethinkdb').table('users').insert({id: new_username, password: new_password}).run(conn, (err, result) => {
if (err) console.log("something has gone wrong with creating that user please try again")
r.db('users').tableCreate(new_username).run(conn, (err, result) => {
r.db('users').table(new_username).insert([{
tags: {},
tasks: {},
projects: {}
}]).run(conn);
r.db.('users').table(new_username).grant(new_username, {read: true, write: true, config: false});
})
})
})
})
}
}
break;
}
})