A website template with lots of features, built with ruby on rails.

user.rb 1.1KB

123456789101112131415161718192021222324252627282930313233343536
  1. class User < ActiveRecord::Base
  2. # Include default devise modules. Others available are:
  3. # :confirmable, :lockable, :timeoutable and :omniauthable
  4. devise :database_authenticatable, :async, :registerable,
  5. :recoverable, :rememberable, :trackable, :validatable
  6. validates :password, presence: true, length: {minimum: 5, maximum: 120}, on: :create
  7. validates :password, length: {minimum: 5, maximum: 120}, on: :update, allow_blank: true
  8. has_many :posts
  9. mount_uploader :avatar, AvatarUploader
  10. process_in_background :avatar
  11. store_in_background :avatar
  12. def full_name
  13. name = self.first_name.to_s + ' ' + self.last_name.to_s
  14. return name
  15. end
  16. after_create do
  17. after_signup_tasks
  18. end
  19. def after_signup_tasks
  20. # Send signup email (worker)
  21. Resque.enqueue(SendSignupMessage, self.id)
  22. # Add user to subscription list
  23. if Subscription.find_by_email(self.email) == nil
  24. Subscription.create(first_name: self.first_name, last_name: self.last_name, email: self.email)
  25. end
  26. # Mixpanel Tracking Analytics
  27. end
  28. end