rack_warden 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YmEzNjc1YzgzMjZmMzViZDIxNDliOTAzNDZlMzBkYmUzZTdlMDY4ZA==
4
+ MzJhMzZlZDM3YTVkYjE4MDczZTM2ZjhlYmU0MTQ0NmYyMjVkMmY3Mg==
5
5
  data.tar.gz: !binary |-
6
- NjhlZGE3ZWY4OWI2MzM2MWVhNzY2YTZiNjcxOGI2ZDZkMjRlZDcxZA==
6
+ NzIwOGNlNTQzZDBkZjk4NTgwYTllOTM3MTJkMzM2Y2EyNWUzNmY0NA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZmU0NTYxZjc0ZDhjMDhmYWFkMzIzMDU3M2ZjYWI1MDhlMmExNTZhYjY5Mzk3
10
- Njk0ZjA5OTdiYjZmODFiMGVkNThkYjYxODEzZDlkNDZiNTEwMGQzNGFiZGJj
11
- OTIxOTQ0YjJjZWU3ZjRjYmJiZDE2MmFlYmI4OWY1M2ZhYWM5MzU=
9
+ ZGFlMzk2OTNiYWU0OGJjYmUxNjAyN2U1MTU0Y2YzMTUyZGI0NDg1MTEzYjgz
10
+ NGFkOGU1ZDk5YjcxOGI5MTNlMmNkMjc2Nzk4OWQzZGY2MjM5NzFkMjgyODcw
11
+ MTI4OGU3YTQxMDI1OTNlYTAwN2Q1MTYwMTFiZDQyMTQ5MzRkODc=
12
12
  data.tar.gz: !binary |-
13
- MGVkMzY5ODI2ZGYwZDg4NzNmNzBjMzI3M2VmZDBkMzIzMmRmNDY1MWU1Mzg5
14
- NDI0NzExODY3NjM1Y2E1MDljYzI3MGU2ZGFlMjgzZjU5Y2Q1ZDU2NzllNzhj
15
- NzA4MDE3NjBhNGU2NzhhYWQzZDVhMDIzYmM5YjI4ZjQ2NzU4MWI=
13
+ Yjk0MWUyMTBjZmMyNmEwNjZlNTAwZmM1M2Q2NmJkYjViNzllYTlhMGIwNDA2
14
+ YTc1NzY0MGY0NDQ4YmExMDA1NzQyYTNiM2YxZDE4ZWJhMmE0MTU4OTg3MGEx
15
+ MWI1MDE5ZjNkOGRjNTUyNjBmMzU0YThkY2JkNzgzMmM0ZDFjNzg=
data/README.md CHANGED
@@ -54,7 +54,7 @@ application-controller.rb
54
54
 
55
55
  ## Configuration
56
56
 
57
- Pass configuration settings to RackWarden through your ``use`` method. The params hash will be translated directly to the app's settings. You can currently specify :database, :views, and :default_route. You can also specify any of the standard Sinatra settings, like :views.
57
+ Pass configuration settings to RackWarden through your ``use`` method. The params hash will be translated directly to the app's settings. You can currently specify :layout, :database, :default_route, and :recaptcha. You can also specify any of the standard Sinatra settings, like :views.
58
58
 
59
59
  If you pass a block with the ``use`` method, the block will be evaluated in the context of the RackWarden::App class. Anything you do in that block is just as if you were writing code in the app class itself. While in the block, you also have access to two relevant objects.
60
60
 
@@ -62,6 +62,36 @@ If you pass a block with the ``use`` method, the block will be evaluated in the
62
62
  set :somesetting, 'some_value'
63
63
  end
64
64
 
65
+ ### Configuration Options
66
+
67
+ Current list of settings specific to rack_warden, with defaults.
68
+
69
+ #### :layout
70
+
71
+ A symbol representing a layout file in any of the view paths.
72
+
73
+ :layout => :'rack_warden_layout.html'
74
+
75
+ #### :default_route
76
+
77
+ A Sinatra route to fall back on after logout, errors, or any action that has no specified route.
78
+
79
+ :default_route => '/'
80
+
81
+ #### :database
82
+
83
+ A DataMapper database specification
84
+
85
+ :database => "sqlite:///Absolute/path/to/your/project/rack_warden.sqlite.db"
86
+
87
+ #### :recaptcha
88
+
89
+ Settings for Google's recaptcha service
90
+
91
+ :recaptcha => {
92
+ :sitekey => '',
93
+ :secret => ''
94
+ }
65
95
 
