Skip to content

Commit

Permalink
killing 'login' attribute on user.
Browse files Browse the repository at this point in the history
  • Loading branch information
stcorbett committed Apr 4, 2009
1 parent 280f3b2 commit ed0921b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 47 deletions.
8 changes: 4 additions & 4 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def new

def create
logout_keeping_session!
user = User.authenticate(params[:login], params[:password])
user = User.authenticate(params[:email], params[:password])
if user
# Protects against session fixation attacks, causes request forgery
# protection if user resubmits an earlier form using back
Expand All @@ -22,7 +22,7 @@ def create
flash[:notice] = "Logged in successfully"
else
note_failed_signin
@login = params[:login]
@email = params[:email]
@remember_me = params[:remember_me]
render :action => 'new'
end
Expand All @@ -37,7 +37,7 @@ def destroy
protected
# Track failed login attempts
def note_failed_signin
flash[:error] = "Couldn't log you in as '#{params[:login]}'"
logger.warn "Failed login for '#{params[:login]}' from #{request.remote_ip} at #{Time.now.utc}"
flash[:error] = "Couldn't log you in as '#{params[:email]}'"
logger.warn "Failed login for '#{params[:email]}' from #{request.remote_ip} at #{Time.now.utc}"
end
end
33 changes: 1 addition & 32 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,8 @@ def if_authorized?(action, resource, &block)
end
end

#
# Link to user's page ('users/1')
#
# By default, their login is used as link text and link title (tooltip)
#
# Takes options
# * :content_text => 'Content text in place of user.login', escaped with
# the standard h() function.
# * :content_method => :user_instance_method_to_call_for_content_text
# * :title_method => :user_instance_method_to_call_for_title_attribute
# * as well as link_to()'s standard options
#
# Examples:
# link_to_user @user
# # => <a href="/users/3" title="barmy">barmy</a>
#
# # if you've added a .name attribute:
# content_tag :span, :class => :vcard do
# (link_to_user user, :class => 'fn n', :title_method => :login, :content_method => :name) +
# ': ' + (content_tag :span, user.email, :class => 'email')
# end
# # => <span class="vcard"><a href="/users/3" title="barmy" class="fn n">Cyril Fotheringay-Phipps</a>: <span class="email">barmy@blandings.com</span></span>
#
# link_to_user @user, :content_text => 'Your user page'
# # => <a href="/users/3" title="barmy" class="nickname">Your user page</a>
#
def link_to_user(user, options={})
raise "Invalid user" unless user
options.reverse_merge! :content_method => :login, :title_method => :login, :class => :nickname
content_text = options.delete(:content_text)
content_text ||= user.send(options.delete(:content_method))
options[:title] ||= user.send(options.delete(:title_method))
link_to h(content_text), user_path(user), options
raise "we dont' use this helper, remove it"
end

#
Expand Down
12 changes: 3 additions & 9 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,18 @@ class User < ActiveRecord::Base
# anything else you want your user to change should be added here.
attr_accessible :email, :name, :password, :password_confirmation



# Authenticates a user by their login name and unencrypted password. Returns the user or nil.
#
# uff. this is really an authorization, not authentication routine.
# We really need a Dispatch Chain here or something.
# This will also let us return a human error message.
#
def self.authenticate(login, password)
return nil if login.blank? || password.blank?
u = find_by_login(login.downcase) # need to get the salt
def self.authenticate(email, password)
return nil if email.blank? || password.blank?
u = find_by_email(email.downcase) # need to get the salt
u && u.authenticated?(password) ? u : nil
end

def login=(value)
write_attribute :login, (value ? value.downcase : nil)
end

def email=(value)
write_attribute :email, (value ? value.downcase : nil)
end
Expand Down
4 changes: 2 additions & 2 deletions app/views/sessions/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<h1>Log In</h1>

<% form_tag session_path do -%>
<p><%= label_tag 'login' %><br />
<%= text_field_tag 'login', @login %></p>
<p><%= label_tag 'email' %><br />
<%= text_field_tag 'email', @email %></p>

<p><%= label_tag 'password' %><br/>
<%= password_field_tag 'password', nil %></p>
Expand Down

0 comments on commit ed0921b

Please sign in to comment.