Hello all,

i am working on login module of application i have the method defined in 
Model and calling it from controller but the error says no method defined 
in controller below are model and controller code
 class AuthenticationController < ApplicationController
def sign_in
    @user = User.new
    end

  def login
  
    username_or_email = params[:user][:username]
    password = params[:user][:password]

    if username_or_email.rindex('@')
      email=username_or_email
      user = User.authenticate_by_email(email, password)
    else
      username=username_or_email
      user = User.authenticate_by_username(username, password)
    end

    if user
      flash[:notice] = 'Welcome.'
      redirect_to :root
    else
       flash.now[:error] = 'Unknown user. Please check your username and 
password.'
       render :action => "sign_in"
    end

  end
end
For model
def self.authenticate_by_email(email, password)
  user = find_by_email(email)
  if user && user.password_hash == BCrypt::Engine.hash_secret(password, 
user.password_salt)
    user
  else
    nil
  end
end
# Autentication by username
def self.authenticate_by_username(username, password)
  user = find_by_username(username)
  if user && user.password_hash == BCrypt::Engine.hash_secret(password, 
user.password_salt)
    user
  else
    nil
  end
end

Kindly help ASAP

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/0761eb10-03ce-4dbc-88d3-f5dc0cf50a7f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to