Hello, I am new in using Rails. I want to implement a login system. I got this error: stack level too deep I have following methods: signup login thanks a lot for your help -- 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 -~----------~----~----~----~------~----~------~--~---
It''s hard to tell without looking at your code, but I''m guessing that you''re getting some sort of recursive function call; make sure that your before_filter is calling what it''s supposed to. Hamid wrote:> Hello, > > I am new in using Rails. > I want to implement a login system. > I got this error: stack level too deep > > I have following methods: > signup > login > > thanks a lot for your help-- 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 -~----------~----~----~----~------~----~------~--~---
jimtron wrote:> It''s hard to tell without looking at your code, but I''m guessing that > you''re getting some sort of recursive function call; make sure that your > before_filter is calling what it''s supposed to. > > Hamid wrote: >> Hello, >> >> I am new in using Rails. >> I want to implement a login system. >> I got this error: stack level too deep >> >> I have following methods: >> signup >> login >> >> thanks a lot for your helpHello this is my code: thank you class SecuredController < ApplicationController before_filter :authorize, :except => :login def login case @request.method when :post if @session[:person] = Person.authenticate( @params[:person_name], params[:person_password]) flash[''notice''] = "Anmeldung erfolgreich" #redirect_back_or_default :action => :signup #redirect_to :action => "welcome" @name = @params[:person_name] end end end def signup @person = Person.new(@params[:person]) if @request.post? and @person.save @session[:person] = Person.authenticate( @person.name, @params[:person][:password]) flash[''notice''] = "Registrierung erfolgreich" redirect_back_or_default :action => "welcome" #redirect_to :action => "welcome" end end def logout @session[:person] = nil end def welcome end end -- 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 -~----------~----~----~----~------~----~------~--~---
Abdelhamid Najah wrote:> jimtron wrote: >> It''s hard to tell without looking at your code, but I''m guessing that >> you''re getting some sort of recursive function call; make sure that your >> before_filter is calling what it''s supposed to. >> >> Hamid wrote: >>> Hello, >>> >>> I am new in using Rails. >>> I want to implement a login system. >>> I got this error: stack level too deep >>> >>> I have following methods: >>> signup >>> login >>> >>> thanks a lot for your help > > Hello > this is my code: > thank you > > class SecuredController < ApplicationController > before_filter :authorize, :except => :login > def login > case @request.method > when :post > if @session[:person] = Person.authenticate( @params[:person_name], > params[:person_password]) > flash[''notice''] = "Anmeldung erfolgreich" > #redirect_back_or_default :action => :signup > #redirect_to :action => "welcome" > @name = @params[:person_name] > end > end > end > > def signup > @person = Person.new(@params[:person]) > > if @request.post? and @person.save > @session[:person] = Person.authenticate( @person.name, > @params[:person][:password]) > flash[''notice''] = "Registrierung erfolgreich" > redirect_back_or_default :action => "welcome" > #redirect_to :action => "welcome" > end > end > > def logout > @session[:person] = nil > end > > def welcome > end > > endthe model person it looks like: require ''digest/sha1'' class Person < ActiveRecord::Base validates_presence_of :name validates_uniqueness_of :name attr_accessor :password_confirmation validates_confirmation_of :password def validate errors.add_to_base("Missing password") if hashed_password.blank? end def self.authenticate(name, password) person = self.find_by_name(name) if person expected_password = encrypted_password(password, person.salt) if person.hashed_password != expected_password person = nil end end end # # ''password'' is a virtual attribute def password @password end def password=(pwd) @password = pwd return if pwd.blank? create_new_salt #self.hashed_password = Person.encrypted_password(self.password, self.salt) self.password = Person.encrypted_password(self.password, self.salt) end def create_new_salt self.salt = self.object_id.to_s + rand.to_s end private def self.encrypted_password(password, salt) string_to_hash = password + "wibble" + salt # ''wibble'' makes it harder to guess Digest::SHA1.hexdigest(string_to_hash) end @@salt = ''[ioaruoagr]'' cattr_accessor :salt end -- 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 -~----------~----~----~----~------~----~------~--~---
def password=(pwd) @password = pwd return if pwd.blank? create_new_salt #self.hashed_password = Person.encrypted_password(self.password, self.salt) self.password = Person.encrypted_password(self.password, self.salt) end This method is calling itself on the last line. Right before the final "end." It will continue to do this until it runs out of stack space and your program crashes. On Jun 2, 6:15 pm, Abdelhamid Najah <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Abdelhamid Najah wrote: > > jimtron wrote: > >> It''s hard to tell without looking at your code, but I''m guessing that > >> you''re getting some sort of recursive function call; make sure that your > >> before_filter is calling what it''s supposed to. > > >> Hamid wrote: > >>> Hello, > > >>> I am new in using Rails. > >>> I want to implement a login system. > >>> I got this error: stack level too deep > > >>> I have following methods: > >>> signup > >>> login > > >>> thanks a lot for your help > > > Hello > > this is my code: > > thank you > > > class SecuredController < ApplicationController > > before_filter :authorize, :except => :login > > def login > > case @request.method > > when :post > > if @session[:person] = Person.authenticate( @params[:person_name], > > params[:person_password]) > > flash[''notice''] = "Anmeldung erfolgreich" > > #redirect_back_or_default :action => :signup > > #redirect_to :action => "welcome" > > @name = @params[:person_name] > > end > > end > > end > > > def signup > > @person = Person.new(@params[:person]) > > > if @request.post? and @person.save > > @session[:person] = Person.authenticate( @person.name, > > @params[:person][:password]) > > flash[''notice''] = "Registrierung erfolgreich" > > redirect_back_or_default :action => "welcome" > > #redirect_to :action => "welcome" > > end > > end > > > def logout > > @session[:person] = nil > > end > > > def welcome > > end > > > end > > the model person it looks like: > > require ''digest/sha1'' > > class Person < ActiveRecord::Base > > validates_presence_of :name > validates_uniqueness_of :name > > attr_accessor :password_confirmation > validates_confirmation_of :password > > def validate > errors.add_to_base("Missing password") if hashed_password.blank? > end > > def self.authenticate(name, password) > person = self.find_by_name(name) > if person > expected_password = encrypted_password(password, person.salt) > if person.hashed_password != expected_password > person = nil > end > end > end > # > # ''password'' is a virtual attribute > def password > @password > end > > def password=(pwd) > @password = pwd > return if pwd.blank? > create_new_salt > #self.hashed_password = Person.encrypted_password(self.password, > self.salt) > self.password = Person.encrypted_password(self.password, self.salt) > end > > def create_new_salt > self.salt = self.object_id.to_s + rand.to_s > end > > private > > def self.encrypted_password(password, salt) > string_to_hash = password + "wibble" + salt # ''wibble'' makes it harder > to guess > Digest::SHA1.hexdigest(string_to_hash) > end > > @@salt = ''[ioaruoagr]'' > cattr_accessor :salt > > end > > -- > 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 -~----------~----~----~----~------~----~------~--~---