Guest User

Untitled

a guest
Jun 16th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. ## M
  2. class User < ActiveRecord::Base
  3. validates_confirmation_of :password, :on => :create
  4.  
  5. attr_accessor :password, :password_confirmation
  6.  
  7. def password=(pass)
  8. salt = User.random_string(8)
  9. update_attributes(:password_salt => salt, :password_hash => Digest::SHA256.hexdigest(pass + salt))
  10. end
  11. end
  12.  
  13. ## V
  14. <% form_for @user do |f| %>
  15. <p>
  16. <%= f.label :password %>
  17. <%= f.password_field :password %>
  18. </p>
  19.  
  20. <p>
  21. <%= f.label :password_confirmation %>
  22. <%= f.password_field :password_confirmation %>
  23. </p>
  24.  
  25. <p>
  26. <%= f.submit 'Create' %>
  27. </p>
  28. <% end %>
  29.  
  30. ## C
  31. class UsersController < ApplicationController
  32. def create
  33. @user = User.new(params[:user])
  34. if @user.save
  35. flash[:notice] = 'User was successfully created.'
  36. redirect_to :action => :index
  37. else
  38. render :action => 'new'
  39. end
  40. end
  41. end
Add Comment
Please, Sign In to add comment