Hey, I''m designing an app which displays the events near a user in RoR. I''m using the beat forum to facilitate user management/sessions/etc. I''ve edited the sessions table in the Beast database to contain a "session_location" value and what I''d like to do is to set this to the users location when they log in. This would allow them to change their location for a session whilst not changing the value in their settings. I know that I have to set this value when a session is created but I''m baffled about how (and where exactly) I have to do it. The following code is used when creating a session: class SessionsController < ApplicationController def create if using_open_id? cookies[:use_open_id] = {:value => ''1'', :expires => 1.year.from_now.utc} open_id_authentication else cookies[:use_open_id] = {:value => ''0'', :expires => 1.year.ago.utc} password_authentication params[:login], params[:password] end end protected def open_id_authentication authenticate_with_open_id params[:openid_url] do |result, openid_url| if result.successful? if self.current_user = User.find_by_openid_url(openid_url) successful_login else failed_login "Sorry, no user by the identity URL {openid_url} exists"[:openid_no_user_message, openid_url.inspect] end else failed_login result.message end end end def password_authentication(name, password) if self.current_user = User.authenticate(name, password) successful_login else failed_login "Invalid login or password, try again please."[:invalid_login_message] end end def successful_login cookies[:login_token] = {:value => "#{current_user.id};#{current_user.active_login_key}", :expires => 1.year.from_now.utc} if params[:remember_me] == "1" redirect_to CGI.unescape(params[:to] || home_path) end end If anyone could help, I''d really appreciate it. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 30 Aug 2008, at 18:23, Gearóid O''Ceallaigh <gearoid.k-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hey, > > I''m designing an app which displays the events near a user in RoR. I''m > using the beat forum to facilitate user management/sessions/etc. I''ve > edited the sessions table in the Beast database to contain a > "session_location" value and what I''d like to do is to set this to the > users location when they log in. This would allow them to change their > location for a session whilst not changing the value in their > settings. > > I know that I have to set this value when a session is created but I''m > baffled about how (and where exactly) I have to do it. The following > code is used when creating a session: >IIRC session.model is the associated database row. Fred> class SessionsController < ApplicationController > def create > if using_open_id? > cookies[:use_open_id] = {:value => ''1'', :expires => > 1.year.from_now.utc} > open_id_authentication > else > cookies[:use_open_id] = {:value => ''0'', :expires => > 1.year.ago.utc} > password_authentication params[:login], params[:password] > end > end > > protected > def open_id_authentication > authenticate_with_open_id params[:openid_url] do |result, > openid_url| > if result.successful? > if self.current_user = User.find_by_openid_url(openid_url) > successful_login > else > failed_login "Sorry, no user by the identity URL > {openid_url} exists"[:openid_no_user_message, openid_url.inspect] > end > else > failed_login result.message > end > end > end > > def password_authentication(name, password) > if self.current_user = User.authenticate(name, password) > successful_login > else > failed_login "Invalid login or password, try again > please."[:invalid_login_message] > end > end > > def successful_login > cookies[:login_token] = {:value => > "#{current_user.id};#{current_user.active_login_key}", :expires => > 1.year.from_now.utc} if params[:remember_me] == "1" > redirect_to CGI.unescape(params[:to] || home_path) > end > end > > If anyone could help, I''d really appreciate it. > >--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Riiight, could you expand on that? Thanks On Aug 30, 9:12 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 30 Aug 2008, at 18:23, Gearóid O''Ceallaigh <gearoi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > > Hey, > > > I''m designing an app which displays the events near a user in RoR. I''m > > using the beat forum to facilitate user management/sessions/etc. I''ve > > edited the sessions table in the Beast database to contain a > > "session_location" value and what I''d like to do is to set this to the > > users location when they log in. This would allow them to change their > > location for a session whilst not changing the value in their > > settings. > > > I know that I have to set this value when a session is created but I''m > > baffled about how (and where exactly) I have to do it. The following > > code is used when creating a session: > > IIRC session.model is the associated database row. > > Fred > > > class SessionsController < ApplicationController > > def create > > if using_open_id? > > cookies[:use_open_id] = {:value => ''1'', :expires => > > 1.year.from_now.utc} > > open_id_authentication > > else > > cookies[:use_open_id] = {:value => ''0'', :expires => > > 1.year.ago.utc} > > password_authentication params[:login], params[:password] > > end > > end > > > protected > > def open_id_authentication > > authenticate_with_open_id params[:openid_url] do |result, > > openid_url| > > if result.successful? > > if self.current_user = User.find_by_openid_url(openid_url) > > successful_login > > else > > failed_login "Sorry, no user by the identity URL > > {openid_url} exists"[:openid_no_user_message, openid_url.inspect] > > end > > else > > failed_login result.message > > end > > end > > end > > > def password_authentication(name, password) > > if self.current_user = User.authenticate(name, password) > > successful_login > > else > > failed_login "Invalid login or password, try again > > please."[:invalid_login_message] > > end > > end > > > def successful_login > > cookies[:login_token] = {:value => > > "#{current_user.id};#{current_user.active_login_key}", :expires => > > 1.year.from_now.utc} if params[:remember_me] == "1" > > redirect_to CGI.unescape(params[:to] || home_path) > > end > > end > > > If anyone could help, I''d really appreciate it.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 30 Aug 2008, at 22:13, Gearóid O''Ceallaigh <gearoid.k-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Riiight, could you expand on that? Thanks >Not much to say really - if the session is stored in the database with activerecordstore then session.model is the activerecord object for the corresponding row in the sessions table Fred> On Aug 30, 9:12 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> On 30 Aug 2008, at 18:23, Gearóid O''Ceallaigh <gearoi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> wrote: >> >> >> >>> Hey, >> >>> I''m designing an app which displays the events near a user in RoR. >>> I''m >>> using the beat forum to facilitate user management/sessions/etc. >>> I''ve >>> edited the sessions table in the Beast database to contain a >>> "session_location" value and what I''d like to do is to set this to >>> the >>> users location when they log in. This would allow them to change >>> their >>> location for a session whilst not changing the value in their >>> settings. >> >>> I know that I have to set this value when a session is created but >>> I''m >>> baffled about how (and where exactly) I have to do it. The following >>> code is used when creating a session: >> >> IIRC session.model is the associated database row. >> >> Fred >> >>> class SessionsController < ApplicationController >>> def create >>> if using_open_id? >>> cookies[:use_open_id] = {:value => ''1'', :expires => >>> 1.year.from_now.utc} >>> open_id_authentication >>> else >>> cookies[:use_open_id] = {:value => ''0'', :expires => >>> 1.year.ago.utc} >>> password_authentication params[:login], params[:password] >>> end >>> end >> >>> protected >>> def open_id_authentication >>> authenticate_with_open_id params[:openid_url] do |result, >>> openid_url| >>> if result.successful? >>> if self.current_user = User.find_by_openid_url(openid_url) >>> successful_login >>> else >>> failed_login "Sorry, no user by the identity URL >>> {openid_url} exists"[:openid_no_user_message, openid_url.inspect] >>> end >>> else >>> failed_login result.message >>> end >>> end >>> end >> >>> def password_authentication(name, password) >>> if self.current_user = User.authenticate(name, password) >>> successful_login >>> else >>> failed_login "Invalid login or password, try again >>> please."[:invalid_login_message] >>> end >>> end >> >>> def successful_login >>> cookies[:login_token] = {:value => >>> "#{current_user.id};#{current_user.active_login_key}", :expires => >>> 1.year.from_now.utc} if params[:remember_me] == "1" >>> redirect_to CGI.unescape(params[:to] || home_path) >>> end >>> end >> >>> If anyone could help, I''d really appreciate it. > >--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---