Class: Ezframe::Auth
Class Attribute Summary collapse
-
.model ⇒ Object
Returns the value of attribute model.
-
.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.
-
#model ⇒ Object
Returns the value of attribute model.
-
#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(model, account) ⇒ Auth
constructor
A new instance of Auth.
Constructor Details
#initialize(model, account) ⇒ Auth
Returns a new instance of Auth.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ezframe/auth.rb', line 61 def initialize(model, account) self.account = account dataset = model.db.dataset(Config[:login_table]) if account.is_a?(Integer) @user = dataset.where(id: account).first else @user = dataset.where(Config[:login_account].to_sym => account).first end unless @user mylog "Auth.initialize: This user does not exist: #{account}" end self.password = @user[:password] @user.delete(:password) end |
Class Attribute Details
.model ⇒ Object
Returns the value of attribute model.
4 5 6 |
# File 'lib/ezframe/auth.rb', line 4 def model @model end |
.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.
59 60 61 |
# File 'lib/ezframe/auth.rb', line 59 def account @account end |
#id ⇒ Object
Returns the value of attribute id.
59 60 61 |
# File 'lib/ezframe/auth.rb', line 59 def id @id end |
#model ⇒ Object
Returns the value of attribute model.
59 60 61 |
# File 'lib/ezframe/auth.rb', line 59 def model @model end |
#password ⇒ Object
Returns the value of attribute password.
59 60 61 |
# File 'lib/ezframe/auth.rb', line 59 def password @password end |
#user ⇒ Object
Returns the value of attribute user.
59 60 61 |
# File 'lib/ezframe/auth.rb', line 59 def user @user end |
Class Method Details
.authenticate(env, account, pass) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ezframe/auth.rb', line 39 def authenticate(env, account, pass) model = env["model"] raise "model is not initialized" unless model @user = model.db.dataset(Config[:login_table]).where(Config[:login_account].to_sym => account ).first if @user mylog "Auth: authenticate: user=#{@user.inspect}" else mylog "authenticate: this user does not exist: #{account}" return nil end mylog "env=#{env.inspect}" env['rack.session'][:user] = @user[:id] password = @user[:password] @user.delete(:password) return nil if !pass || !password !!(password == pass) end |
.get(model, account) ⇒ Object
35 36 37 |
# File 'lib/ezframe/auth.rb', line 35 def get(model, account) new(model, account) end |
.init_warden ⇒ 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 |
# File 'lib/ezframe/auth.rb', line 6 def init_warden Warden::Manager.serialize_into_session do |auth| mylog "serialize_into: #{auth.inspect}" auth.user[:id] end Warden::Manager.serialize_from_session do |account| mylog "serialize_from: account = #{account}" inst = Auth.get(env['model'], account) mylog "inst = #{inst.inspect}" inst end Warden::Strategies.add(:mystrategy) do def valid? # mylog "valid?" params["account"] || params["password"] end def authenticate! mylog "authenticate!: #{params}" if Auth.authenticate(env, params["account"], params["password"]) success!(Auth.get(env['model'], params["account"])) else env['x-rack.flash'].error = 'ユーザーが登録されていないか、パスワードが違っています。' fail!("authenticate failure") end end end end |