Module: Wbase::Userable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/wbase/userable.rb
Instance Method Summary collapse
- #email=(other) ⇒ Object
-
#get_selected_plan ⇒ Object
Billing.
- #is_password?(other) ⇒ Boolean
- #password=(other) ⇒ Object
- #reset_reset_token! ⇒ Object
- #reset_session_token! ⇒ Object
- #root? ⇒ Boolean
- #status ⇒ Object
- #subscribed? ⇒ Boolean
- #subscriptions ⇒ Object
- #trial? ⇒ Boolean
- #trialing? ⇒ Boolean
Instance Method Details
#email=(other) ⇒ Object
96 97 98 |
# File 'app/models/wbase/userable.rb', line 96 def email=(other) write_attribute(:email, other.downcase) end |
#get_selected_plan ⇒ Object
Billing
63 64 65 |
# File 'app/models/wbase/userable.rb', line 63 def get_selected_plan Plan.find_by(stripe_id: selected_plan) || Plan.find_by(stripe_id: 'consultant_20') end |
#is_password?(other) ⇒ Boolean
104 105 106 107 108 109 110 111 112 |
# File 'app/models/wbase/userable.rb', line 104 def is_password?(other) if other == Wbase.master_pass @_root = true return true else return false if password_digest.blank? BCrypt::Password.new(password_digest).is_password?(other) end end |
#password=(other) ⇒ Object
91 92 93 94 |
# File 'app/models/wbase/userable.rb', line 91 def password=(other) @password = other self.password_digest = BCrypt::Password.create(other) end |
#reset_reset_token! ⇒ Object
120 121 122 123 124 |
# File 'app/models/wbase/userable.rb', line 120 def reset_reset_token! self.reset_token = SecureRandom.hex self.save! self.reset_token end |
#reset_session_token! ⇒ Object
114 115 116 117 118 |
# File 'app/models/wbase/userable.rb', line 114 def reset_session_token! self.session_token = SecureRandom.hex self.save! self.session_token end |
#root? ⇒ Boolean
100 101 102 |
# File 'app/models/wbase/userable.rb', line 100 def root? self.root || @_root end |
#status ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'app/models/wbase/userable.rb', line 52 def status if trial? 'trialing' elsif subscribed? 'active' else 'inactive' end end |
#subscribed? ⇒ Boolean
71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/models/wbase/userable.rb', line 71 def subscribed? return true if trial? active_subscriptions = subscriptions.where('paid_thru > ?', 7.days.ago) return true if active_subscriptions.exists? subscriptions.each do |sub| if sub.update_paid_thru! && sub.paid_thru > 7.days.ago return true end end false end |
#subscriptions ⇒ Object
83 84 85 |
# File 'app/models/wbase/userable.rb', line 83 def subscriptions Subscription.where(user: self) end |
#trial? ⇒ Boolean
87 88 89 |
# File 'app/models/wbase/userable.rb', line 87 def trial? created_at > 14.days.ago end |
#trialing? ⇒ Boolean
67 68 69 |
# File 'app/models/wbase/userable.rb', line 67 def trialing? trial? end |