ruby - Sinatra and session variables which are not being set -


for reason, session variables not being set in app. using sinatra 1.2.1.

here piece of code:

module gitwiki   class app < sinatra::base      configure       enable :sessions        set :app_file, __file__       set :root, file.expand_path(file.join(file.dirname(__file__), '..', '..'))        set :auth |bool|         condition           redirect '/login' unless logged_in?         end       end     end      helpers       def logged_in?         not @user.nil?       end     end      error pagenotfound       page = request.env["sinatra.error"].name       redirect "/#{page}/edit"     end      before       content_type "text/html", :charset => "utf-8"       @user = session[:user]     end      "/login/?"       erb :login     end      post "/login"       user = user.get       if user.authenticate(params[:username], params[:password])         session[:user] = params[:username]         p session # => {:user=>"root"}       else         # aziz!  light!       end        redirect '/'     end      "/"       p session # => {}       redirect "/" + gitwiki.homepage     end      # ...    end end 

as can see, session[:user] not being set, or rather session hash being reset after each request. know going on please?

if you're using shotgun, add following line configure block:

set :session_secret, "my session secret" 

to quote rkh, sinatra's current maintainer:

[shotgun] restart server on every request, thereby regenerate session secret , invalidate sessions. has been fixed in current master. simple fix: set session_secret option.

note: fix doesn't work if use rack::session::pool


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -