-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
1,734 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
'use strict' | ||
|
||
/* | ||
* adonis-session | ||
* | ||
* (c) Harminder Virk <virk@adonisjs.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
const path = require('path') | ||
const { Command } = require('@adonisjs/ace') | ||
|
||
class ConfigSession extends Command { | ||
constructor (Helpers) { | ||
super() | ||
this.Helpers = Helpers | ||
} | ||
/** | ||
* The command signature | ||
* | ||
* @method signature | ||
* | ||
* @return {String} | ||
*/ | ||
static get signature () { | ||
return ` | ||
config:session | ||
{ -e, --echo: Echo session file contents } | ||
` | ||
} | ||
|
||
/** | ||
* The command description | ||
* | ||
* @method description | ||
* | ||
* @return {String} | ||
*/ | ||
static get description () { | ||
return 'Save session config to the config file' | ||
} | ||
|
||
/** | ||
* IoC container injections | ||
* | ||
* @method inject | ||
* | ||
* @return {Array} | ||
*/ | ||
static get inject () { | ||
return ['Adonis/Src/Helpers'] | ||
} | ||
|
||
/** | ||
* Handle method called by ace when command is executed | ||
* | ||
* @method handle | ||
* | ||
* @param {Object} args | ||
* @param {Boolean} options.echo | ||
* | ||
* @return {void} | ||
*/ | ||
async handle (args, { echo }) { | ||
const template = await this.readFile(path.join(__dirname, './templates/config.mustache'), 'utf-8') | ||
|
||
/** | ||
* Echo template over creating the config file | ||
*/ | ||
if (echo) { | ||
return this.viaAce ? console.log(template) : 'echoed' | ||
} | ||
|
||
/** | ||
* Create config file | ||
*/ | ||
const configPath = `${path.join(this.Helpers.configPath(), 'session.js')}` | ||
await this.generateFile(configPath, template, {}) | ||
|
||
if (!this.viaAce) { | ||
return configPath | ||
} | ||
this.completed('created', configPath.replace(this.Helpers.appRoot(), '').replace(path.sep, '')) | ||
} | ||
} | ||
|
||
module.exports = ConfigSession |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
'use strict' | ||
|
||
const Env = use('Env') | ||
|
||
module.exports = { | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| Session Driver | ||
|-------------------------------------------------------------------------- | ||
| | ||
| The session driver to be used for storing session values. It can be | ||
| cookie, file or redis. | ||
| | ||
| For `redis` driver, make sure to install and register `@adonisjs/redis` | ||
| | ||
*/ | ||
driver: Env.get('SESSION_DRIVER', 'cookie'), | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| Cookie Name | ||
|-------------------------------------------------------------------------- | ||
| | ||
| The name of the cookie to be used for saving session id. Session ids | ||
| are signed and encrypted. | ||
| | ||
*/ | ||
cookieName: 'adonis-session', | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| Clear session when browser closes | ||
|-------------------------------------------------------------------------- | ||
| | ||
| If this value is true, the session cookie will be temporary and will be | ||
| removed when browser closes. | ||
| | ||
*/ | ||
clearWithBrowser: true, | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| Session age | ||
|-------------------------------------------------------------------------- | ||
| | ||
| This value is only used when `clearWithBrowser` is set to false. The | ||
| age must be a valid https://npmjs.org/package/ms string or should | ||
| be in milliseconds. | ||
| | ||
| Valid values are: | ||
| '2h', '10d', '5y', '2.5 hrs' | ||
| | ||
*/ | ||
age: '2h', | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| Cookie options | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Cookie options defines the options to be used for setting up session | ||
| cookie | ||
| | ||
*/ | ||
cookie: { | ||
httpOnly: true, | ||
sameSite: true | ||
}, | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Sessions location | ||
|-------------------------------------------------------------------------- | ||
| | ||
| If driver is set to file, we need to define the relative location from | ||
| the temporary path or absolute url to any location. | ||
| | ||
*/ | ||
file: { | ||
location: 'sessions' | ||
}, | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Redis config | ||
|-------------------------------------------------------------------------- | ||
| | ||
| The configuration for the redis driver. By default we reference it from | ||
| the redis file. But you are free to define an object here too. | ||
| | ||
*/ | ||
redis: 'self::redis.default' | ||
} |
Oops, something went wrong.