aboutsummaryrefslogtreecommitdiff
path: root/src/index.js
diff options
context:
space:
mode:
authorMark Powers <markppowers0@gmail.com>2019-02-02 10:51:10 -0500
committerMark Powers <markppowers0@gmail.com>2019-02-02 10:51:10 -0500
commitc21eba4246be5c9831705a86592b45c70648c167 (patch)
tree0e4470f574ab77287a1ad40f196b1643dd0b1c7d /src/index.js
parentd1162d1bd12cbb3eae9889768adbbb293852c066 (diff)
Add admin panel
Diffstat (limited to 'src/index.js')
-rw-r--r--src/index.js28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/index.js b/src/index.js
index b47824a..925a166 100644
--- a/src/index.js
+++ b/src/index.js
@@ -2,8 +2,21 @@ const server = require('./server');
const Sequelize = require('sequelize');
const fs = require('fs');
const path = require('path');
+const jwt = require('jsonwebtoken');
-const dbCreds = JSON.parse(fs.readFileSync(path.join(__dirname, 'config.json'))).database;
+const config = JSON.parse(fs.readFileSync(path.join(__dirname, 'config.json')));
+
+const dbCreds = config.database;
+const secret = config.jwt_secret;
+
+const jwtFunctions = {
+ sign: function(message) {
+ return jwt.sign({ value: message }, secret);
+ },
+ verify: function(token) {
+ return jwt.verify(token, secret).value;
+ }
+}
const database = new Sequelize(dbCreds.database, dbCreds.user, dbCreds.password, {
logging(str) {
@@ -43,7 +56,16 @@ function setUpModels(){
},}),
"pictures": database.define('pictures', {
source: { type: Sequelize.TEXT, allowNull: false},
- })
+ }),
+ "users": database.define('user', {
+ username: {
+ type: Sequelize.STRING,
+ allowNull: false,
+ },
+ password: {
+ type: Sequelize.STRING,
+ allowNull: false,
+ },})
}
models.pictures.belongsTo(models.posts);
return models;
@@ -52,6 +74,6 @@ function setUpModels(){
const models = setUpModels();
sync();
-server.setUpRoutes(models);
+server.setUpRoutes(models, jwtFunctions);
server.listen();