sinatra-security 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown ADDED
@@ -0,0 +1,45 @@
1
+ Sinatra Security
2
+ ================
3
+
4
+ This gem just provides you with the standard authentication mechanisms you would expect from your typical app.
5
+
6
+ How to use
7
+ ==========
8
+
9
+ # in your terminal
10
+ [sudo] gem install sinatra-security
11
+
12
+ # in your sinatra app
13
+ require 'sinatra'
14
+ require 'sinatra/security'
15
+
16
+ get "/public" do
17
+ "Hello public world"
18
+ end
19
+
20
+ get "/private" do
21
+ login_required
22
+
23
+ "Hello private world"
24
+ end
25
+
26
+ get "/login" do
27
+ @user = User.new
28
+
29
+ haml :login
30
+ end
31
+
32
+ Note on Patches/Pull Requests
33
+ -----------------------------
34
+
35
+ * Fork the project.
36
+ * Make your feature addition or bug fix.
37
+ * Add tests for it. This is important so I don't break it in a
38
+ future version unintentionally.
39
+ * Commit, do not mess with rakefile, version, or history.
40
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
41
+ * Send me a pull request. Bonus points for topic branches.
42
+
43
+ Copyright
44
+ ---------
45
+ Copyright (c) 2010 Cyril David. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -0,0 +1,46 @@
1
+ require 'sinatra'
2
+ require 'sinatra/security'
3
+
4
+ class User
5
+ attr :id
6
+
7
+ def self.authenticate(user, pass)
8
+ User.new(42) if [ user, pass ] == [ 'quentin', 'test' ]
9
+ end
10
+
11
+ def self.[](id)
12
+ User.new(id)
13
+ end
14
+
15
+ def initialize(id = nil)
16
+ @id = id
17
+ end
18
+ end
19
+
20
+ use Rack::Session::Cookie
21
+
22
+ get "/" do
23
+ haml :home
24
+ end
25
+
26
+ get "/public" do
27
+ "Hello public world"
28
+ end
29
+
30
+ get "/private" do
31
+ require_login
32
+
33
+ "Hello private world <a href='/logout'>Logout</a>"
34
+ end
35
+
36
+ get "/login" do
37
+ @user = User.new
38
+
39
+ haml :login
40
+ end
41
+
42
+ get "/logout" do
43
+ logout!
44
+
45
+ redirect '/'
46
+ end
@@ -0,0 +1,4 @@
1
+ %h1 Sinatra Classic Example
2
+
3
+ %a(href='/public') Public View
4
+ %a(href='/private') Private View
@@ -0,0 +1,10 @@
1
+ %h1 Login
2
+
3
+ - if error = session.delete(:error)
4
+ %p= error
5
+
6
+ %form(action='/login' method='post')
7
+ %input(type='text' name='username')
8
+ %input(type='password' name='password')
9
+
10
+ %button(type='submit') Login
@@ -37,6 +37,10 @@ module Sinatra
37
37
  def ensure_current_user(user)
38
38
  halt 404 unless user == current_user
39
39
  end
40
+
41
+ def logout!
42
+ session.delete(:user)
43
+ end
40
44
  end
41
45
  end
42
46
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sinatra-security}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Cyril David"]
@@ -14,15 +14,18 @@ Gem::Specification.new do |s|
14
14
  s.email = %q{cyx.ucron@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.markdown"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
21
  ".gitignore",
22
22
  "LICENSE",
23
- "README.rdoc",
23
+ "README.markdown",
24
24
  "Rakefile",
25
25
  "VERSION",
26
+ "examples/classic.rb",
27
+ "examples/views/home.haml",
28
+ "examples/views/login.haml",
26
29
  "lib/sinatra/security.rb",
27
30
  "lib/sinatra/security/helpers.rb",
28
31
  "sinatra-security.gemspec",
@@ -39,7 +42,8 @@ Gem::Specification.new do |s|
39
42
  s.test_files = [
40
43
  "test/helper.rb",
41
44
  "test/test_sinatra-security.rb",
42
- "test/test_sinatra_security_helpers.rb"
45
+ "test/test_sinatra_security_helpers.rb",
46
+ "examples/classic.rb"
43
47
  ]
44
48
 
45
49
  if s.respond_to? :specification_version then
@@ -110,4 +110,13 @@ class TestSinatraSecurityHelpers < Test::Unit::TestCase
110
110
  end
111
111
  end
112
112
  end
113
+
114
+ describe "#logout" do
115
+ should "set the remove the session[:user]" do
116
+ @context.session[:user] = 1
117
+ @context.logout!
118
+
119
+ assert ! @context.session[:user]
120
+ end
121
+ end
113
122
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Cyril David
@@ -26,14 +26,17 @@ extensions: []
26
26
 
27
27
  extra_rdoc_files:
28
28
  - LICENSE
29
- - README.rdoc
29
+ - README.markdown
30
30
  files:
31
31
  - .document
32
32
  - .gitignore
33
33
  - LICENSE
34
- - README.rdoc
34
+ - README.markdown
35
35
  - Rakefile
36
36
  - VERSION
37
+ - examples/classic.rb
38
+ - examples/views/home.haml
39
+ - examples/views/login.haml
37
40
  - lib/sinatra/security.rb
38
41
  - lib/sinatra/security/helpers.rb
39
42
  - sinatra-security.gemspec
@@ -75,3 +78,4 @@ test_files:
75
78
  - test/helper.rb
76
79
  - test/test_sinatra-security.rb
77
80
  - test/test_sinatra_security_helpers.rb
81
+ - examples/classic.rb
data/README.rdoc DELETED
@@ -1,17 +0,0 @@
1
- = sinatra-security
2
-
3
- Description goes here.
4
-
5
- == Note on Patches/Pull Requests
6
-
7
- * Fork the project.
8
- * Make your feature addition or bug fix.
9
- * Add tests for it. This is important so I don't break it in a
10
- future version unintentionally.
11
- * Commit, do not mess with rakefile, version, or history.
12
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
- * Send me a pull request. Bonus points for topic branches.
14
-
15
- == Copyright
16
-
17
- Copyright (c) 2010 Cyril David. See LICENSE for details.