Stack level too deep

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

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

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

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 N. [email protected]

Abdelhamid N. 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