66
96
  ## Customization
67
97
 
@@ -5,10 +5,11 @@ module RackWarden
5
5
  class App < Sinatra::Base
6
6
  enable :sessions
7
7
  register Sinatra::Flash
8
- set :config_files, [ENV['RACK_WARDEN_CONFIG_FILE'], 'rack_warden.yml', 'rack_warden.yaml'].compact.uniq
8
+ set :config_files, [ENV['RACK_WARDEN_CONFIG_FILE'], 'rack_warden.yml', 'config/rack_warden.yml'].compact.uniq
9
9
  set :layout, :'rack_warden_layout.html'
10
10
  set :default_route, '/'
11
11
  set :database, "sqlite://#{Dir.pwd}/rack_warden.sqlite.db"
12
+ set :recaptcha, Hash.new
12
13
 
13
14
  # Load config from file, if any exist.
14
15
  Hash.new.tap do |hash|
@@ -151,10 +152,9 @@ module RackWarden
151
152
  params['user'] && params['user']['username'] && params['user']['password']
152
153
  end
153
154
 
154
- # TODO: This doesn't work.
155
155
  def create_user
156
156
 
157
- recaptcha
157
+ verify_recaptcha if settings.recaptcha[:secret]
158
158
 
159
159
  return unless valid_user_input?
160
160
  user = User.create(username: params['user']['username'])
@@ -162,14 +162,14 @@ module RackWarden
162
162
  user.save && warden.set_user(user)
163
163
  end
164
164
 
165
- # reCAPTCHA. See https://www.google.com/recaptcha/admin#site/318693958?setup
166
- def recaptcha(skip_redirect=false)
167
- _recaptcha = ActiveSupport::JSON.decode(open("https://www.google.com/recaptcha/api/siteverify?secret=6LdG4v4SAAAAAJxwcS8pZRG371ZucyYg5yVUji_V&response=#{params['g-recaptcha-response']}&remoteip=#{request.ip}").read)
165
+ def verify_recaptcha(skip_redirect=false, ip=request.ip, response=params['g-recaptcha-response'])
166
+ secret = settings.recaptcha[:secret]
167
+ _recaptcha = ActiveSupport::JSON.decode(open("https://www.google.com/recaptcha/api/siteverify?secret=#{secret}&response=#{response}&remoteip=#{ip}").read)
168
168
  puts "RECAPTCHA", _recaptcha
169
- #(render action and return) unless recaptcha['success']
170
- unless _recaptcha['success'] || skip_redirect
171
- flash(:rwarden)[:error] = "Please confirm you are human."
172
- redirect back
169
+ unless _recaptcha['success']
170
+ flash(:rwarden)[:error] = "Please confirm you are human"
171
+ redirect back unless skip_redirect
172
+ Halt "You appear to be a robot."
173
173
  end
174
174
  end
175
175
 
@@ -215,7 +215,7 @@ module RackWarden
215
215
  end
216
216
 
217
217
  get '/auth/create' do
218
- erb :'create_user.html', :layout=>settings.layout
218
+ erb :'create_user.html', :layout=>settings.layout, :locals=>{:recaptcha_sitekey=>settings.recaptcha[:sitekey]}
219
219
  end
220
220
 
221
221
  post '/auth/create' do
@@ -1,3 +1,3 @@
1
1
  module RackWarden
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -2,8 +2,8 @@
2
2
  <form action="<%=url('/auth/create', false)%>" method="post">
3
3
  <p>Username: <input type="text" name="user[username]" /></p>
4
4
  <p>Password: <input type="password" name="user[password]" /></p>
5
- <% if @recapture_key %>
6
- <div class="g-recaptcha control text-control" data-sitekey="<%=@recapture_key%>"></div>
5
+ <% if recaptcha_sitekey %>
6
+ <div class="g-recaptcha control text-control" data-sitekey="<%=recaptcha_sitekey%>"></div>
7
7
  <% end %>
8
8
  <input type="submit" value="Create" />
9
9
  </form>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack_warden
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Richardson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-28 00:00:00.000000000 Z
11
+ date: 2014-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler