calib-rails 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -5
- data/lib/calib/controllers/basic_auth.rb +32 -27
- data/lib/calib/rails/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c136ae28f6cd9225817e20d584b8fe3a10c2eeb94fb0954cb0e5c35203f361b
|
4
|
+
data.tar.gz: c355b4cba03b6b191d0cbf0a47e0830cb09a9c11e7fdfbf1428bb8b800311474
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b327099d26cef807af1c22101dd7600c36c9ccd1469e79b2c382dc9024c3f9e1c5a611980f9cecac1bdfad141272a3db7344222da71d04a019ba40724ad95df2
|
7
|
+
data.tar.gz: 6f7adea3885ab9dc94ad99bd8b7ab83bd7037259a66af3d1b336738c33aaa7bb0ce83131afabdd3913bcd470095db215ad261568d7bf9603bb3d04b71d959b17
|
data/README.md
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
# Calib::Rails
|
2
|
-
|
2
|
+
Calib::Rails is modules of something tips for Rails.
|
3
3
|
|
4
4
|
## Usage
|
5
|
-
|
5
|
+
Please read rdocs.
|
6
|
+
|
7
|
+
- [Calib::Controllers::BasicAuth](http://www.rubydoc.info/gems/calib-rails/Calib/Controllers/BasicAuth)
|
8
|
+
- [Calib::Devise::FriendlyForwardable](http://www.rubydoc.info/gems/calib-rails/Calib/Devise/FriendlyForwardable)
|
6
9
|
|
7
10
|
## Installation
|
8
11
|
Add this line to your application's Gemfile:
|
@@ -21,8 +24,5 @@ Or install it yourself as:
|
|
21
24
|
$ gem install calib-rails
|
22
25
|
```
|
23
26
|
|
24
|
-
## Contributing
|
25
|
-
Contribution directions go here.
|
26
|
-
|
27
27
|
## License
|
28
28
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -1,40 +1,45 @@
|
|
1
|
+
# == A Module for Basic Authentication
|
2
|
+
# authenticated status stored in session.
|
3
|
+
# avoid frequently logging in
|
4
|
+
#
|
1
5
|
# [usage]
|
2
|
-
#
|
6
|
+
# class ApplicationController < ActionController::Base
|
7
|
+
# include Calib::Controllers::BasicAuth
|
8
|
+
# basic_auth(user: 'myuser', pass: 'secret')
|
9
|
+
# ...
|
10
|
+
# end
|
11
|
+
#
|
3
12
|
# basic_auth # read ENV['BASIC_AUTH_USER'] and ENV['BASIC_AUTH_PASS']
|
4
13
|
# basic_auth(user: 'myuser', pass: 'secret') # standard
|
5
14
|
#
|
6
15
|
# basic_auth(user: 'myuser', pass: 'secret') do
|
7
16
|
# request.domain != 'localhost' # localhost is unblocked domain.
|
8
17
|
# end
|
9
|
-
module Calib
|
10
|
-
|
11
|
-
module BasicAuth
|
12
|
-
extend ActiveSupport::Concern
|
18
|
+
module Calib::Controllers::BasicAuth
|
19
|
+
extend ActiveSupport::Concern
|
13
20
|
|
14
|
-
|
15
|
-
|
21
|
+
included do
|
22
|
+
class_attribute :basic_auth_user, :basic_auth_pass, :basic_auth_session_key, :basic_auth_block
|
16
23
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
24
|
+
def self.basic_auth(user: ENV['BASIC_AUTH_USER'], password: ENV['BASIC_AUTH_PASS'], key: :basic_auth, &block)
|
25
|
+
self.basic_auth_user = user
|
26
|
+
self.basic_auth_pass = password
|
27
|
+
self.basic_auth_session_key = key
|
28
|
+
self.basic_auth_block = block
|
29
|
+
end
|
23
30
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
31
|
+
before_action -> {
|
32
|
+
return if self.class.basic_auth_user.blank?
|
33
|
+
return if session[self.class.basic_auth_session_key].present?
|
34
|
+
return if self.class.basic_auth_block.present? && !self.class.basic_auth_block.call(request)
|
28
35
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
38
|
-
end
|
36
|
+
authenticate_or_request_with_http_basic do |user, pass|
|
37
|
+
if user == self.class.basic_auth_user && pass == self.class.basic_auth_pass
|
38
|
+
session[self.class.basic_auth_session_key] = true
|
39
|
+
return true
|
40
|
+
end
|
41
|
+
false
|
42
|
+
end
|
43
|
+
}
|
39
44
|
end
|
40
45
|
end
|
data/lib/calib/rails/version.rb
CHANGED