On Mon, 2007-03-05 at 21:50 +0100, chris wrote:> I have figured out everything except for how to add a new user to the
> database. The book gives an example of adding a user through the
> command line, and that works fine. I can login using a user created
> that way. I cannot, however, figure out how to add a new user from a
> form. The problem seems to occur when trying to except a user submitted
> password (of which there is no corresponding DB listing) and generating
> a salt and hash to be stored in the DB. The method in the user model:
>
> 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
>
> how do I accept a password from a view from a form, generate the
> password and salt and save it to the DB. Here is what I have for the
> view form
>
> View:
>
> <%= form_tag({:action => ''new_user''}, :multipart
=> true) %>
>
> <div class="new_i">
> <p><b>Username:</b><br>
> <%= text_field("user",
"username", "size" => 20 ) %>
> </p>
> </div>
>
> <div class="new_i">
> <p><b>Password:</b><br>
> <%= text_field_tag("password",nil,
"size" => 20 ) %>
> </p>
> </div>
>
>
> <%= submit_tag(" Register ")%>
> <%= end_form_tag %>
>
>
> I changed the text_field to text_field_tag because the fact that
> password is not a line in the DB was raising an error. I can''t
figure
> out how to handle this in the controller in :action =>
"new_user"
----
<%= form_tag({:action => ''new_user''}, :multipart =>
true) %>
<div class="new_i">
<p><b>Username:</b><br>
<%= text_field("user", "username", "size"
=> 20 ) %>
</p>
</div>
<div class="new_i">
<p><b>Password:</b><br>
<%= text_field("user", "password", "size"
=> 20 ) %>
</p>
</div>
<%= submit_tag(" Register ")%>
<%= end_form_tag %>
I don''t know what '':multipart => true'' does for
you
--
Craig White <craig-CnJ8jr4MGtxl57MIdRCFDg@public.gmane.org>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---