Skip to content

Commit

Permalink
Merge branch 'release-3.0.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Nov 8, 2016
2 parents 46d1437 + 181549d commit ad73415
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 92 deletions.
2 changes: 2 additions & 0 deletions BACKERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ Below is the list of awesome people supporting the development of AdonisJs. You

- Nicholas Rempel - [Servmetrics Ltd.](http://servmetrics.com/)
- Hans-Helge Bürger - [hanshelgebuerger.de](http://hanshelgebuerger.de)
- Marshall Moore - [chapterandver.se](chapterandver.se)
- Romain Lanz
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
<a name="3.0.5"></a>
## [3.0.5](https://github.com/adonisjs/adonis-framework/compare/v3.0.4...v3.0.5) (2016-11-08)


### Bug Fixes

* **session:** new cookie driver instance for each request ([c784fbb](https://github.com/adonisjs/adonis-framework/commit/c784fbb))



<a name="3.0.4"></a>
## [3.0.4](https://github.com/adonisjs/adonis-framework/compare/v3.0.3...v3.0.4) (2016-11-02)

Expand Down
59 changes: 34 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,53 @@
# AdonisJS Framework
<p align="center">
<a href="http://adonisjs.com"><img src="https://cloud.githubusercontent.com/assets/2793951/19925021/865beda4-a0ee-11e6-85bb-20ccd8f72211.png" alt="AdonisJs Framework"></a>
</p>

[![Gitter](https://img.shields.io/badge/+%20GITTER-JOIN%20CHAT%20%E2%86%92-1DCE73.svg?style=flat-square)](https://gitter.im/adonisjs/adonis-framework)
[![Trello](https://img.shields.io/badge/TRELLO-%E2%86%92-89609E.svg?style=flat-square)](https://trello.com/b/yzpqCgdl/adonis-for-humans)
[![Version](https://img.shields.io/npm/v/adonis-framework.svg?style=flat-square)](https://www.npmjs.com/package/adonis-framework)
[![Build Status](https://img.shields.io/travis/adonisjs/adonis-framework/master.svg?style=flat-square)](https://travis-ci.org/adonisjs/adonis-framework)
[![Coverage Status](https://img.shields.io/coveralls/adonisjs/adonis-framework/master.svg?style=flat-square)](https://coveralls.io/github/adonisjs/adonis-framework?branch=master)
[![Downloads](https://img.shields.io/npm/dt/adonis-framework.svg?style=flat-square)](https://www.npmjs.com/package/adonis-framework)
[![License](https://img.shields.io/npm/l/adonis-framework.svg?style=flat-square)](https://opensource.org/licenses/MIT)
[![Support AdonisJs](https://img.shields.io/badge/patreon-support-brightgreen.svg?style=flat-square)](https://www.patreon.com/adonisframework)
<p align="center">
<a href="https://www.npmjs.com/package/adonis-framework"><img src="https://img.shields.io/npm/v/adonis-framework.svg?style=flat-square" alt="Version"></a>
<a href="https://travis-ci.org/adonisjs/adonis-framework"><img src="https://img.shields.io/travis/adonisjs/adonis-framework/master.svg?style=flat-square" alt="Build Status"></a>
<a href="https://coveralls.io/github/adonisjs/adonis-framework?branch=master"><img src="https://img.shields.io/coveralls/adonisjs/adonis-framework/master.svg?style=flat-square" alt="Coverage Status"></a>
<a href="https://www.npmjs.com/package/adonis-framework"><img src="https://img.shields.io/npm/dt/adonis-framework.svg?style=flat-square" alt="Downloads"></a>
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/npm/l/adonis-framework.svg?style=flat-square" alt="License"></a>
</p>

> :pray: This repository contains the core of the AdonisJS framework.
<p align="center">
<a href="https://gitter.im/adonisjs/adonis-framework"><img src="https://img.shields.io/badge/gitter-join%20us-1DCE73.svg?style=flat-square" alt="Gitter"></a>
<a href="https://trello.com/b/yzpqCgdl/adonis-for-humans"><img src="https://img.shields.io/badge/trello-roadmap-89609E.svg?style=flat-square" alt="Trello"></a>
<a href="https://www.patreon.com/adonisframework"><img src="https://img.shields.io/badge/patreon-support%20AdonisJs-brightgreen.svg?style=flat-square" alt="Support AdonisJs"></a>
</p>

Adonis is a MVC framework for NodeJS built on solid foundations.
<br>

It is the first NodeJS framework with support for [Dependency Injection](http://adonisjs.com/docs/3.1/controllers#_dependency_injection) and has a lean [IoC Container](http://adonisjs.com/docs/3.1/ioc-container) to resolve and mock dependencies. It borrows the concept of [Service Providers](http://adonisjs.com/docs/3.1/ioc-container#_service_providers) from the popular [PHP framework Laravel](https://laravel.com) to write scalable applications.
AdonisJs is a MVC framework for Node.js built around practical use cases to give you a perfect solution that meets all of your needs. We focus on writing elegant code and being one of the most stable frameworks in the Node Community. :evergreen_tree:

You can learn more about AdonisJS and all of its awesomeness on http://adonisjs.com :evergreen_tree:
It is the first Node.js framework with support for [Dependency Injection](http://adonisjs.com/docs/controllers#_dependency_injection) and to have a lean [IoC Container](http://adonisjs.com/docs/ioc-container) to help you resolve and mock dependencies. It borrows the concept of [Service Providers](http://adonisjs.com/docs/ioc-container#_service_providers) from the popular [PHP framework Laravel](https://laravel.com) that lets you easily write scalable applications.

You can learn more about AdonisJs and all of its awesomeness on http://adonisjs.com :rocket:

<br>
<hr>
<br>

## Table of Contents

* [Team Members](#team-members)
* [Requirements](#requirements)
* [Getting Started](#getting-started)
* [Contribution Guidelines](#contribution-guidelines)

## <a name="team-members"></a>Team Members

* Harminder Virk ([Caffiene Blogging](http://amanvirk.me/)) <virk.officials@gmail.com>

<br>
## <a name="requirements"></a>Requirements

AdonisJS is build on the top of ES2015, which makes the code more enjoyable and cleaner to read. It doesn't make use of any transpiler and depends upon Core V8 implemented features.
AdonisJs is built on the top of ES2015, which makes the code more enjoyable and cleaner to read. It doesn't make use of any transpilers and depends upon Core V8 implemented features.

For these reasons, AdonisJS require you to use `node >= 4.0` and `npm >= 3.0`.
For these reasons, AdonisJs targets Node.js `4.0` or higher.

<br>
## <a name="getting-started"></a>Getting Started

AdonisJS provide a [CLI tool](https://github.com/AdonisJs/adonis-cli) to scaffold and generate a project with all required dependencies.
AdonisJs provides a [CLI tool](https://github.com/adonisjs/adonis-cli) to scaffold and generate a project with all required dependencies.

```bash
$ npm install -g adonis-cli
$ npm i -g adonis-cli
```

```bash
Expand All @@ -48,10 +56,11 @@ $ cd awesome-project
$ npm run start
```

[Official Documentation](http://adonisjs.com/docs/3.1/installation)
:point_right: [Read the Official Documentation](http://adonisjs.com/docs/installation)

<br>
## <a name="contribution-guidelines"></a>Contribution Guidelines

In favor of active development we accept contributions for everyone. You can contribute by submitting a bug, creating pull requests or even improving documentation.
In favor of active development we accept contributions from everyone. You can contribute by submitting a bug, creating pull requests or even improving documentation.

You can find a complete guide to be followed strictly before submitting your pull requests in the [Official Documentation](http://adonisjs.com/docs/3.1/contributing).
You can find a complete guide to be followed strictly before submitting your pull requests in the [Official Documentation](http://adonisjs.com/docs/contributing).
34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "adonis-framework",
"version": "3.0.4",
"version": "3.0.5",
"description": "Adonis framework makes it easy for you to write webapps with less code",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -29,24 +29,24 @@
"devDependencies": {
"adonis-fold": "^3.0.3",
"adonis-redis": "^1.0.1",
"chai": "^3.3.0",
"chai": "^3.5.0",
"cheerio": "^0.22.0",
"co-mocha": "^1.1.3",
"co-supertest": "0.0.10",
"coveralls": "^2.11.7",
"coveralls": "^2.11.14",
"cz-conventional-changelog": "^1.2.0",
"formidable": "^1.0.17",
"istanbul": "^0.4.0",
"mocha": "^3.1.1",
"mocha-lcov-reporter": "^1.1.0",
"pem": "^1.8.1",
"istanbul": "^0.4.5",
"mocha": "^3.1.2",
"mocha-lcov-reporter": "^1.2.0",
"pem": "^1.8.3",
"semver": "^5.3.0",
"shelljs": "^0.7.5",
"sinon": "^1.17.5",
"sinon": "^1.17.6",
"standard": "^8.5.0",
"supertest": "^1.1.0",
"supertest": "^2.0.1",
"test-console": "^1.0.0",
"zombie": "^4.2.1"
"zombie": "^5.0.1"
},
"dependencies": {
"adonis-binding-resolver": "^1.0.1",
Expand All @@ -56,17 +56,17 @@
"co": "^4.6.0",
"co-fs-extra": "^1.2.1",
"dotenv": "^2.0.0",
"eventemitter2": "^2.1.0",
"lodash": "^4.14.1",
"node-cookie": "^1.0.2",
"eventemitter2": "^2.1.3",
"lodash": "^4.16.6",
"node-cookie": "^1.0.3",
"node-exceptions": "^1.0.3",
"node-req": "^1.0.5",
"node-res": "^3.0.0",
"node-res": "^3.0.1",
"node-uuid": "^1.4.7",
"nunjucks": "^2.3.0",
"path-to-regexp": "^1.3.0",
"nunjucks": "^3.0.0",
"path-to-regexp": "^1.6.0",
"require-all": "^2.0.0",
"serve-static": "^1.10.2",
"serve-static": "^1.11.1",
"type-of-is": "^3.4.0"
},
"config": {
Expand Down
2 changes: 1 addition & 1 deletion providers/ServerProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const ServiceProvider = require('adonis-fold').ServiceProvider
class ServerProvider extends ServiceProvider {

* register () {
this.app.bind('Adonis/Src/Server', function (app) {
this.app.singleton('Adonis/Src/Server', function (app) {
const Request = app.use('Adonis/Src/Request')
const Response = app.use('Adonis/Src/Response')
const Route = app.use('Adonis/Src/Route')
Expand Down
53 changes: 34 additions & 19 deletions src/Session/Drivers/Cookie/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,8 @@
const CookieManager = require('../../CookieManager')
const _ = require('lodash')

/**
* Cookie driver for the session manager
* @class
* @alias SessionCookieDriver
*/
class Cookie {

/**
* Injects ['Adonis/Src/Config']
*/
static get inject () {
return ['Adonis/Src/Config']
}
class RequestCookie {

/**
* @constructor
*/
constructor (Config) {
this.cookieName = `${Config.get('session.cookie', 'adonis-session')}-value`
this.cookieManager = new CookieManager(Config)
Expand Down Expand Up @@ -116,9 +101,39 @@ class Cookie {
setRequest (request, response) {
this.request = request
this.response = response
this.response.once('finish', () => {
this.cookieJar = {}
})
}

}

/**
* Cookie driver for the session manager
* @class
* @alias SessionCookieDriver
*/
class Cookie {

/**
* Injects ['Adonis/Src/Config']
*/
static get inject () {
return ['Adonis/Src/Config']
}

/**
* @constructor
*/
constructor (Config) {
this.Config = Config
}

/**
* This method is called by session instance to get
* the fresh instance of cookie driver.
*
* @return {Object}
*/
fresh () {
return new RequestCookie(this.Config)
}

}
Expand Down
11 changes: 6 additions & 5 deletions src/Session/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ class Session {
* @private
*/
_setDriverRequest () {
if (this.constructor.driver.setRequest) {
this.constructor.driver.setRequest(this.request, this.response)
if (this.driver.setRequest) {
this.driver.setRequest(this.request, this.response)
}
}

Expand All @@ -104,6 +104,7 @@ class Session {
this.cookieManager = new CookieManager(this.constructor.config)
this.sessionCookieName = this.constructor.config.get('session.cookie', 'adonis-session')
this.sessionExpiryMs = this.constructor.config.get('session.age', 120) * 60 * 1000
this.driver = typeof (this.constructor.driver.fresh) === 'function' ? this.constructor.driver.fresh() : this.constructor.driver
this.sessionId = null
this.sessionPayload = null
}
Expand Down Expand Up @@ -150,7 +151,7 @@ class Session {
if (this.sessionPayload) {
return this.sessionPayload
}
const sessionValues = yield this.constructor.driver.read(sessionId)
const sessionValues = yield this.driver.read(sessionId)
this.sessionPayload = Store.unPackValues(sessionValues)
return this.sessionPayload
}
Expand All @@ -176,7 +177,7 @@ class Session {
_.set(sessionValues, key, value)
}
this.sessionPayload = sessionValues
return yield this.constructor.driver.write(sessionId, Store.packValues(this.sessionPayload))
return yield this.driver.write(sessionId, Store.packValues(this.sessionPayload))
}

/**
Expand Down Expand Up @@ -286,7 +287,7 @@ class Session {
* @return {Boolean}
*/
* flush () {
yield this.constructor.driver.destroy(this.getSessionId())
yield this.driver.destroy(this.getSessionId())
this.sessionPayload = null
this.sessionId = null
return this.cookieManager.remove(this.request, this.response, this.sessionCookieName)
Expand Down
36 changes: 11 additions & 25 deletions test/unit/sessions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@ describe('Session', function () {
const session = new SessionManager(Config)
expect(session.driver.sessionPath).to.equal('')
})

it('should set the driver to the value returned by fresh method', function * () {
class Redis {
fresh () {
return 'foo'
}
}
SessionManager.extend('my-redis', new Redis())
const Session = new SessionManager(new Config(null, {driver: 'my-redis'}))
expect(new Session().driver).to.equal('foo')
})
})

context('Session class @session', function () {
Expand Down Expand Up @@ -706,31 +717,6 @@ describe('Session', function () {
const cookies = parseCookies(res.headers['set-cookie'])
expect(cookies['adonis-session']).to.match(/Expires=\w{3},\s*\d{1,}\s*\w{3}\s*\d{4}/)
})

it('should clean cookie jar when request gets over', function * () {
const config = new Config()
Session.driver = new CookieDriver(config)
Session.config = config

const server = http.createServer(function (req, res) {
const session = new Session(req, res)
co(function * () {
yield session.put('name', 'virk')
return Session.driver.cookieJar
}).then(function (jar) {
res.writeHead(200, {'content-type': 'application/json'})
res.write(JSON.stringify({jar}))
res.end()
}).catch(function (err) {
res.writeHead(500, {'content-type': 'application/json'})
res.end(JSON.stringify(err))
})
})

const res = yield supertest(server).get('/').expect(200).end()
expect(res.body.jar).deep.equal({name: {d: 'virk', t: 'String'}})
expect(Session.driver.cookieJar).deep.equal({})
})
})

context('File Driver @file', function () {
Expand Down

0 comments on commit ad73415

Please sign in to comment.