Advertisement
Guest User

Untitled

a guest
Mar 16th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. class User < ActiveRecord::Base
  2. has_many :subscriptions
  3. has_many :channels, through: :subscriptions
  4.  
  5. validates :email, presence: true, uniqueness: true
  6. validates :password, presence: true
  7.  
  8. def password
  9. @password ||= BCrypt::Password.new(hashed_password)
  10. end
  11.  
  12. def password=(new_password)
  13. @password = BCrypt::Password.create(new_password)
  14. self.hashed_password = @password
  15. end
  16.  
  17. def self.authenticate(params)
  18. user = User.find_by(email: params[:email])
  19. return user if user && user.password == params[:password]
  20. end
  21. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement