Skip to content

Commit f54e8cd

Browse files
committed
Corrected some ESLint issues. Reworked some default settings (mainly for testing). Started adding Mocha / Chai testing with "Fixted" v3 functionality. Fixed license in package.json.
1 parent 61b77c8 commit f54e8cd

File tree

19 files changed

+784
-56
lines changed

19 files changed

+784
-56
lines changed

.eslintrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
// or could use some advice, come by https://sailsjs.com/support.
2323
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2424

25+
"settings": {
26+
"react": {
27+
"version": "detect"
28+
}
29+
},
2530
"env": {
2631
"node": true,
2732
"es6": true

.mocharc.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
bail: false #stop on first error
2+
async-only: true
3+
require:
4+
- 'test/hooks.js'
5+
spec: 'test/**/*.test.js'
6+
timeout: 5000

api/helpers/finalize-request-log.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ module.exports = {
4646
}
4747

4848
if (out.access_token) {
49+
// eslint-disable-next-line camelcase
4950
out.access_token = bleep;
5051
}
5152

5253
if (out.refresh_token) {
54+
// eslint-disable-next-line camelcase
5355
out.refresh_token = bleep;
5456
}
5557
}

api/helpers/is-email.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
},
1818

1919
fn: function(inputs, exits){
20+
// eslint-disable-next-line no-useless-escape
2021
const emailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
2122

2223
return exits.success(emailRegex.test(inputs.email));

api/models/Session.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ module.exports = {
1313
required: true
1414
},
1515

16-
16+
data: {
17+
type: 'json'
18+
},
1719

1820
createdAt: {
1921
type: 'ref',

api/models/User.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,14 @@ async function hashPassword(pass) {
77
return hash.toString('base64');
88
}
99

10-
function updatePassword(user, next) {
10+
async function updatePassword(password) {
1111
// "binary to ASCII" aka base64
1212
// btoa('scrypt') = c2NyeXB0
13-
if (user.password && user.password.length > 1 && user.password.substr(0, 8) !== 'c2NyeXB0') {
14-
return hashPassword(user.password).then((hash) => {
15-
user.password = hash;
16-
17-
return next();
18-
});
13+
if (password && password.length > 1 && password.substr(0, 8) !== 'c2NyeXB0') {
14+
password = await hashPassword(password);
1915
}
2016

21-
return next();
17+
return password;
2218
}
2319

2420
module.exports = {
@@ -68,7 +64,7 @@ module.exports = {
6864
columnType: 'varchar(191)',
6965
// see: https://sailsjs.com/documentation/reference/waterline-orm/queries/decrypt
7066
// You will need to "decrypt" the user object before you can check if the password is valid.
71-
encrypt: true
67+
// encrypt: true // currently, does not work as intended, as password is encrypted before we can hash it
7268
},
7369

7470
verificationKey: {
@@ -118,7 +114,6 @@ module.exports = {
118114
return _.omit(this, [
119115
'password',
120116
'verificationKey',
121-
'email',
122117
'deletedAt',
123118
'deletedBy'
124119
]);
@@ -134,26 +129,34 @@ module.exports = {
134129
return scrypt.verify(hashBuffer, raw).then((isAMatch) => isAMatch);
135130
},
136131

137-
beforeCreate: (user, next) => {
132+
beforeCreate: async function(user, next) {
138133
const email = user.email.toLowerCase().trim();
139134

135+
console.log(user.password);
136+
140137
user.email = email;
141138
user.avatar = 'https://www.gravatar.com/avatar/' + md5(email);
142-
user.firstName = user.firstName.charAt(0).toUpperCase() + user.firstName.slice(1).trim();
143-
user.lastName = user.lastName.charAt(0).toUpperCase() + user.lastName.slice(1).trim();
139+
user.firstName = user.firstName.trim().charAt(0).toUpperCase() + user.firstName.slice(1).trim();
140+
user.lastName = user.lastName.trim().charAt(0).toUpperCase() + user.lastName.slice(1).trim();
144141
user.id = sails.helpers.generateUuid();
145142

146-
return updatePassword(user, next);
143+
user.password = await updatePassword(user.password);
144+
145+
return next();
147146
},
148147

149-
beforeUpdate: (user, next) => {
148+
beforeUpdate: async function(user, next) {
150149
const email = user.email.toLowerCase().trim();
151150

152151
user.email = email;
153152
user.avatar = 'https://www.gravatar.com/avatar/' + md5(email);
154-
user.firstName = user.firstName.charAt(0).toUpperCase() + user.firstName.slice(1).trim();
155-
user.lastName = user.lastName.charAt(0).toUpperCase() + user.lastName.slice(1).trim();
153+
user.firstName = user.firstName.trim().charAt(0).toUpperCase() + user.firstName.slice(1).trim();
154+
user.lastName = user.lastName.trim().charAt(0).toUpperCase() + user.lastName.slice(1).trim();
155+
156+
if (user.password) {
157+
user.password = await updatePassword(user.password);
158+
}
156159

157-
return updatePassword(user, next);
160+
return next();
158161
}
159162
};

config/custom.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010

1111
module.exports.custom = {
1212

13-
/***************************************************************************
14-
* *
15-
* Any other custom config this Sails app should use during development. *
16-
* *
17-
***************************************************************************/
18-
// mailgunDomain: 'transactional-mail.example.com',
19-
// mailgunSecret: 'key-testkeyb183848139913858e8abd9a3',
20-
// stripeSecret: 'sk_test_Zzd814nldl91104qor5911gjald',
21-
// …
13+
/***************************************************************************
14+
* *
15+
* Any other custom config this Sails app should use during development. *
16+
* *
17+
***************************************************************************/
18+
// mailgunDomain: 'transactional-mail.example.com',
19+
// mailgunSecret: 'key-testkeyb183848139913858e8abd9a3',
20+
// stripeSecret: 'sk_test_Zzd814nldl91104qor5911gjald',
21+
// …
2222

2323
};

config/datastores.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ module.exports.datastores = {
5151
adapter: 'sails-mysql',
5252
// url: 'mysql://user:password@host:port/database',
5353

54+
host: process.env.DB_HOST || 'localhost',
55+
user: process.env.DB_USER || 'root',
56+
password: process.env.DB_PASS || 'mypass',
57+
database: process.env.DB || 'myapp',
58+
port: process.env.DB_PORT || 3306,
59+
charset: 'utf8mb4',
60+
collation: 'utf8mb4_general_ci',
61+
timezone: 'UTC'
5462
}
5563

5664

config/env/production.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ module.exports = {
5050
* *
5151
***************************************************************************/
5252
default: {
53-
adapter: 'sails-mysql',
5453
host: process.env.RDS_HOSTNAME || 'localhost',
5554
user: process.env.RDS_USERNAME || 'produser',
5655
password: process.env.RDS_PASSWORD || 'myprodpassword',

config/local.js.sample

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ module.exports = {
2020

2121
datastores: {
2222
default: {
23-
adapter: 'sails-mysql',
2423
host: 'localhost',
2524
user: 'root',
2625
password: 'my@w3s0m3password',

config/models.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module.exports.models = {
3535
* *
3636
***************************************************************************/
3737

38-
// schema: true,
38+
schema: true,
3939

4040

4141
/***************************************************************************

config/views.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,26 @@
1616

1717
module.exports.views = {
1818

19-
/***************************************************************************
20-
* *
21-
* Extension to use for your views. When calling `res.view()` in an action, *
22-
* you can leave this extension off. For example, calling *
23-
* `res.view('homepage')` will (using default settings) look for a *
24-
* `views/homepage.ejs` file. *
25-
* *
26-
***************************************************************************/
19+
/***************************************************************************
20+
* *
21+
* Extension to use for your views. When calling `res.view()` in an action, *
22+
* you can leave this extension off. For example, calling *
23+
* `res.view('homepage')` will (using default settings) look for a *
24+
* `views/homepage.ejs` file. *
25+
* *
26+
***************************************************************************/
2727

28-
// extension: 'ejs',
28+
// extension: 'ejs',
2929

30-
/***************************************************************************
31-
* *
32-
* The path (relative to the views directory, and without extension) to *
33-
* the default layout file to use, or `false` to disable layouts entirely. *
34-
* *
35-
* Note that layouts only work with the built-in EJS view engine! *
36-
* *
37-
***************************************************************************/
30+
/***************************************************************************
31+
* *
32+
* The path (relative to the views directory, and without extension) to *
33+
* the default layout file to use, or `false` to disable layouts entirely. *
34+
* *
35+
* Note that layouts only work with the built-in EJS view engine! *
36+
* *
37+
***************************************************************************/
3838

39-
layout: 'layouts/layout'
39+
layout: 'layouts/layout'
4040

4141
};

0 commit comments

Comments
 (0)