Class: Fir::AdminAuth
- Inherits:
-
Rack::Auth::Basic
- Object
- Rack::Auth::Basic
- Fir::AdminAuth
- Includes:
- AdminMiddleware
- Defined in:
- lib/fir/admin.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(*args) ⇒ AdminAuth
constructor
A new instance of AdminAuth.
Methods included from AdminMiddleware
Constructor Details
#initialize(*args) ⇒ AdminAuth
Returns a new instance of AdminAuth.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/fir/admin.rb', line 11 def initialize(*args) super if File.exists?('users.yml') @users = YAML::load(File.read('users.yml')) @users = {} unless @users.is_a?(Hash) # In case of an invalid YAML file else @users = {} end @authenticator = lambda do |username, password| if @users[username] salt = @users[username]['salt'] expected = @users[username]['crypted_password'] actual = Fir.encrypt_password(password, salt) expected == actual else false end end end |
Instance Method Details
#call(env) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/fir/admin.rb', line 31 def call(env) if admin_path?(env) super(env) else @app.call(env) end end |