Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to configure sessions #2

Closed
jodosha opened this issue Jun 12, 2014 · 9 comments · Fixed by #57
Closed

Allow to configure sessions #2

jodosha opened this issue Jun 12, 2014 · 9 comments · Fixed by #57
Assignees
Milestone

Comments

@jodosha
Copy link
Member

jodosha commented Jun 12, 2014

A Lotus application should provide an API to enable sessions and to allow developers to set options for it. This should take advantage of the middleware configuration (#40).

Proposal:

module Bookshelf
  class Application < ::Lotus::Application
    configure do
      sessions true

      middleware.use Rack::Session::Redis,
        domain: 'foo.com',
        expire_after: 2592000
    end
  end
end

Please note that sessions true should enable sessions, by including Lotus::Action::Sessions into Bookshelf::Action taking advantage of Lotus::Controller::Configuration#modules.

The ideal place where this should happen is at the load time.

Alternative proposal:

module Bookshelf
  class Application < ::Lotus::Application
    configure do
      sessions :redis,
        domain: 'foo.com',
        expire_after: 2592000
    end
  end
end

This should:

  1. Enable sessions with the same mechanisms above
  2. Lookup for a Rack::Session::Redis middleware and add it with middleware.use

This is alternative is nicer, because it hides the internal requirements of the framework (see sessions true above). On the other hand, we're introducing a convention: :redis => Rack::Session::Redis. I'd make #sessions to accept also a class (name). Example sessions MySessionStore and/or sessions 'MySessionStore'.

@mistersourcerer
Copy link

Hy @jodosha, can you provide some more context on what do you need here?

@jodosha
Copy link
Member Author

jodosha commented Jul 9, 2014

@ricardovaleriano I've updated the description of this ticket with a design proposal.

@simi
Copy link
Contributor

simi commented Jul 9, 2014

@jodosha what would session true do? For example in sinatra, similar code is adding Rack::Session::Cookie with given params (for example secret key) to middleware stack.

Now it looks like two session middlewares will be used at the same time for your example.

@jodosha
Copy link
Member Author

jodosha commented Jul 9, 2014

@simi from the description:

Please note that sessions true should enable sessions, by including Lotus::Action::Sessions into Bookshelf::Action taking advantage of Lotus::Controller::Configuration#modules.

I'm gonna rethink the proposal, the actual is verbose because of the framework internals.

@simi
Copy link
Contributor

simi commented Jul 9, 2014

Damn, I should try to read better.

Anyway, session true is providing only session method for Lotus::Action now. You need to use some session storage middleware always. Can you confirm this?

@jodosha
Copy link
Member Author

jodosha commented Jul 9, 2014

@simi I confirm. please have a look at the updated proposal.

@mistersourcerer
Copy link

Nice @jodosha, thank you for the clarification.

@michalmuskala
Copy link
Contributor

Is anybody doing something about this issue? If not I'd like to help with this.

@gotjosh
Copy link
Contributor

gotjosh commented Jul 16, 2014

It's assigned to me but I have plans to work on it over the weekend or by the end of the week. If you'd like to take it for spin and you'll have it completed sooner then I don't mind at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants