-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
11 changed files
with
588 additions
and
3 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
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,55 @@ | ||
'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 memoryStore = {} | ||
|
||
/** | ||
* Memory driver to save session values inside | ||
* memory. | ||
* | ||
* NOTE: Should be used in testing only | ||
* | ||
* @class Memory | ||
* @constructor | ||
*/ | ||
class Memory { | ||
/** | ||
* Write session values to memory | ||
* | ||
* @method write | ||
* | ||
* @param {String} sessionId | ||
* @param {Object} values | ||
* | ||
* @return {void} | ||
*/ | ||
write (sessionId, values) { | ||
memoryStore[sessionId] = values | ||
} | ||
|
||
/** | ||
* Returns value for a given session id | ||
* | ||
* @method read | ||
* | ||
* @param {String} sessionId | ||
* | ||
* @return {String} | ||
*/ | ||
read (sessionId) { | ||
return memoryStore[sessionId] | ||
} | ||
|
||
touch () {} | ||
} | ||
|
||
module.exports = exports = Memory | ||
exports.memoryStore = memoryStore |
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,49 @@ | ||
'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 _ = require('lodash') | ||
|
||
module.exports = function (View) { | ||
View.global('old', function (key, defaultValue) { | ||
return _.get(this.flashMessages, key, defaultValue) | ||
}) | ||
|
||
View.global('errors', function () { | ||
return this.$globals.old('errors') | ||
}) | ||
|
||
View.global('hasErrors', function (key) { | ||
return !!_.size(this.$globals.errors()) | ||
}) | ||
|
||
View.global('getErrorFor', function (key) { | ||
const errors = this.$globals.errors() | ||
|
||
/** | ||
* If errors is an object and not an array | ||
* then return the value for the key | ||
*/ | ||
if (_.isPlainObject(errors)) { | ||
return _.get(errors, key) | ||
} | ||
|
||
/** | ||
* Otherwise look inside array assuming validation | ||
* error structure | ||
*/ | ||
const errorMessage = _.find(errors, (error) => error.field === key) | ||
return errorMessage ? errorMessage.message : null | ||
}) | ||
|
||
View.global('hasErrorFor', function (key) { | ||
return !!this.$globals.error(key) | ||
}) | ||
} |
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
Oops, something went wrong.