Ruby on Rails Sunday, August 24, 2014

On 24 August 2014 17:32, Bharath Neo <lists@ruby-forum.com> wrote:
> Colin Law wrote in post #1155762:
>> On 23 August 2014 06:32, Bharath Neo <lists@ruby-forum.com> wrote:
>>> The problem is that I want to hold sessions who have not logged out. And
>>> clear sessions who have not logged in. Sessions are created
>>> automatically by rails when the login page loads itself.
>>
>> Sorry, don't understand. Can you clarify what you mean by 'logged
>> out'? I assumed you meant users that have clicked on the 'logout'
>> link.
>>
>> Colin
>
> Okie. This is what I see from how its happening:
>
> 1. There is a login page
> 2. When login page is loaded I see an entry for a session put in.

What do you mean by 'loading' the login page? The code you posted
shows the session being created in session create, which is presumably
as a result of posting the login form, not displaying. It is up to
you what code you put there.

>
> +-----+----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+---------------------+---------------------+
> | id | session_id | data
> | created_at | updated_at |
> +-----+----------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+---------------------+---------------------+
> | 172 | 683aeb1fec89147c16db6ffb8614d915 |
> BAh7BiIQX2NzcmZfdG9rZW4iMUVNN1ZVSSt6cGdMaTdRT1RycjhuVTlkWHMr
> M1RyYzZyZUpYaEh5eE93VDQ9
>
> 3. When someone logs in successfully, I set the user_id value in the
> session variable. Right then I see that the sql record has the value in
> "data" variable changed.
>
> session[:user_id] = params[:email]
>
> 4. When someone logs out, I clear the value and call reset_session.
> Again I see the sql record has the "data" variable with changed value.
>
> session[:user_id] = nil
> reset_session
>
> Hence the problem is:
> 1. Can't I ensure a session record is created only when I want - After
> the user logs in ?

When a user logs in check whether they already have an active session
and if so restore that one and remove the new one (or even better
don't save it). If there is nothing stored in the session other than
the fact that they have logged in then you can just delete any old
ones for that user.

Colin

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLvfH3GdzO%2By1F%2BK%3Du8BOF1Kjcd8rWYvsnobu6-pLB90hQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment