Skip to content

Commit b0225fb

Browse files
author
margot
committed
updates
1 parent e315aad commit b0225fb

27 files changed

+5554
-24458
lines changed

.babelrc

+5-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
{ "presets": [ "react" ] }
1+
{
2+
"presets": [
3+
"@babel/preset-react"
4+
]
5+
}

.env.example

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ APP_URL=http://${HOST}:${PORT}
55

66
CACHE_VIEWS=false
77

8-
APP_KEY=2wsjLSopTjD6WQEztTYIZgCFou8wpLJn
8+
APP_KEY=
99

1010
DB_CONNECTION=sqlite
1111
DB_HOST=127.0.0.1
@@ -15,3 +15,4 @@ DB_PASSWORD=
1515
DB_DATABASE=adonis
1616

1717
SESSION_DRIVER=cookie
18+
HASH_DRIVER=bcrypt

.gitignore

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Node modules
22
node_modules
3+
package-lock.json
34

45
# Adonis directory for storing tmp files
56
tmp
@@ -8,4 +9,12 @@ tmp
89
.env
910

1011
# The development sqlite file
11-
database/development.sqlite
12+
database/*.sqlite
13+
14+
# VSCode & Webstorm history directories
15+
.history
16+
.idea
17+
18+
# webpack output
19+
public/app.css
20+
public/app.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict'
2+
3+
class ConvertEmptyStringsToNull {
4+
async handle ({ request }, next) {
5+
if (Object.keys(request.body).length) {
6+
request.body = Object.assign(
7+
...Object.keys(request.body).map(key => ({
8+
[key]: request.body[key] !== '' ? request.body[key] : null
9+
}))
10+
)
11+
}
12+
13+
await next()
14+
}
15+
}
16+
17+
module.exports = ConvertEmptyStringsToNull

app/Models/Token.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
/** @type {typeof import('@adonisjs/lucid/src/Lucid/Model')} */
34
const Model = use('Model')
45

56
class Token extends Model {

app/Models/Traits/NoTimestamp.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict'
2+
3+
class NoTimestamp {
4+
register (Model) {
5+
Object.defineProperties(Model, {
6+
createdAtColumn: {
7+
get: () => null,
8+
},
9+
updatedAtColumn: {
10+
get: () => null,
11+
},
12+
})
13+
}
14+
}
15+
16+
module.exports = NoTimestamp

app/Models/User.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
'use strict'
22

3+
/** @type {import('@adonisjs/framework/src/Hash')} */
34
const Hash = use('Hash')
5+
6+
/** @type {typeof import('@adonisjs/lucid/src/Lucid/Model')} */
47
const Model = use('Model')
58

69
class User extends Model {
@@ -11,8 +14,8 @@ class User extends Model {
1114
* A hook to hash the user password before saving
1215
* it to the database.
1316
*/
14-
this.addHook('beforeCreate', async (userInstance) => {
15-
if (userInstance.password) {
17+
this.addHook('beforeSave', async (userInstance) => {
18+
if (userInstance.dirty.password) {
1619
userInstance.password = await Hash.make(userInstance.password)
1720
}
1821
})

config/app.js

+41-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
'use strict'
22

3+
/** @type {import('@adonisjs/framework/src/Env')} */
34
const Env = use('Env')
45

56
module.exports = {
7+
8+
/*
9+
|--------------------------------------------------------------------------
10+
| Application Name
11+
|--------------------------------------------------------------------------
12+
|
13+
| This value is the name of your application and can be used when you
14+
| need to place the application's name in a email, view or
15+
| other location.
16+
|
17+
*/
18+
19+
name: Env.get('APP_NAME', 'AdonisJs'),
20+
621
/*
722
|--------------------------------------------------------------------------
823
| App Key
@@ -12,15 +27,15 @@ module.exports = {
1227
| to encrypted cookies, sessions and other sensitive data.
1328
|
1429
*/
15-
appKey: Env.get('APP_KEY'),
30+
appKey: Env.getOrFail('APP_KEY'),
1631

1732
http: {
1833
/*
1934
|--------------------------------------------------------------------------
2035
| Allow Method Spoofing
2136
|--------------------------------------------------------------------------
2237
|
23-
| Method spoofing allows to make requests by spoofing the http verb.
38+
| Method spoofing allows you to make requests by spoofing the http verb.
2439
| Which means you can make a GET request but instruct the server to
2540
| treat as a POST or PUT request. If you want this feature, set the
2641
| below value to true.
@@ -33,10 +48,10 @@ module.exports = {
3348
| Trust Proxy
3449
|--------------------------------------------------------------------------
3550
|
36-
| Trust proxy defines whether X-Forwaded-* headers should be trusted or not.
51+
| Trust proxy defines whether X-Forwarded-* headers should be trusted or not.
3752
| When your application is behind a proxy server like nginx, these values
3853
| are set automatically and should be trusted. Apart from setting it
39-
| to true or false Adonis supports handful or ways to allow proxy
54+
| to true or false Adonis supports a handful of ways to allow proxy
4055
| values. Read documentation for that.
4156
|
4257
*/
@@ -47,7 +62,7 @@ module.exports = {
4762
| Subdomains
4863
|--------------------------------------------------------------------------
4964
|
50-
| Offset to be used for returning subdomains for a given request.For
65+
| Offset to be used for returning subdomains for a given request. For
5166
| majority of applications it will be 2, until you have nested
5267
| sudomains.
5368
| cheatsheet.adonisjs.com - offset - 2
@@ -67,12 +82,13 @@ module.exports = {
6782
*/
6883
jsonpCallback: 'callback',
6984

85+
7086
/*
7187
|--------------------------------------------------------------------------
7288
| Etag
7389
|--------------------------------------------------------------------------
7490
|
75-
| Set etag on all HTTP response. In order to disable for selected routes,
91+
| Set etag on all HTTP responses. In order to disable for selected routes,
7692
| you can call the `response.send` with an options object as follows.
7793
|
7894
| response.send('Hello', { ignoreEtag: true })
@@ -100,9 +116,9 @@ module.exports = {
100116
| Dot Files
101117
|--------------------------------------------------------------------------
102118
|
103-
| Define how to treat dot files when trying to server static resources.
119+
| Define how to treat dot files when trying to serve static resources.
104120
| By default it is set to ignore, which will pretend that dotfiles
105-
| does not exists.
121+
| do not exist.
106122
|
107123
| Can be one of the following
108124
| ignore, deny, allow
@@ -206,5 +222,22 @@ module.exports = {
206222
filename: 'adonis.log',
207223
level: 'info'
208224
}
225+
},
226+
227+
/*
228+
|--------------------------------------------------------------------------
229+
| Generic Cookie Options
230+
|--------------------------------------------------------------------------
231+
|
232+
| The following cookie options are generic settings used by AdonisJs to create
233+
| cookies. However, some parts of the application like `sessions` can have
234+
| seperate settings for cookies inside `config/session.js`.
235+
|
236+
*/
237+
cookie: {
238+
httpOnly: true,
239+
sameSite: false,
240+
path: '/',
241+
maxAge: 7200
209242
}
210243
}

config/auth.js

+17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
/** @type {import('@adonisjs/framework/src/Env')} */
34
const Env = use('Env')
45

56
module.exports = {
@@ -73,5 +74,21 @@ module.exports = {
7374
options: {
7475
secret: Env.get('APP_KEY')
7576
}
77+
},
78+
79+
/*
80+
|--------------------------------------------------------------------------
81+
| Api
82+
|--------------------------------------------------------------------------
83+
|
84+
| The Api scheme makes use of API personal tokens to authenticate a user.
85+
|
86+
*/
87+
api: {
88+
serializer: 'lucid',
89+
model: 'App/Models/User',
90+
scheme: 'api',
91+
uid: 'email',
92+
password: 'password'
7693
}
7794
}

config/cors.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module.exports = {
2929
| Array - An array of allowed methods
3030
|
3131
*/
32-
methods: ['GET', 'PUT', 'POST'],
32+
methods: ['GET', 'PUT', 'PATCH', 'POST', 'DELETE'],
3333

3434
/*
3535
|--------------------------------------------------------------------------

config/database.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
'use strict'
22

3+
/** @type {import('@adonisjs/framework/src/Env')} */
34
const Env = use('Env')
5+
6+
/** @type {import('@adonisjs/ignitor/src/Helpers')} */
47
const Helpers = use('Helpers')
58

69
module.exports = {

config/hash.js

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
'use strict'
2+
3+
/** @type {import('@adonisjs/framework/src/Env')} */
4+
const Env = use('Env')
5+
6+
module.exports = {
7+
/*
8+
|--------------------------------------------------------------------------
9+
| Driver
10+
|--------------------------------------------------------------------------
11+
|
12+
| Driver to be used for hashing values. The same driver is used by the
13+
| auth module too.
14+
|
15+
*/
16+
driver: Env.get('HASH_DRIVER', 'bcrypt'),
17+
18+
/*
19+
|--------------------------------------------------------------------------
20+
| Bcrypt
21+
|--------------------------------------------------------------------------
22+
|
23+
| Config related to bcrypt hashing. https://www.npmjs.com/package/bcrypt
24+
| package is used internally.
25+
|
26+
*/
27+
bcrypt: {
28+
rounds: 10
29+
},
30+
31+
/*
32+
|--------------------------------------------------------------------------
33+
| Argon
34+
|--------------------------------------------------------------------------
35+
|
36+
| Config related to argon. https://www.npmjs.com/package/argon2 package is
37+
| used internally.
38+
|
39+
| Since argon is optional, you will have to install the dependency yourself
40+
|
41+
|============================================================================
42+
| npm i argon2
43+
|============================================================================
44+
|
45+
*/
46+
argon: {
47+
type: 1
48+
}
49+
}

config/session.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
/** @type {import('@adonisjs/framework/src/Env')} */
34
const Env = use('Env')
45

56
module.exports = {
@@ -64,7 +65,7 @@ module.exports = {
6465
*/
6566
cookie: {
6667
httpOnly: true,
67-
sameSite: true,
68+
sameSite: false,
6869
path: '/'
6970
},
7071

@@ -90,5 +91,11 @@ module.exports = {
9091
| the redis file. But you are free to define an object here too.
9192
|
9293
*/
93-
redis: 'self::redis.local'
94+
redis: {
95+
host: '127.0.0.1',
96+
port: 6379,
97+
password: null,
98+
db: 0,
99+
keyPrefix: ''
100+
}
94101
}

config/shield.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ module.exports = {
7272
| X-XSS-Protection
7373
|--------------------------------------------------------------------------
7474
|
75-
| X-XSS Protection saves from applications from XSS attacks. It is adopted
75+
| X-XSS Protection saves applications from XSS attacks. It is adopted
7676
| by IE and later followed by some other browsers.
7777
|
7878
| Learn more at https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection

database/factory.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
|
1212
*/
1313

14+
/** @type {import('@adonisjs/lucid/src/Factory')} */
1415
// const Factory = use('Factory')
1516

16-
/**
17-
Factory.blueprint('App/Models/User', (faker) => {
18-
return {
19-
username: faker.username()
20-
}
21-
})
22-
*/
17+
// Factory.blueprint('App/Models/User', (faker) => {
18+
// return {
19+
// username: faker.username()
20+
// }
21+
// })

database/migrations/1503248427885_user.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
'use strict'
22

3+
/** @type {import('@adonisjs/lucid/src/Schema')} */
34
const Schema = use('Schema')
45

56
class UserSchema extends Schema {
67
up () {
7-
this.create('users', table => {
8+
this.create('users', (table) => {
89
table.increments()
910
table.string('username', 80).notNullable().unique()
1011
table.string('email', 254).notNullable().unique()

0 commit comments

Comments
 (0)