First Commit
This commit is contained in:
commit
601e886c14
2123 files changed
+334815
No files matched your search
+6
@@ -0,0 +1,6 @@
|
||||
language: "node_js"
|
||||
node_js:
|
||||
- 0.4
|
||||
- 0.6
|
||||
- 0.8
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2012-2013 Jared Hanson
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
# connect-flash
|
||||
|
||||
The flash is a special area of the session used for storing messages. Messages
|
||||
are written to the flash and cleared after being displayed to the user. The
|
||||
flash is typically used in combination with redirects, ensuring that the message
|
||||
is available to the next page that is to be rendered.
|
||||
|
||||
This middleware was extracted from [Express](http://expressjs.com/) 2.x, after
|
||||
Express 3.x removed direct support for the flash. connect-flash brings this
|
||||
functionality back to Express 3.x, as well as any other middleware-compatible
|
||||
framework or application. +1 for [radical reusability](http://substack.net/posts/b96642/the-node-js-aesthetic).
|
||||
|
||||
## Install
|
||||
|
||||
$ npm install connect-flash
|
||||
|
||||
## Usage
|
||||
|
||||
#### Express 3.x
|
||||
|
||||
Flash messages are stored in the session. First, setup sessions as usual by
|
||||
enabling `cookieParser` and `session` middleware. Then, use `flash` middleware
|
||||
provided by connect-flash.
|
||||
|
||||
```javascript
|
||||
var flash = require('connect-flash');
|
||||
var app = express();
|
||||
|
||||
app.configure(function() {
|
||||
app.use(express.cookieParser('keyboard cat'));
|
||||
app.use(express.session({ cookie: { maxAge: 60000 }}));
|
||||
app.use(flash());
|
||||
});
|
||||
```
|
||||
|
||||
With the `flash` middleware in place, all requests will have a `req.flash()` function
|
||||
that can be used for flash messages.
|
||||
|
||||
```javascript
|
||||
app.get('/flash', function(req, res){
|
||||
// Set a flash message by passing the key, followed by the value, to req.flash().
|
||||
req.flash('info', 'Flash is back!')
|
||||
res.redirect('/');
|
||||
});
|
||||
|
||||
app.get('/', function(req, res){
|
||||
// Get an array of flash messages by passing the key to req.flash()
|
||||
res.render('index', { messages: req.flash('info') });
|
||||
});
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
For an example using connect-flash in an Express 3.x app, refer to the [express3](https://github.com/jaredhanson/connect-flash/tree/master/examples/express3)
|
||||
example.
|
||||
|
||||
## Tests
|
||||
|
||||
$ npm install --dev
|
||||
$ make test
|
||||
|
||||
[](http://travis-ci.org/jaredhanson/connect-flash)
|
||||
|
||||
## Credits
|
||||
|
||||
- [Jared Hanson](http://github.com/jaredhanson)
|
||||
- [TJ Holowaychuk](https://github.com/visionmedia)
|
||||
|
||||
## License
|
||||
|
||||
[The MIT License](http://opensource.org/licenses/MIT)
|
||||
|
||||
Copyright (c) 2012-2013 Jared Hanson <[http://jaredhanson.net/](http://jaredhanson.net/)>
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
var format = require('util').format;
|
||||
var isArray = require('util').isArray;
|
||||
|
||||
|
||||
/**
|
||||
* Expose `flash()` function on requests.
|
||||
*
|
||||
* @return {Function}
|
||||
* @api public
|
||||
*/
|
||||
module.exports = function flash(options) {
|
||||
options = options || {};
|
||||
var safe = (options.unsafe === undefined) ? true : !options.unsafe;
|
||||
|
||||
return function(req, res, next) {
|
||||
if (req.flash && safe) { return next(); }
|
||||
req.flash = _flash;
|
||||
next();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Queue flash `msg` of the given `type`.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* req.flash('info', 'email sent');
|
||||
* req.flash('error', 'email delivery failed');
|
||||
* req.flash('info', 'email re-sent');
|
||||
* // => 2
|
||||
*
|
||||
* req.flash('info');
|
||||
* // => ['email sent', 'email re-sent']
|
||||
*
|
||||
* req.flash('info');
|
||||
* // => []
|
||||
*
|
||||
* req.flash();
|
||||
* // => { error: ['email delivery failed'], info: [] }
|
||||
*
|
||||
* Formatting:
|
||||
*
|
||||
* Flash notifications also support arbitrary formatting support.
|
||||
* For example you may pass variable arguments to `req.flash()`
|
||||
* and use the %s specifier to be replaced by the associated argument:
|
||||
*
|
||||
* req.flash('info', 'email has been sent to %s.', userName);
|
||||
*
|
||||
* Formatting uses `util.format()`, which is available on Node 0.6+.
|
||||
*
|
||||
* @param {String} type
|
||||
* @param {String} msg
|
||||
* @return {Array|Object|Number}
|
||||
* @api public
|
||||
*/
|
||||
function _flash(type, msg) {
|
||||
if (this.session === undefined) throw Error('req.flash() requires sessions');
|
||||
var msgs = this.session.flash = this.session.flash || {};
|
||||
if (type && msg) {
|
||||
// util.format is available in Node.js 0.6+
|
||||
if (arguments.length > 2 && format) {
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
msg = format.apply(undefined, args);
|
||||
} else if (isArray(msg)) {
|
||||
msg.forEach(function(val){
|
||||
(msgs[type] = msgs[type] || []).push(val);
|
||||
});
|
||||
return msgs[type].length;
|
||||
}
|
||||
return (msgs[type] = msgs[type] || []).push(msg);
|
||||
} else if (type) {
|
||||
var arr = msgs[type];
|
||||
delete msgs[type];
|
||||
return arr || [];
|
||||
} else {
|
||||
this.session.flash = {};
|
||||
return msgs;
|
||||
}
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* Expose middleware.
|
||||
*/
|
||||
exports = module.exports = require('./flash');
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"connect-flash@0.1.1",
|
||||
"C:\\Users\\flami\\OneDrive\\Desktop\\node_passport_login"
|
||||
]
|
||||
],
|
||||
"_from": "connect-flash@0.1.1",
|
||||
"_id": "connect-flash@0.1.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-2GMPJtlaf4UfmVax6MxnMvO2qjA=",
|
||||
"_location": "/connect-flash",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "connect-flash@0.1.1",
|
||||
"name": "connect-flash",
|
||||
"escapedName": "connect-flash",
|
||||
"rawSpec": "0.1.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "0.1.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/connect-flash/-/connect-flash-0.1.1.tgz",
|
||||
"_spec": "0.1.1",
|
||||
"_where": "C:\\Users\\flami\\OneDrive\\Desktop\\node_passport_login",
|
||||
"author": {
|
||||
"name": "Jared Hanson",
|
||||
"email": "jaredhanson@gmail.com",
|
||||
"url": "http://www.jaredhanson.net/"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "http://github.com/jaredhanson/connect-flash/issues"
|
||||
},
|
||||
"dependencies": {},
|
||||
"description": "Flash message middleware for Connect.",
|
||||
"devDependencies": {
|
||||
"vows": "0.6.x"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4.0"
|
||||
},
|
||||
"homepage": "https://github.com/jaredhanson/connect-flash#readme",
|
||||
"keywords": [
|
||||
"connect",
|
||||
"express",
|
||||
"flash",
|
||||
"messages"
|
||||
],
|
||||
"licenses": [
|
||||
{
|
||||
"type": "MIT",
|
||||
"url": "http://www.opensource.org/licenses/MIT"
|
||||
}
|
||||
],
|
||||
"main": "./lib",
|
||||
"name": "connect-flash",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/jaredhanson/connect-flash.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "NODE_PATH=lib node_modules/.bin/vows test/*-test.js"
|
||||
},
|
||||
"version": "0.1.1"
|
||||
}
|
||||
Reference in new issue
Block a user