merb-auth-
merb-auth-
1 # Initialization hook - runs before AfterAppLo ads BootLoader 2 def self.init 3 # Actually check if the user is active 4 ::Merb::Authentica tion.after_auth entication do |user, *rest| 5 if user.respond_to ?(:active?) 6 user.active? ? user : nil 7 else 8 user 9 end 10 end 11 end
ただ、この実装では、ログインに失敗した場合に何のエラーメッセージも表示されないため、以下のようにExceptions
1 class Exceptions< Merb::Cont roller 2 (snip) 3 def unauthenti cated 4 request.exceptions .each do |e| 5 session.authentica tion.errors.add(:general, e.message) 6 end if request.exceptions 7 render :format => :html 8 end 9 end
Merbでは、アクションの実行中に例外が発生した場合、Exceptionsrequest.ex
で参照出来ます。
あとは、view側で
1 <%= error_messages_for session.authentica tion %>
を記述すればOK.
posted by
genki
on Thu 1 Jan 2009
at 21:31