sinatra-nedry 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/sinatra/nedry.rb +52 -0
  3. metadata +58 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 869e90dfada7db6b99ce35b1f00560b98ad8769e
4
+ data.tar.gz: e5c156c1e20fcf74cb18821d0721ebfa90754064
5
+ SHA512:
6
+ metadata.gz: 775ef1c10a6fcb219c2f0f17a23a55ac5faff92dbb63157c4dadd31d6df69c704fa2b9a12e2b732b21d58a308c4add6e3c6a19296ae4f6f6bb639230a9365778
7
+ data.tar.gz: 9085bcc812c68884a54ede23dc34cf9d230ba49dab09269c5f06b64e4ac003331e3144a278d4cd99168466cfb2e0e7e7bdebc3b9c21f6aa85dca492888dc0a64
@@ -0,0 +1,52 @@
1
+ module Sinatra
2
+ module Nedry
3
+ def protected!(&blk)
4
+ if authorized?
5
+ blk.call
6
+ else
7
+ not_authorized
8
+ end
9
+ end
10
+
11
+ def flagged!(&blk)
12
+ if authorized? || ENV["RACK_ENV"] != "production"
13
+ blk.call
14
+ else
15
+ not_authorized
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def authorized?
22
+ admin_credentials = if ENV["RACK_ENV"] == "production"
23
+ [ENV["ADMIN_USERNAME"], ENV["ADMIN_PASSWORD"]]
24
+ else
25
+ ["admin", "admin"]
26
+ end
27
+
28
+ @auth ||= Rack::Auth::Basic::Request.new(request.env)
29
+ @auth.provided? and @auth.basic? and @auth.credentials and @auth.credentials == admin_credentials
30
+ end
31
+
32
+ def not_authorized
33
+ headers['WWW-Authenticate'] = 'Basic realm="Restricted Area"'
34
+ halt 401, NOT_AUTH_TEMPLAT
35
+ end
36
+
37
+ NOT_AUTH_TEMPLATE = <<-ERB
38
+ <div style="text-align: center; margin-top: 40px">
39
+ <iframe
40
+ width="853"
41
+ height="480"
42
+ src="//www.youtube.com/embed/RfiQYRn7fBg?autoplay=1&loop=1&playlist=RfiQYRn7fBg"
43
+ frameborder="0"
44
+ allowfullscreen>
45
+ </iframe>
46
+ <h1>Ah ah ah!</h1>
47
+ </div>
48
+ ERB
49
+ end
50
+
51
+ helpers Nedry
52
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatra-nedry
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Callum Stott
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sinatra
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description:
28
+ email:
29
+ - callum@seadowg.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - lib/sinatra/nedry.rb
35
+ homepage:
36
+ licenses: []
37
+ metadata: {}
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubyforge_project:
54
+ rubygems_version: 2.0.3
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: HTTP Basic Auth helpers for Sinatra with built in Ah ah ah!
58
+ test_files: []