2011-07-26 21 views
0

管理ページにアクセスするための1つのパスワードを持つPadrinoアプリを作成しました。私は承認のために次のヘルパーを使用しています。Padrinoの有効期限のないセッション

# Check if the user is authenticated. 
def authenticated?(opts = {}) 
    if session["cooly"] != options.session_secret 
    redirect url(opts[:send_to] || :login) 
    end 
end 

# Create a new session. 
def authenticate! 
    session["cooly"] ||= 0 
    session["cooly"] = options.session_secret 
end 

私のブラウザを終了すると、セッションが終了し、再度ログインする必要があります。どのようにセッションを維持するのですか?

答えて

0

に答えは無期限クッキーを作ることだった持っていることを確認します。

# Check if the user is authenticated. 
def authenticated?(opts = {}) 
    if session["cooly"] == options.session_secret || request.cookies["cooly"] == options.session_secret 
    return true 
    else 
    redirect url(opts[:send_to] || :login) 
    end 
end 

# Create a new session. 
def authenticate! 
    session["cooly"] ||= 0 
    session["cooly"] = options.session_secret 

    expiration_date = 10.year.from_now 

    response.set_cookie('cooly', :value => options.session_secret, :expires => expiration_date) 
end 
1

はアプリsession_secret

set :session_secret, 'fc29ce0f33f0c8cde13f3'

関連する問題