Class: Ezframe::Auth
Class Attribute Summary collapse
-
.user ⇒ Object
Returns the value of attribute user.
Instance Attribute Summary collapse
-
#account ⇒ Object
Returns the value of attribute account.
-
#id ⇒ Object
Returns the value of attribute id.
-
#password ⇒ Object
Returns the value of attribute password.
-
#user ⇒ Object
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(account) ⇒ Auth
constructor
A new instance of Auth.
- #inspect ⇒ Object
Constructor Details
#initialize(account) ⇒ Auth
Returns a new instance of Auth.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/ezframe/auth.rb', line 69 def initialize(account) self.account = account auth_conf = Config[:auth] dataset = DB.dataset(auth_conf[:table]) if account.is_a?(Integer) @user = dataset.where(id: account).first else @user = dataset.where(auth_conf[:user].to_sym => account).first end unless @user EzLog.error "Auth.initialize: This user does not exist: #{account}" return end self.password = @user[auth_conf[:password].to_sym] @user.delete(:password) end |
Class Attribute Details
.user ⇒ Object
Returns the value of attribute user.
4 5 6 |
# File 'lib/ezframe/auth.rb', line 4 def user @user end |
Instance Attribute Details
#account ⇒ Object
Returns the value of attribute account.
67 68 69 |
# File 'lib/ezframe/auth.rb', line 67 def account @account end |
#id ⇒ Object
Returns the value of attribute id.
67 68 69 |
# File 'lib/ezframe/auth.rb', line 67 def id @id end |
#password ⇒ Object
Returns the value of attribute password.
67 68 69 |
# File 'lib/ezframe/auth.rb', line 67 def password @password end |
#user ⇒ Object
Returns the value of attribute user.
67 68 69 |
# File 'lib/ezframe/auth.rb', line 67 def user @user end |
Class Method Details
.authenticate(env, account, pass) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ezframe/auth.rb', line 40 def authenticate(env, account, pass) return nil if !pass || pass.strip.empty? EzLog.debug("Auth.self.authenticate: account=#{account}, pass=#{pass}") auth_conf = Config[:auth] user_data = DB.dataset(auth_conf[:table]).where(auth_conf[:user].to_sym => account ).first if user_data EzLog.info "Auth: self.authenticate: has user: #{@user}" else EzLog.info "Auth.self.authenticate: this user does not exist: #{account}" return nil end db_pass = user_data[auth_conf[:password].to_sym] user_data.delete(:password) return nil if !db_pass || db_pass.strip.length < 8 bcrypt = BCrypt::Password.new(db_pass) if bcrypt == pass env['rack.session'][:user] = user_data[:id] @user = user_data EzLog.debug("Auth.self.authenticate: success: password match!") return true else EzLog.debug("Auth.self.authenticate: failure: password mismatch") end return nil end |
.get(account) ⇒ Object
36 37 38 |
# File 'lib/ezframe/auth.rb', line 36 def get(account) new(account) end |
.init ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ezframe/auth.rb', line 6 def init Warden::Manager.serialize_into_session do |auth| # EzLog.info "serialize_into: #{auth.inspect}" auth.user[:id] end Warden::Manager.serialize_from_session do |account| # EzLog.info "serialize_from: account = #{account}" inst = Auth.get(account) # EzLog.info "inst = #{inst.inspect}" inst end Warden::Strategies.add(:mystrategy) do def valid? # EzLog.info "valid?" params["account"] || params["password"] end def authenticate! EzLog.info "mystrategy.authenticate!: user=#{user}, params=#{params}" if Auth.authenticate(env, params["account"], params["password"]) EzLog.info "mystrategy.authenticate!: success: user=#{user}" success!(Auth.get(params["account"])) else EzLog.info "mystrategy.authenticate!: failed: user=#{user}" fail!(Message[:login_failure]) end end end end |
Instance Method Details
#inspect ⇒ Object
86 87 88 |
# File 'lib/ezframe/auth.rb', line 86 def inspect "account=#{@account}, user=#{@user}, id=#{@id}" end |