Class: TDiary::Rack::Auth::Basic
- Inherits:
-
Object
- Object
- TDiary::Rack::Auth::Basic
- Defined in:
- lib/tdiary/rack/auth/basic.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, file = '.htpasswd') ⇒ Basic
constructor
A new instance of Basic.
Constructor Details
#initialize(app, file = '.htpasswd') ⇒ Basic
Returns a new instance of Basic.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/tdiary/rack/auth/basic.rb', line 10 def initialize(app, file = '.htpasswd') @authenticator = ::Rack::Auth::Basic.new(app) do |user, pass| unless File.exist?(file) raise PasswordFileNotFound.new("#{file} is not found. Please create it by htpasswd program.") end htpasswd = WEBrick::HTTPAuth::Htpasswd.new(file) crypted = htpasswd.get_passwd(nil, user, false) crypted == pass.crypt(crypted) if crypted end end |
Instance Method Details
#call(env) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/tdiary/rack/auth/basic.rb', line 21 def call(env) begin @authenticator.call(env) rescue PasswordFileNotFound => e [403, {"Content-Type" => "text/plain"}, [e.]] end end |