ruby - "Remember me" option - how do I implement it? -


i have simple authentication system in sinatra application. it's set session[:user_id] user's id when user enters correct login , password , that's it. enough now, won't use solutions.

what need make "remember me" option. how can simple solution? can't figure out.

the way i've done (we're using omniauth authentication , mongoid user storage - login form uses ajax reply json). html field corresponds "remember me" checkbox called "remember":

post '/auth/identity/callback'   u = user.find(env['omniauth.auth']['uid'])   session[:user] = u   session.options[:expire_after] = 2592000 unless params['remember'].nil? # 30 days   [200, {:msg => 'user logged in'}.to_json] end 

the key here sessions.options[:expire_after] line. if don't set :expire_after, cookie automatically deleted when browser quits. once set it, cookie becomes persisten across browser restarts, , kept number of seconds specified.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -