Hello. I would like to create a loggin system. I have a players model with name and passwd. Then, I would like to put the player item in the session. When I try to loggin, it create a player, so, I''m kind of lost here : login_controller.rb : class LoginController < ApplicationController def index if request.get? session[:current_user]=nil @Player = Player.new else @Player = Player.new(params[:player]) logged_in_user = @Player.try_to_login if logged_in_user session[:current_user]=logged_in_user else flash[:notice] = "Utilisateur invalide" end end end end player.rb class Player < ActiveRecord::Base has_one :accessory has_many :possessions has_many :games, :through =>:possessions, :select => "possessions.user_notation, possessions.user_comment, games.*" def self.login (name, password) find(:first, :conditions => ["name = ? and password = ?", name, password]) end def try_to_loggin Player.login(self.name, self.password) end end index.html.erb in login <% form_for(@Player) do |f| %> <%= f.error_messages %> <p> <%= f.text_field :name %> </p> <p> <%= f.text_field :password %> </p> <p> <%= f.submit "Login" %> </p> <% end %> Any ideas ? Link that can 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 -~----------~----~----~----~------~----~------~--~---
Use something like restful_authentication http://github.com/technoweenie/restful_authentication ----- Ryan Bigg Freelancer http://frozenplague.net On 04/01/2009, at 8:57 PM, Sobert wrote:> > Hello. > > I would like to create a loggin system. I have a players model with > name and passwd. Then, I would like to put the player item in the > session. > > When I try to loggin, it create a player, so, I''m kind of lost here : > > login_controller.rb : > > class LoginController < ApplicationController > def index > if request.get? > session[:current_user]=nil > @Player = Player.new > else > @Player = Player.new(params[:player]) > logged_in_user = @Player.try_to_login > if logged_in_user > session[:current_user]=logged_in_user > else > flash[:notice] = "Utilisateur invalide" > end > end > end > end > > > > > player.rb > > class Player < ActiveRecord::Base > has_one :accessory > has_many :possessions > has_many :games, :through =>:possessions, :select => > "possessions.user_notation, possessions.user_comment, games.*" > > def self.login (name, password) > find(:first, :conditions => ["name = ? and password = ?", name, > password]) > end > > def try_to_loggin > Player.login(self.name, self.password) > end > > end > > > index.html.erb in login > > <% form_for(@Player) do |f| %> > <%= f.error_messages %> > <p> > <%= f.text_field :name %> > </p> > <p> > <%= f.text_field :password %> > </p> > <p> > <%= f.submit "Login" %> > </p> > <% end %> > > Any ideas ? Link that can 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 -~----------~----~----~----~------~----~------~--~---
There''s no way of doing it simply ? Because I''m kind of new in Ror, and I''d like to work this out with only the basics. On 4 jan, 12:34, Ryan Bigg <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Use something like restful_authenticationhttp://github.com/technoweenie/restful_authentication > ----- > Ryan Bigg > Freelancerhttp://frozenplague.net > > On 04/01/2009, at 8:57 PM, Sobert wrote: > > > > > > > Hello. > > > I would like to create a loggin system. I have a players model with > > name and passwd. Then, I would like to put the player item in the > > session. > > > When I try to loggin, it create a player, so, I''m kind of lost here : > > > login_controller.rb : > > > class LoginController < ApplicationController > > def index > > if request.get? > > session[:current_user]=nil > > @Player = Player.new > > else > > @Player = Player.new(params[:player]) > > logged_in_user = @Player.try_to_login > > if logged_in_user > > session[:current_user]=logged_in_user > > else > > flash[:notice] = "Utilisateur invalide" > > end > > end > > end > > end > > > player.rb > > > class Player < ActiveRecord::Base > > has_one :accessory > > has_many :possessions > > has_many :games, :through =>:possessions, :select => > > "possessions.user_notation, possessions.user_comment, games.*" > > > def self.login (name, password) > > find(:first, :conditions => ["name = ? and password = ?", name, > > password]) > > end > > > def try_to_loggin > > Player.login(self.name, self.password) > > end > > > end > > > index.html.erb in login > > > <% form_for(@Player) do |f| %> > > <%= f.error_messages %> > > <p> > > <%= f.text_field :name %> > > </p> > > <p> > > <%= f.text_field :password %> > > </p> > > <p> > > <%= f.submit "Login" %> > > </p> > > <% end %> > > > Any ideas ? Link that can help ? Thanks !- Masquer le texte des messages précédents - > > - Afficher le texte des messages précédents ---~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ok, I''ve finally found this http://codingbitch.com/p/comboy/User+authentication+in+Ruby+on+Rails Adapting this is fine. On 4 jan, 12:43, Sobert <sok...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> There''s no way of doing it simply ? Because I''m kind of new in Ror, > and I''d like to work this out with only the basics. > > On 4 jan, 12:34, Ryan Bigg <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Use something like restful_authenticationhttp://github.com/technoweenie/restful_authentication > > ----- > > Ryan Bigg > > Freelancerhttp://frozenplague.net > > > On 04/01/2009, at 8:57 PM, Sobert wrote: > > > > Hello. > > > > I would like to create a loggin system. I have a players model with > > > name and passwd. Then, I would like to put the player item in the > > > session. > > > > When I try to loggin, it create a player, so, I''m kind of lost here : > > > > login_controller.rb : > > > > class LoginController < ApplicationController > > > def index > > > if request.get? > > > session[:current_user]=nil > > > @Player = Player.new > > > else > > > @Player = Player.new(params[:player]) > > > logged_in_user = @Player.try_to_login > > > if logged_in_user > > > session[:current_user]=logged_in_user > > > else > > > flash[:notice] = "Utilisateur invalide" > > > end > > > end > > > end > > > end > > > > player.rb > > > > class Player < ActiveRecord::Base > > > has_one :accessory > > > has_many :possessions > > > has_many :games, :through =>:possessions, :select => > > > "possessions.user_notation, possessions.user_comment, games.*" > > > > def self.login (name, password) > > > find(:first, :conditions => ["name = ? and password = ?", name, > > > password]) > > > end > > > > def try_to_loggin > > > Player.login(self.name, self.password) > > > end > > > > end > > > > index.html.erb in login > > > > <% form_for(@Player) do |f| %> > > > <%= f.error_messages %> > > > <p> > > > <%= f.text_field :name %> > > > </p> > > > <p> > > > <%= f.text_field :password %> > > > </p> > > > <p> > > > <%= f.submit "Login" %> > > > </p> > > > <% end %> > > > > Any ideas ? Link that can help ? Thanks !- Masquer le texte des messages précédents - > > > - Afficher le texte des messages précédents -- Masquer le texte des messages précédents - > > - Afficher le texte des messages précédents ---~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---