Permalink
Browse files

認証セッション続ける事を考えてメソッドを細かくした

  • Loading branch information...
1 parent a49efcd commit 840dddae3ac5d243b1b416528fda411387e02648 @mashiro committed Apr 13, 2012
Showing with 18 additions and 14 deletions.
  1. +18 −14 lib/rlyeh/deep_ones/auth.rb
@@ -28,13 +28,17 @@ def authenticated?
@authenticated
end
- def authenticate!(env, auth)
- @authenticator.call self
+ def authenticate!(env)
+ if @authenticator && @authenticator.call(self)
+ succeeded env
+ else
+ failed env
+ end
end
- def succeeded(env, id)
+ def succeeded(env)
@authorized = true
- session = load_session env, id
+ session = load_session env, to_session_id
session.attach env.connection
name = env.settings.server_name
@@ -49,13 +53,20 @@ def succeeded(env, id)
messages.each do |type, message|
env.connection.send_numeric_reply type, @host, message
end
+
+ debug(env) { "Succeeded #{env.connection.host}:#{env.connection.port}" }
end
def failed(env)
+ debug(env) { "Failed #{env.connection.host}:#{env.connection.port}" }
+ end
+
+ def to_session_id
+ @nick
end
- def load_session(env, id)
- env.server.sessions[id] ||= Rlyeh::Session.new(id)
+ def load_session(env, session_id)
+ env.server.sessions[session_id] ||= Rlyeh::Session.new(session_id)
end
on :pass do |env|
@@ -70,14 +81,7 @@ def load_session(env, id)
@user = env.message.params[0]
@real = env.message.params[3]
@host = env.connection.host
-
- if (id = authenticate!(env, self))
- succeeded env, id
- debug(env) { "Succeeded #{env.connection.host}:#{env.connection.port}" }
- else
- failed env
- debug(env) { "Failed #{env.connection.host}:#{env.connection.port}" }
- end
+ authenticate! env
end
end
end

0 comments on commit 840ddda

Please sign in to comment.