shaselai
2008-Jun-19 05:40 UTC
How to setup a Session and use its data from other classes?
I am trying to do an authentication where I have : session["User"] = User.authenticate(@params["name"], @params["password"]) and the program continues on if the authentication is correct. Now if later on in the session I want to access "User"''s data (using active directory) I try to use: if session["User"].id == 0 //do something else //do something else Now I always get id =0 so i must have set the session wrong or not at all? Here is how i do the authentication: if session["User"] = User.authenticate(@params["name"], @params["password"]) if session["return_to"] redirect_to_path(session["return_to"]) session["return_to"] = nil else redirect_to :controller => "NewController" end else flash[:error] = ''Invalid user name and/or password.'' redirect_to :action => "index" end I try to use session["User"] elsewhere to get data but no good. Can someone help? thanks! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ar Chron
2008-Jun-19 13:28 UTC
Re: How to setup a Session and use its data from other class
First question is "Does your User.authenticate return a user object to be stored in session?" From the sparse look we have at the code, that''s where I''d be looking first... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
shaselai
2008-Jun-19 13:49 UTC
Re: How to setup a Session and use its data from other class
No, the User.authenticate does : User.find(first,....) to check for user authentication. How do I return the object? with this way? sorry i am bit new at this.... thanks! On Jun 19, 9:28 am, Ar Chron <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> First question is "Does your User.authenticate return a user object to > be stored in session?" > > From the sparse look we have at the code, that''s where I''d be looking > first... > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
shaselai
2008-Jun-19 14:33 UTC
Re: How to setup a Session and use its data from other class
it also seems the ID is 0,1 and apparently in ruby that is true/false class... so after I set the session correctly do I just do : if session["User"].id == true //do something else //etc... ? On Jun 19, 9:49 am, shaselai <shase...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> No, the User.authenticate does : > User.find(first,....) to check for user authentication. How do I > return the object? with this way? sorry i am bit new at this.... > thanks! > > On Jun 19, 9:28 am, Ar Chron <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > > First question is "Does your User.authenticate return a user object to > > be stored in session?" > > > From the sparse look we have at the code, that''s where I''d be looking > > first... > > -- > > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---