merb-auth-slice-activation
は、merbでemailアクティベーションを簡単に実装するための非常に便利なSliceです。
このSliceは、merb-auth-coreが提供するhookである、after_authenticationをフックする事によって、アクティベーションが済んでいないアカウントでのログインをブロックする仕様になっています。該当するコードは以下の通り。

merb-auth-slice-activation/lib/merb-auth-slice-activation.rb

ruby>>
# Initialization hook - runs before AfterAppLoads BootLoader
def self.init
# Actually check if the user is active
::Merb::Authentication.after_authentication do |user, *rest|
if user.respond_to?(:active?)
user.active? ? user : nil
else
user
end
end
end
<<--

ただ、この実装では、ログインに失敗した場合に何のエラーメッセージも表示されないため、以下のようにExceptionsコントローラにコードを加え、エラーメッセージを表示するようにしてみます。

ruby>>
class Exceptions < Merb::Controller
(snip)
def unauthenticated
request.exceptions.each do |e|
session.authentication.errors.add(:general, e.message)
end if request.exceptions
render :format => :html
end
end
<<--

Merbでは、アクションの実行中に例外が発生した場合、Exceptionsコントローラに処理が回ってきます。その場合、発生した例外オブジェクトは、request.exceptionsで参照出来ます。

あとは、view側で

rails>>
<%= error_messages_for session.authentication %>
<<--

を記述すればOK.

posted by genki genki on Thu 1 Jan 2009 at 21:22 with 0 comments
Contents rssrss
光ファイバーを二次元振動させて走査するAR用ディスプレイ
因果の取り違え
Swift2's defer for CoffeeScript
mongodb-3.0からcreateIndexのdropDupsが無くなったらしい
mongodb-3.0以降のWiredTigerの設定を動的に変更する方法
一般楕円の高速生成アルゴリズムへの道標
farro mantecatoのレシピ
Droonga関連の記事のまとめ
RuntimeErrorの特定のメッセージに限定してrescueする方法
jQueryでscriptタグを実行せずにappendする
Tags
coffeescriptdefergroongajsmemonodenodejs
Comments rssrss
https://fromkorea.peoplead.kr/bbs/board.php?bo_table=free&wr_id=72875 https://fromkorea.peoplead.kr/bbs/board.php?bo_table=free&wr_id=72875: Nice blog. I liked reading. Many thanks for the in... 04/24 06:13
https://Xn--Mgmarkt8-9DB.Com/ https://Xn--Mgmarkt8-9DB.Com/: Что выбрать: Tor или VPN для безопасного MEGA? ... 04/24 01:57
https://buy-property-uae.com/ https://buy-property-uae.com/: Real estate experts are convinced, that buying pro... 04/24 00:16
https://buy-property-uae.com/ https://buy-property-uae.com/: Real estate experts are convinced, that acquiring ... 04/24 00:16
https://xn--mgmarkt9-9db.com https://xn--mgmarkt9-9db.com: Как проверить целостность ссылок MEGA: защита от ... 04/23 22:08
https://xn--mgmarkt6-9db.com https://xn--mgmarkt6-9db.com: Как обезопасить хранилище криптовалюты: сравнение... 04/23 20:02
https://www.lifnest.com/author/bradwhiddon136/ https://www.lifnest.com/author/bradwhiddon136/: Лучший bulk index checker из тех, что я пробовал... 04/23 10:21
https://mklider.ru/katalog/protivopozharnoe-oborudovanie/predohranitel-ognevoy-zhidkostnyy-pozh/ https://mklider.ru/katalog/protivopozharnoe-oborudovanie/predohranitel-ognevoy-zhidkostnyy-pozh/: За многие годы работы по производству резервуаров ... 04/23 10:05