-
Notifications
You must be signed in to change notification settings - Fork 5
/
create-user.js
74 lines (66 loc) · 1.84 KB
/
create-user.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var express = require('express');
var app = express();
var readline = require('readline');
var pg = require('pg');
var scrypt = require('scrypt');
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var rl = readline.createInterface(process.stdin, process.stdout);
var config = require('./config.json');
var knex = require('knex')(config.knex);
function buildUserTable(table) {
return knex.schema.hasTable(table).then(function(exists) {
if (!exists) {
return knex.schema.createTable(table, function(t) {
t.increments('id')
.notNullable()
.primary()
.unique();
t.string('username')
.unique()
.notNullable();
t.string('password')
.notNullable();
});
}
});
}
function buildPortfolioTable(table) {
return knex.schema.hasTable(table).then(function(exists) {
if (!exists) {
return knex.schema.createTable(table, function(t) {
t.
})
}
})
}
rl.setPrompt('» ');
function insertUser(user, pass) {
return knex('test_user').insert({
username: user,
password: pass
}).then(function(data) {
rl.prompt();
});
}
function createNewUser() {
rl.question('Username » ', function(username) {
rl.question('Password » ', function(password) {
console.log(username, password);
insertUser(username, password);
rl.prompt();
});
});
}
rl.question('Are you a new user? ', function(answer) {
if (answer.match(/^y(es)?$/i)) {
createNewUser();
} else {
rl.prompt();
}
});
rl.on('line', function(line) {
console.log(line);
rl.prompt();
});
app.listen(6446);