TJ Stankus wrote:
Perhaps :except => :signin instead of :except => [:signin]
Hi,
Tried that one, but it didn’t help. The application trace says:
Username or password invalid
RAILS_ROOT: ./script/…/config/…
Application Trace | Framework Trace | Full Trace
#{RAILS_ROOT}/app/models/user.rb:19:in authenticate' #{RAILS_ROOT}/app/controllers/admin_controller.rb:19:insignin’
It does look like it is going through authentication, even given the
advice not to. Here’s the controller:
class AdminController < ApplicationController
before_filter :check_authentication, :except => :signin
def check_authentication
unless session[:user]
session[:intended_action] = action_name
session[:intended_controller] = controller_name
redirect_to :action => “signin”
end
end
def signin
session[:user] = User.authenticate(params[:username],
params[:password]).id
redirect_to :action => session[:intended_action],
:controller => session[:intended_controller]
end
end
Line 19 of user.rb is the raise command below:
require ‘digest/sha2’
class User < ActiveRecord::Base
validates_uniqueness_of :username
def password=(pass)
salt = [Array.new(6){rand(256).chr}.join].pack(“m”).chomp
self.password_salt, self.password_hash =
salt, Digest::SHA256.hexdigest(pass + salt)
end
def self.authenticate(username, password)
user = User.find(:first, :conditions => [‘username = ?’, username])
if user.blank? ||
Digest::SHA256.hexdigest(password + user.password_salt) !=
user.password_hash
raise “Username or password invalid”
end
user
end
end
And signin.rhtml is:
Signin for Admin Access
<%= start_form_tag :action => "signin" %>
Username:
<%= text_field_tag "username" %>
Password:
<%= password_field_tag "password" %>
<%= submit_tag "Signin" %>
<%= end_form_tag%>
- - -
I cleared the browser cache. I took out
#before_filter :check_authentication, :except => :signin
to see if it will take me to the signin screen, but, no, it didn’t. So
there is something fundamentally wrong with my setup.
Thanks for any help,
gk