Update seed and authentication with salt
This commit is contained in:
parent
03a9c793d8
commit
165d376294
24
README.md
24
README.md
@ -41,23 +41,23 @@ Sleep Tracker is intended for anyone interested in improving their sleep and hea
|
|||||||
| field | data type | metadata |
|
| field | data type | metadata |
|
||||||
| :------------- | :--------------- | :-------------------------------------------------- |
|
| :------------- | :--------------- | :-------------------------------------------------- |
|
||||||
| id | unsigned integer | primary key, auto-increments, generated by database |
|
| id | unsigned integer | primary key, auto-increments, generated by database |
|
||||||
| session_user | unsigned integer | foreign key referencing `sessions.user_id` |
|
| session_id | unsigned integer | foreign key referencing `sessions.id` |
|
||||||
| session_date | unsigned integer | foreign key referencing `sessions.wake_time` |
|
| user_id | unsigned integer | foreign key referencing `users.id` |
|
||||||
| sleep_duration | unsigned integer | |
|
| sleep_duration | unsigned integer | |
|
||||||
| average_mood | float | |
|
| average_mood | float | |
|
||||||
|
|
||||||
## API Endpoints
|
## API Endpoints
|
||||||
|
|
||||||
- [x] `POST /api/auth/register` - add a new user
|
- `POST /api/auth/register` - add a new user
|
||||||
- [x] `POST /api/auth/login` - login with user/password
|
- `POST /api/auth/login` - login with user/password
|
||||||
|
|
||||||
- [x] `GET /api/users/:id` - fetch a user
|
- `GET /api/users/:id` - fetch a user
|
||||||
- [x] `PUT /api/users/:id` - update a user
|
- `PUT /api/users/:id` - update a user
|
||||||
- [x] `DELETE /api/users/:id` - delete a user
|
- `DELETE /api/users/:id` - delete a user
|
||||||
|
|
||||||
- [x] `GET /api/users/:id/sessions` - fetch list of all sessions by user id
|
- `GET /api/users/:id/sessions` - fetch list of all sessions by user id
|
||||||
- [x] `POST /api/users/sessions` - add a session
|
- `POST /api/users/sessions` - add a session
|
||||||
- [x] `PUT /api/users/sessions/:id` - update a session by id
|
- `PUT /api/users/sessions/:id` - update a session by id
|
||||||
- [x] `DELETE /api/users/sessions/:id` - delete 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
22
data/seeds/01-addUsers.js
Normal 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)
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
};
|
@ -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.
@ -1,3 +1,4 @@
|
|||||||
|
require("dotenv").config();
|
||||||
const router = require('express').Router();
|
const router = require('express').Router();
|
||||||
const bcrypt = require('bcryptjs');
|
const bcrypt = require('bcryptjs');
|
||||||
|
|
||||||
@ -6,7 +7,7 @@ const Users = require('../users/usersModel');
|
|||||||
|
|
||||||
router.post('/register', (req, res) => {
|
router.post('/register', (req, res) => {
|
||||||
let user = req.body;
|
let user = req.body;
|
||||||
const hash = bcrypt.hashSync(user.password, 10);
|
const hash = bcrypt.hashSync(user.password, process.env.SECRET, 10);
|
||||||
user.password = hash;
|
user.password = hash;
|
||||||
|
|
||||||
Users.addUser(user)
|
Users.addUser(user)
|
||||||
|
Loading…
Reference in New Issue
Block a user