Update seed and authentication with salt

This commit is contained in:
ruihildt 2019-08-01 17:42:18 +02:00
parent 03a9c793d8
commit 165d376294
5 changed files with 36 additions and 32 deletions

View File

@ -41,23 +41,23 @@ Sleep Tracker is intended for anyone interested in improving their sleep and hea
| field | data type | metadata |
| :------------- | :--------------- | :-------------------------------------------------- |
| id | unsigned integer | primary key, auto-increments, generated by database |
| session_user | unsigned integer | foreign key referencing `sessions.user_id` |
| session_date | unsigned integer | foreign key referencing `sessions.wake_time` |
| session_id | unsigned integer | foreign key referencing `sessions.id` |
| user_id | unsigned integer | foreign key referencing `users.id` |
| sleep_duration | unsigned integer | |
| average_mood | float | |
## API Endpoints
- [x] `POST /api/auth/register` - add a new user
- [x] `POST /api/auth/login` - login with user/password
- `POST /api/auth/register` - add a new user
- `POST /api/auth/login` - login with user/password
- [x] `GET /api/users/:id` - fetch a user
- [x] `PUT /api/users/:id` - update a user
- [x] `DELETE /api/users/:id` - delete a user
- `GET /api/users/:id` - fetch a user
- `PUT /api/users/:id` - update a user
- `DELETE /api/users/:id` - delete a user
- [x] `GET /api/users/:id/sessions` - fetch list of all sessions by user id
- [x] `POST /api/users/sessions` - add a session
- [x] `PUT /api/users/sessions/:id` - update a session by id
- [x] `DELETE /api/users/sessions/:id` - delete a session by id
- `GET /api/users/:id/sessions` - fetch list of all sessions by user id
- `POST /api/users/sessions` - add a session
- `PUT /api/users/sessions/:id` - update a session by id
- `DELETE /api/users/sessions/:id` - delete a session by id
- [ ] `GET /api/dailyaverages/:id` - fetch a list of last 30 daily averages by user id
- `GET /api/users/:id/dailyaverages` - fetch a list of last 30 daily averages by user id

22
data/seeds/01-addUsers.js Normal file
View File

@ -0,0 +1,22 @@
require("dotenv").config();
const bcrypt = require('bcryptjs');
exports.seed = function(knex) {
return knex('users').truncate()
.then(function () {
return knex('users').insert([
{
id: 1,
email: 'gabe@ls.com',
username: 'gabe',
password: bcrypt.hashSync('1234', process.env.SECRET, 10)
},
{
id: 2,
email: 'gabe2@ls.com',
username: 'gabe2',
password: bcrypt.hashSync('1234', process.env.SECRET, 10)
}
]);
});
};

View File

@ -1,19 +0,0 @@
exports.seed = function(knex) {
return knex('users').truncate()
.then(function () {
return knex('users').insert([
// {
// id: 1,
// email: 'gabe@ls.com',
// username: 'gabe',
// password: '1234'
// },
// {
// id: 2,
// email: 'gabe2@ls.com',
// username: 'gabe2',
// password: '1234'
// }
]);
});
};

Binary file not shown.

View File

@ -1,3 +1,4 @@
require("dotenv").config();
const router = require('express').Router();
const bcrypt = require('bcryptjs');
@ -6,7 +7,7 @@ const Users = require('../users/usersModel');
router.post('/register', (req, res) => {
let user = req.body;
const hash = bcrypt.hashSync(user.password, 10);
const hash = bcrypt.hashSync(user.password, process.env.SECRET, 10);
user.password = hash;
Users.addUser(user)