sinatra-session_helpers 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +42 -12
- data/lib/sinatra/session_helpers.rb +0 -3
- data/lib/sinatra/session_helpers/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7838404449cb5ca64f475784682933a9908da031
|
4
|
+
data.tar.gz: 9fb0e9582dd20b644428ffa758c163db4e0da060
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 382c9678756366ac115562877839f8fe98797c2750ae52cf762bed9ba48ef950a49497afd8408dc23849d43e9aafe87e890adec6114644a0741d9cd3cdd7ed78
|
7
|
+
data.tar.gz: f6f8f5ee6bcc5039e8d37ce54e7542b93031c33d84bd66419370357405890f4cf19a049f96a3ee440349b50859ca3c9e62a9532a160c76fe44d06671773bbbfb
|
data/README.md
CHANGED
@@ -22,34 +22,44 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
###
|
25
|
+
### [Enable Sessions](http://www.sinatrarb.com/faq.html#sessions)
|
26
|
+
|
27
|
+
Since 0.2.0, this gem doesn't automatically enable sessions.
|
28
|
+
This means **you have to enable sessions in your app.**
|
29
|
+
|
30
|
+
This is so you can choose how to enable them, like using `Rack::Session::Cookie` if you need.
|
31
|
+
|
32
|
+
Enable Sinatra built-in sessions:
|
26
33
|
|
27
34
|
```ruby
|
28
|
-
|
29
|
-
`session_end!(destroy=true)` -> Ends the session. If `destroy` is false then
|
30
|
-
session data will be preserved, even though future calls to `session?` will return false
|
31
|
-
`session?` -> Returns true if the session is valid
|
32
|
-
`session!` -> Redirects the client to the URL specified in
|
33
|
-
the `session_fail` option unless the session is valid
|
35
|
+
enable :sessions
|
34
36
|
```
|
35
37
|
|
36
|
-
|
38
|
+
Or, if you need to set additional parameters for sessions, like expiration date, use `Rack::Session::Cookie` directly instead of `enable :sessions` (example from Rack documentation):
|
37
39
|
|
40
|
+
```ruby
|
41
|
+
use Rack::Session::Cookie, :key => 'rack.session',
|
42
|
+
:domain => 'foo.com',
|
43
|
+
:path => '/',
|
44
|
+
:expire_after => 2592000, # In seconds
|
45
|
+
:secret => 'change_me'
|
38
46
|
```
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
47
|
+
|
48
|
+
#### Advanced Sinatra built-in sessions parameters
|
49
|
+
|
50
|
+
Here's how to do if you want to use Sinatra's built-in sessions, instead of `Rack::Session::Cookie`, and still specify additional parameters.
|
43
51
|
|
44
52
|
You can force a specific secret key on the session:
|
45
53
|
|
46
54
|
```ruby
|
55
|
+
enable :sessions
|
47
56
|
set :session_secret, '$ecR3t'
|
48
57
|
```
|
49
58
|
|
50
59
|
Or other optional parameters like this:
|
51
60
|
|
52
61
|
```ruby
|
62
|
+
enable :sessions
|
53
63
|
set :sessions, :key => 'sinatra.session',
|
54
64
|
:path => '/',
|
55
65
|
:domain => 'foo.com',
|
@@ -57,6 +67,25 @@ set :sessions, :key => 'sinatra.session',
|
|
57
67
|
:secret => 'change_me'
|
58
68
|
```
|
59
69
|
|
70
|
+
### Helper Methods
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
`session_start!` -> Starts the session
|
74
|
+
`session_end!(destroy=true)` -> Ends the session. If `destroy` is false then
|
75
|
+
session data will be preserved, even though future calls to `session?` will return false
|
76
|
+
`session?` -> Returns true if the session is valid
|
77
|
+
`session!` -> Redirects the client to the URL specified in
|
78
|
+
the `session_fail` option unless the session is valid
|
79
|
+
```
|
80
|
+
|
81
|
+
### Settings
|
82
|
+
|
83
|
+
```
|
84
|
+
`session_fail` -> A URL in your app that the client will be redirected to
|
85
|
+
when `session!` is called and the session is not valid.
|
86
|
+
Defaults to '/login'
|
87
|
+
```
|
88
|
+
|
60
89
|
## Examples
|
61
90
|
|
62
91
|
As with all Sinatra extensions, Sinatra::SessionHelpers may be used in both classic and modular-style apps. First, classic.
|
@@ -65,6 +94,7 @@ As with all Sinatra extensions, Sinatra::SessionHelpers may be used in both clas
|
|
65
94
|
require 'sinatra'
|
66
95
|
require 'sinatra/session_helpers'
|
67
96
|
|
97
|
+
enable :sessions
|
68
98
|
set :session_fail, '/login'
|
69
99
|
set :session_secret, 'So0perSeKr3t!'
|
70
100
|
set :sessions, :key => 'my_app'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-session_helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julien Ma
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|