「アクティブ化」される前、または電子メール/パスワードでログインできるようになる前に、ユーザーにアクティブ化リンクをクリックしてもらいたいです。
私は宝石を使用していないので、そのままにしておきたいです。私の問題は、ユーザーが登録した後、アクティベーション コードをクリックせずにログインできることです。モデルへの Confirmation_token 行と Confirmed 行があります。
ユーザーコントローラー:
def create
@user = User.new(params[:user])
if @user.save
render "root_path"
else
render "new"
end
end
def confirmed
user = User.find(:first, :conditions => {:confirmation_token => params[:confirmation_token]})
if (!params[:confirmation_token].blank?) && user && !user.confirmed?
user.confirmed!
self.current_user = user
flash[:notice] = "Thank you. You account is now activated."
redirect_to account_preference_path(current_user)
else
flash[:notice] = "Sorry we don't have your email in our database."
redirect_to root_path
end
終わり
ユーザーモデル:
def confirmed!
self.confirmed = true
self.confirmation_token = nil
save(false)
end
何か不足していますか?ありがとう!
devise や auth-logic などの gem があることは知っていますが、それをゼロから作成する方法を学びたいと思っています。ありがとう。
編集:
セッションコントローラー
def create
user = User.authenticate(params[:email], params[:password])
if user && user.confirmed == true
cookies.permanent.signed[:remember_token]
redirect_to account_path(user.id), :notice => "Welcome, #{user.first_name}"
else
flash.now.alert = "Invalid email or password."
render "new"
end
end