Skip to content

Commit

Permalink
Merge branch 'release/1.0.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Jul 31, 2017
2 parents 218598e + add36dc commit 6111c86
Show file tree
Hide file tree
Showing 8 changed files with 1,734 additions and 239 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
<a name="1.0.5"></a>
## [1.0.5](https://github.com/adonisjs/adonis-session/compare/v1.0.4...v1.0.5) (2017-07-31)


### Bug Fixes

* **cookie:** touch values cookie everytime ([06b02cc](https://github.com/adonisjs/adonis-session/commit/06b02cc))


### Features

* **command:** add config:session command ([89e49eb](https://github.com/adonisjs/adonis-session/commit/89e49eb))



<a name="1.0.4"></a>
## [1.0.4](https://github.com/adonisjs/adonis-session/compare/v1.0.3...v1.0.4) (2017-07-22)

Expand Down
89 changes: 89 additions & 0 deletions commands/ConfigSession.js
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
93 changes: 93 additions & 0 deletions commands/templates/config.mustache
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'
}

0 comments on commit 6111c86

Please sign in to comment.