Login form question

I’m using Rails Recipes to create a login form but instead of username
and password, my setup is firstname, lastname, password.

I seemed to be gramatically challenged and not sure how to set up the
parameter list. Can anyone offer up a suggestion.
The book shows the method starting like:

if request.post?
user = User.find(:first, :conditions => [‘username = ?’ ,
params[:username]])

So here is my attempt but with some obvious mistakes:
def login
if request.post?
user = User.find(:first, :conditions => [‘first_name = ?’,
‘last_name = ?’, params
[:first_name],
[last_name]


end

TIA
Stuart

I’m now getting a wrong number of arguments (2 for 1).
Again, the user should sign on with first name , last name, password

def login
if request.post?
user = User.find(:first, :conditions => [‘first_name = ?’,
‘last_name = ?’,
params[:first_name, :last_name]])
if user.blank? ||
Digest::SHA256.hexdigest(params[:password] + user.password_salt)
!=
user.password_hash
raise “First name, Last name, or password invalid”
end
session[:user] = user.id
redirect_to :action => session[:intended_action],
:controller => session[:intended_controller]
end
end

Stuart

Try
User.find(:first, :conditions => [‘first_name = ? AND last_name = ?’,
params[:first_name], params[:last_name])

Jon

user = User.find(:first, :conditions => [‘first_name = ? and last_name
= ?’, params[:first_name], params[:last_name])

Thank you , that fixed it!

Stuart

Actually I should ask another question, in the recipes book the login
form is built with
start_form_tag, so:
<%= start_form_tag :action => “signin” %>
Username:
<%= text_field_tag “username” %>

Password:
<%= password_field_tag “password” %>

<%= submit_tag “Sign in” %>
<%= end_form_tag %>

I am using a regular form tag , wondering if that would make a
different how the post is handled?
Here is the way I constructed the form:

Log in to your account First name: <%= text_field "user", "first_name" %>
<label for="last_name" >Last name:</label>
<%= text_field "user", "last_name" %>

<label for="password" >Password:</label>
<%= password_field "user", "password" %>

<input type="Submit" value="Login" %>
</form>

Stuart

I guess it does make a difference because with start_form_tag the form
works. :slight_smile:

Thanks
Stuart

Stuart Fellowes wrote:

I guess it does make a difference because with start_form_tag the form
works. :slight_smile:

Thanks
Stuart

You can always View Source from your browser to see what’s different
between the two approaches.

Jeff

Good idea, I forgot that option.

Stuart

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs