Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User < ActiveRecord::Base
- has_many :subscriptions
- has_many :channels, through: :subscriptions
- validates :email, presence: true, uniqueness: true
- validates :password, presence: true
- def password
- @password ||= BCrypt::Password.new(hashed_password)
- end
- def password=(new_password)
- @password = BCrypt::Password.create(new_password)
- self.hashed_password = @password
- end
- def self.authenticate(params)
- user = User.find_by(email: params[:email])
- return user if user && user.password == params[:password]
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement