Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Rails 3 session generator
class SessionCookieGenerator
def self.generate user_obj
new(user_obj).generate
end
def initialize user_obj
@user = user_obj
@cookie = {}
@session = {'rack.session' => {}}
end
def generate
warden_session = Warden::SessionSerializer.new(@session)
warden_session.store(@user, :admin_user)
@cookie['warden.user.admin_user.key'] = @session['rack.session']['warden.user.admin_user.key']
session_secret = App::Application.config.secret_token
verifier = ActiveSupport::MessageVerifier.new(session_secret, digest: 'SHA1')
verifier.generate @cookie.merge(session_id: SecureRandom.hex(16))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment