Skip to content

Commit be8fc13

Browse files
committed
Built out PnwedPasswords.com API functionality into is-password-valid helper. FINALLY removed the usage of res._headers, so no more annoying deprecation message. Simplified stored session data.
1 parent 7cd19df commit be8fc13

File tree

77 files changed

+1142
-469
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1142
-469
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## [v3.1.2](https://github.com/neonexus/sails-react-bootstrap-webpack/compare/v3.1.1...v3.1.2) (2022-10-24)
4+
5+
### Features
6+
7+
* Built out PnwedPasswords.com (HaveIBeenPwned.com) API functionality into `is-password-valid` helper.
8+
* FINALLY removed the usage of `res._headers`, so no more annoying deprecation message.
9+
* Simplified stored session data.
10+
311
## [v3.1.1](https://github.com/neonexus/sails-react-bootstrap-webpack/compare/v3.1.0...v3.1.1) (2022-09-08)
412

513
### Features

README.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ Need help? Want to hire me to build your next app or prototype? You can contact
88

99
## Main Features
1010

11-
+ Automatic (incoming) request logging (manual outgoing), via Sails models / hooks.
12-
+ Setup for Webpack auto-reload dev server.
13-
+ Setup so Sails will serve Webpack-built bundles as separate apps (so, a marketing site, and an admin site can live side-by-side).
14-
+ Includes [react-bootstrap](https://www.npmjs.com/package/react-bootstrap) to make using Bootstrap styles / features with React easier.
15-
+ Schema validation and enforcement for `PRODUCTION`. This repo is set up for `MySQL`. If you plan to use a different datastore, you will likely want to disable the schema validation and enforcement feature inside [`config/bootstrap.js`](config/bootstrap.js). See [schema validation and enforcement](#schema-validation-and-enforcement) for more info.
11+
* Automatic (incoming) request logging (manual outgoing), via Sails models / hooks.
12+
* Setup for Webpack auto-reload dev server.
13+
* Setup so Sails will serve Webpack-built bundles as separate apps (so, a marketing site, and an admin site can live side-by-side).
14+
* Includes [react-bootstrap](https://www.npmjs.com/package/react-bootstrap) to make using Bootstrap styles / features with React easier.
15+
* Schema validation and enforcement for `PRODUCTION`. This repo is set up for `MySQL`. If you plan to use a different datastore, you will likely want to disable the schema validation and enforcement feature inside [`config/bootstrap.js`](config/bootstrap.js). See [schema validation and enforcement](#schema-validation-and-enforcement) for more info.
16+
* Can enforce password creation isn't found in [PwnedPasswords]()
1617

1718
## Branch Warning
1819
The `master` branch is experimental, and the [release branch](https://github.com/neonexus/sails-react-bootstrap-webpack/tree/release) (or the [`releases section`](https://github.com/neonexus/sails-react-bootstrap-webpack/releases)) is where one should base their use of this template.
@@ -70,10 +71,10 @@ If you DO NOT like this behavior, and would prefer the variables stay the same a
7071
|-------------------------------------------------------------------------|-----------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------|
7172
| ASSETS_URL | "" (empty string) | Webpack is configured to modify static asset URLs to point to a CDN, like CloudFront. MUST end with a slash " / ", or be empty. |
7273
| BASE_URL | https://myapi.app | The address of the Sails instance. |
73-
| **DEV:**&nbsp;&nbsp;&nbsp;&nbsp;DB_HOST<br />**PROD:**&nbsp;DB_HOSTNAME | localhost | The hostname of the datastore. |
74-
| **DEV:**&nbsp;&nbsp;&nbsp;&nbsp;DB_USER<br />**PROD:**&nbsp;DB_USERNAME | **DEV:**&nbsp;&nbsp;&nbsp;&nbsp;root <br /> **PROD:**&nbsp;produser | Username of the datastore. |
75-
| **DEV:**&nbsp;&nbsp;&nbsp;&nbsp;DB_PASS<br />**PROD:**&nbsp;DB_PASSWORD | **DEV:**&nbsp;&nbsp;&nbsp;&nbsp;mypass <br /> **PROD:**&nbsp;prodpass | Password of the datastore. |
76-
| DB_NAME | **DEV:**&nbsp;&nbsp;&nbsp;&nbsp;myapp <br /> **PROD:**&nbsp;prod | The name of the database inside the datastore. |
74+
| &nbsp;&nbsp;&nbsp;**DEV:**&nbsp;DB_HOST<br />**PROD:**&nbsp;DB_HOSTNAME | localhost | The hostname of the datastore. |
75+
| &nbsp;&nbsp;&nbsp;**DEV:**&nbsp;DB_USER<br />**PROD:**&nbsp;DB_USERNAME | &nbsp;&nbsp;&nbsp;**DEV:**&nbsp;root <br /> **PROD:**&nbsp;produser | Username of the datastore. |
76+
| &nbsp;&nbsp;&nbsp;**DEV:**&nbsp;DB_PASS<br />**PROD:**&nbsp;DB_PASSWORD | &nbsp;&nbsp;&nbsp;**DEV:**&nbsp;mypass <br /> **PROD:**&nbsp;prodpass | Password of the datastore. |
77+
| DB_NAME | &nbsp;&nbsp;&nbsp;**DEV:**&nbsp;myapp <br /> **PROD:**&nbsp;prod | The name of the database inside the datastore. |
7778
| DB_PORT | 3306 | The port number for the datastore. |
7879
| DB_SSL | true | If the datastore requires SSL, set this to "true". |
7980
| SESSION_SECRET | "" (empty string) | Used to sign cookies, and SHOULD be set, especially on PRODUCTION environments. |
@@ -142,13 +143,13 @@ middleware: {
142143

143144
### Useful Links
144145

145-
+ [Sails Framework Documentation](https://sailsjs.com/get-started)
146-
+ [Sails Deployment Tips](https://sailsjs.com/documentation/concepts/deployment)
147-
+ [Sails Community Support Options](https://sailsjs.com/support)
148-
+ [Sails Professional / Enterprise Options](https://sailsjs.com/enterprise)
149-
+ [`react-bootstrap` Documentation](https://react-bootstrap.netlify.app/)
150-
+ [Webpack Documentation](https://webpack.js.org/)
151-
+ [Simple data fixtures for testing Sails.js (the npm package `fixted`)](https://www.npmjs.com/package/fixted)
146+
* [Sails Framework Documentation](https://sailsjs.com/get-started)
147+
* [Sails Deployment Tips](https://sailsjs.com/documentation/concepts/deployment)
148+
* [Sails Community Support Options](https://sailsjs.com/support)
149+
* [Sails Professional / Enterprise Options](https://sailsjs.com/enterprise)
150+
* [`react-bootstrap` Documentation](https://react-bootstrap.netlify.app/)
151+
* [Webpack Documentation](https://webpack.js.org/)
152+
* [Simple data fixtures for testing Sails.js (the npm package `fixted`)](https://www.npmjs.com/package/fixted)
152153

153154

154155
### Version info

api/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ See: [Actions and Controllers](https://sailsjs.com/documentation/concepts/action
1010

1111
## Helpers
1212

13-
Helpers are generic, reusable functions used by multiple controllers (or hooks, policies, etc).
13+
Helpers are generic, reusable functions that can be used by controllers, hooks, models, policies, or responses.
1414

1515
See: [Helpers](https://sailsjs.com/documentation/concepts/helpers)
1616

api/controllers/admin/create-user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ module.exports = {
6060
let isPasswordValid;
6161

6262
if (inputs.setPassword) {
63-
isPasswordValid = sails.helpers.isPasswordValid.with({
63+
isPasswordValid = await sails.helpers.isPasswordValid.with({
6464
password: inputs.password,
6565
user: {firstName: inputs.firstName, lastName: inputs.lastName, email: inputs.email}
6666
});

api/controllers/admin/delete-user.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ module.exports = {
2626
},
2727

2828
fn: async (inputs, exits, env) => {
29+
if (inputs.id === env.req.session.user.id) {
30+
return exits.badRequest('One does not simply delete themselves...');
31+
}
32+
2933
const foundUser = await sails.models.user.findOne({id: inputs.id, deletedAt: null});
3034

3135
if (!foundUser) {
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
module.exports = {
2+
friendlyName: 'Get Deleted Users',
3+
4+
description: 'Get paginated list of soft-deleted users',
5+
6+
inputs: {
7+
page: {
8+
description: 'The page number to return',
9+
type: 'number',
10+
defaultsTo: 1,
11+
min: 1
12+
},
13+
14+
limit: {
15+
description: 'The amount of users to return',
16+
type: 'number',
17+
defaultsTo: 25,
18+
min: 1,
19+
max: 500
20+
}
21+
},
22+
23+
exits: {
24+
ok: {
25+
responseType: 'ok'
26+
},
27+
badRequest: {
28+
responseType: 'badRequest'
29+
},
30+
serverError: {
31+
responseType: 'serverError'
32+
}
33+
},
34+
35+
fn: async (inputs, exits) => {
36+
const query = sails.helpers.paginateForQuery.with({
37+
limit: inputs.limit,
38+
page: inputs.page,
39+
where: {
40+
deletedAt: {'!=': null} // get all soft-deleted users
41+
},
42+
sort: [{deletedAt: 'ASC'}, {createdAt: 'DESC'}]
43+
});
44+
45+
let out = await sails.helpers.paginateForJson.with({
46+
model: sails.models.user,
47+
objToWrap: {users: []}, // this is the object that will be output to "out", and will contain additional pagination info,
48+
query
49+
});
50+
51+
// We assign the users to the object afterward, so we can run our safety checks.
52+
// Otherwise, if we were to put the users object into "objToWrap", they would be transformed, and the "customToJSON" feature would no longer work, and hashed passwords would leak.
53+
out.users = await sails.models.user.find(_.omit(pagination, ['page'])).populate('deletedBy');
54+
55+
return exits.ok(out);
56+
}
57+
};

api/controllers/admin/get-users.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = {
1515
description: 'The amount of users to return',
1616
type: 'number',
1717
defaultsTo: 25,
18-
min: 10,
18+
min: 1,
1919
max: 500
2020
}
2121
},
@@ -38,8 +38,6 @@ module.exports = {
3838
page: inputs.page
3939
});
4040

41-
const users = await sails.models.user.find(_.omit(pagination, ['page']));
42-
4341
let out = await sails.helpers.paginateForJson.with({
4442
model: sails.models.user,
4543
query: pagination,
@@ -48,7 +46,7 @@ module.exports = {
4846

4947
// We assign the users to the object afterward, so we can run our safety checks.
5048
// Otherwise, if we were to put the users object into "objToWrap", they would be transformed, and the "customToJSON" feature would no longer work, and hashed passwords would leak.
51-
out.users = users;
49+
out.users = await sails.models.user.find(_.omit(pagination, ['page']));
5250

5351
return exits.ok(out);
5452
}

api/controllers/common/login.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ module.exports = {
4242
return exits.badRequest(badEmailPass);
4343
}
4444

45+
await sails.helpers.isPasswordValid(inputs.password);
46+
4547
if (!await sails.models.user.doPasswordsMatch(inputs.password, foundUser.password)) {
4648
return exits.badRequest(badEmailPass);
4749
}
@@ -51,13 +53,6 @@ module.exports = {
5153
id: 'c', // required, auto-generated
5254
user: foundUser.id,
5355
data: {
54-
user: {
55-
id: foundUser.id,
56-
firstName: foundUser.firstName,
57-
lastName: foundUser.lastName,
58-
email: foundUser.email,
59-
role: foundUser.role
60-
},
6156
_csrfSecret: csrf.secret
6257
}
6358
}).fetch();

api/helpers/create-log.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ module.exports = {
2525

2626
fn: function(inputs, exits){
2727
const user = (inputs.req.session && inputs.req.session.user) ? inputs.req.session.user.id : null,
28-
account = (inputs.req.session && inputs.req.session.account) ? inputs.req.session.account.id : null,
2928
request = (inputs.req.requestId) ? inputs.req.requestId : null;
3029

3130
const newLog = {
3231
data: inputs.data,
3332
user,
34-
account,
3533
request,
3634
description: inputs.description
3735
};

api/helpers/finalize-request-log.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module.exports = {
3333
fn: async function(inputs, exits) {
3434
if (inputs.req.requestId) {
3535
let out = _.merge({}, inputs.body),
36-
headers = _.merge({}, inputs.res._headers), // copy the object
36+
headers = _.merge({}, inputs.res.getHeaders()), // copy the object
3737
bleep = '*******';
3838

3939
if (!sails.config.logSensitiveData) { // a custom configuration option, for the request logger hook

0 commit comments

Comments
 (0)