File knexfile.js changed (mode: 100644) (index eedc12e..145f803) |
1 |
1 |
const path = require('path'); |
const path = require('path'); |
2 |
2 |
|
|
3 |
|
const BASE_PATH = path.join(__dirname, 'src', 'server', 'db'); |
|
|
3 |
|
const BASE_PATH = path.join(__dirname, 'server', 'db'); |
4 |
4 |
|
|
5 |
5 |
module.exports = { |
module.exports = { |
6 |
6 |
test: { |
test: { |
7 |
7 |
client: 'pg', |
client: 'pg', |
8 |
|
connection: 'postgres://localhost:5432/tv_api_test', |
|
|
8 |
|
connection: 'postgres://bitvice:response@localhost:5432/taskViceTest', |
9 |
9 |
migrations: { |
migrations: { |
10 |
10 |
directory: path.join(BASE_PATH, 'migrations') |
directory: path.join(BASE_PATH, 'migrations') |
11 |
11 |
}, |
}, |
|
... |
... |
module.exports = { |
15 |
15 |
}, |
}, |
16 |
16 |
development: { |
development: { |
17 |
17 |
client: 'pg', |
client: 'pg', |
18 |
|
connection: 'postgres://localhost:5432/tv_api', |
|
|
18 |
|
connection: 'postgres://bitvice:response@localhost:5432/taskVice', |
19 |
19 |
migrations: { |
migrations: { |
20 |
20 |
directory: path.join(BASE_PATH, 'migrations') |
directory: path.join(BASE_PATH, 'migrations') |
21 |
21 |
}, |
}, |
File package.json changed (mode: 100644) (index e97c812..ab93ac2) |
1 |
1 |
{ |
{ |
2 |
|
"name": "task-vice", |
|
3 |
|
"version": "1.0.0", |
|
4 |
|
"description": "Simple task manager", |
|
5 |
|
"main": "index.js", |
|
6 |
|
"scripts": { |
|
7 |
|
"start": "node ./server/index.js", |
|
8 |
|
"test": "./node_modules/mocha/bin/_mocha ./test/**/*.test.js" |
|
9 |
|
}, |
|
10 |
|
"devDependencies": { |
|
11 |
|
"chai": "4.1.1", |
|
12 |
|
"chai-http": "^3.0.0", |
|
13 |
|
"mocha": "3.5.0", |
|
14 |
|
"sinon": "^4.1.5" |
|
15 |
|
}, |
|
16 |
|
"dependencies": { |
|
17 |
|
"bcryptjs": "^2.4.3", |
|
18 |
|
"knex": "^0.13.0", |
|
19 |
|
"koa": "^2.3.0", |
|
20 |
|
"koa-bodyparser": "^4.2.0", |
|
21 |
|
"koa-passport": "^4.0.1", |
|
22 |
|
"koa-redis": "^3.1.1", |
|
23 |
|
"koa-router": "^7.2.1", |
|
24 |
|
"koa-session": "^5.5.1", |
|
25 |
|
"passport-local": "^1.0.0", |
|
26 |
|
"pg": "^7.1.2" |
|
27 |
|
}, |
|
28 |
|
"repository": { |
|
29 |
|
"type": "git", |
|
30 |
|
"url": "https://rocketgit.com/user/bitvice/TaskVice" |
|
31 |
|
}, |
|
32 |
|
"keywords": ["tasks","manager"], |
|
33 |
|
"author": "bitvice", |
|
34 |
|
"license": "MIT" |
|
|
2 |
|
"name": "task-vice", |
|
3 |
|
"version": "1.0.0", |
|
4 |
|
"description": "Simple task manager", |
|
5 |
|
"main": "index.js", |
|
6 |
|
"scripts": { |
|
7 |
|
"start": "node ./server/index.js", |
|
8 |
|
"test": "./node_modules/mocha/bin/_mocha ./test/**/*.test.js" |
|
9 |
|
}, |
|
10 |
|
"devDependencies": { |
|
11 |
|
"chai": "4.1.1", |
|
12 |
|
"chai-http": "^3.0.0", |
|
13 |
|
"mocha": "3.5.0", |
|
14 |
|
"sinon": "^4.1.5" |
|
15 |
|
}, |
|
16 |
|
"dependencies": { |
|
17 |
|
"bcryptjs": "^2.4.3", |
|
18 |
|
"knex": "^0.13.0", |
|
19 |
|
"koa": "^2.3.0", |
|
20 |
|
"koa-bodyparser": "^4.2.0", |
|
21 |
|
"koa-passport": "^4.0.1", |
|
22 |
|
"koa-redis": "^3.1.1", |
|
23 |
|
"koa-router": "^7.2.1", |
|
24 |
|
"koa-session": "^5.5.1", |
|
25 |
|
"passport-local": "^1.0.0", |
|
26 |
|
"pg": "^7.1.2" |
|
27 |
|
}, |
|
28 |
|
"repository": { |
|
29 |
|
"type": "git", |
|
30 |
|
"url": "https://rocketgit.com/user/bitvice/TaskVice" |
|
31 |
|
}, |
|
32 |
|
"keywords": [ |
|
33 |
|
"tasks", |
|
34 |
|
"manager" |
|
35 |
|
], |
|
36 |
|
"author": "bitvice", |
|
37 |
|
"license": "MIT" |
35 |
38 |
} |
} |
File server/db/migrations/20171231115201_users.js added (mode: 100644) (index 0000000..02a500f) |
|
1 |
|
|
|
2 |
|
exports.up = (knex, Promise) => { |
|
3 |
|
return knex.schema.createTable('users', (table) => { |
|
4 |
|
table.increments(); |
|
5 |
|
table.string('username').unique().notNullable(); |
|
6 |
|
table.string('password').notNullable(); |
|
7 |
|
table.boolean('admin').notNullable().defaultTo(false); |
|
8 |
|
}); |
|
9 |
|
}; |
|
10 |
|
|
|
11 |
|
|
|
12 |
|
exports.down = (knex, Promise) => { |
|
13 |
|
return knex.schema.dropTable('users'); |
|
14 |
|
}; |
File server/routes/auth.js changed (mode: 100644) (index 0153797..6e4ecb0) |
... |
... |
const router = new Router(); |
9 |
9 |
|
|
10 |
10 |
router.get('/auth/register', async (ctx) => { |
router.get('/auth/register', async (ctx) => { |
11 |
11 |
ctx.type = 'html'; |
ctx.type = 'html'; |
12 |
|
ctx.body = fs.createReadStream('./src/server/views/register.html'); |
|
|
12 |
|
ctx.body = fs.createReadStream('./server/views/register.html'); |
13 |
13 |
}); |
}); |
14 |
14 |
|
|
15 |
15 |
router.post('/auth/register', async (ctx) => { |
router.post('/auth/register', async (ctx) => { |
|
... |
... |
router.post('/auth/register', async (ctx) => { |
28 |
28 |
router.get('/auth/login', async (ctx) => { |
router.get('/auth/login', async (ctx) => { |
29 |
29 |
if (!helpers.ensureAuthenticated(ctx)) { |
if (!helpers.ensureAuthenticated(ctx)) { |
30 |
30 |
ctx.type = 'html'; |
ctx.type = 'html'; |
31 |
|
ctx.body = fs.createReadStream('./src/server/views/login.html'); |
|
|
31 |
|
ctx.body = fs.createReadStream('./server/views/login.html'); |
32 |
32 |
} else { |
} else { |
33 |
33 |
ctx.redirect('/auth/status'); |
ctx.redirect('/auth/status'); |
34 |
34 |
} |
} |
|
... |
... |
router.get('/auth/logout', async (ctx) => { |
59 |
59 |
router.get('/auth/status', async (ctx) => { |
router.get('/auth/status', async (ctx) => { |
60 |
60 |
if (helpers.ensureAuthenticated(ctx)) { |
if (helpers.ensureAuthenticated(ctx)) { |
61 |
61 |
ctx.type = 'html'; |
ctx.type = 'html'; |
62 |
|
ctx.body = fs.createReadStream('./src/server/views/status.html'); |
|
|
62 |
|
ctx.body = fs.createReadStream('./server/views/status.html'); |
63 |
63 |
} else { |
} else { |
64 |
64 |
ctx.redirect('/auth/login'); |
ctx.redirect('/auth/login'); |
65 |
65 |
} |
} |
|
... |
... |
router.get('/auth/status', async (ctx) => { |
68 |
68 |
router.get('/auth/admin', async (ctx) => { |
router.get('/auth/admin', async (ctx) => { |
69 |
69 |
if (await helpers.ensureAdmin(ctx)) { |
if (await helpers.ensureAdmin(ctx)) { |
70 |
70 |
ctx.type = 'html'; |
ctx.type = 'html'; |
71 |
|
ctx.body = fs.createReadStream('./src/server/views/admin.html'); |
|
|
71 |
|
ctx.body = fs.createReadStream('./server/views/admin.html'); |
72 |
72 |
} else { |
} else { |
73 |
73 |
ctx.redirect('/auth/login'); |
ctx.redirect('/auth/login'); |
74 |
74 |
} |
} |
File test/integration/routes.auth.stub.test.js changed (mode: 100644) (index d313eec..20f70e9) |
... |
... |
const chaiHttp = require('chai-http'); |
7 |
7 |
const sinon = require('sinon'); |
const sinon = require('sinon'); |
8 |
8 |
chai.use(chaiHttp); |
chai.use(chaiHttp); |
9 |
9 |
|
|
10 |
|
const server = require('../..//server/index'); |
|
11 |
|
const knex = require('../..//server/db/connection'); |
|
12 |
|
const queries = require('../..//server/db/queries/users'); |
|
13 |
|
const store = require('../..//server/session'); |
|
14 |
|
const helpers = require('../..//server/routes/_helpers'); |
|
|
10 |
|
const server = require('../../server/index'); |
|
11 |
|
const knex = require('../../server/db/connection'); |
|
12 |
|
const queries = require('../../server/db/queries/users'); |
|
13 |
|
const store = require('../../server/session'); |
|
14 |
|
const helpers = require('../../server/routes/_helpers'); |
15 |
15 |
|
|
16 |
16 |
describe('routes : auth - stubbed', () => { |
describe('routes : auth - stubbed', () => { |
17 |
17 |
|
|