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
97 98 99 |
# File 'app/models/wbase/userable.rb', line 97 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
105 106 107 108 109 110 111 112 113 |
# File 'app/models/wbase/userable.rb', line 105 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
92 93 94 95 |
# File 'app/models/wbase/userable.rb', line 92 def password=(other) @password = other self.password_digest = BCrypt::Password.create(other) end |
#reset_reset_token! ⇒ Object
121 122 123 124 125 |
# File 'app/models/wbase/userable.rb', line 121 def reset_reset_token! self.reset_token = SecureRandom.hex self.save! self.reset_token end |
#reset_session_token! ⇒ Object
115 116 117 118 119 |
# File 'app/models/wbase/userable.rb', line 115 def reset_session_token! self.session_token = SecureRandom.hex self.save! self.session_token end |
#root? ⇒ Boolean
101 102 103 |
# File 'app/models/wbase/userable.rb', line 101 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 82 |
# File 'app/models/wbase/userable.rb', line 71 def subscribed? return true if Rails.env.development? 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
84 85 86 |
# File 'app/models/wbase/userable.rb', line 84 def subscriptions Subscription.where(user: self) end |
#trial? ⇒ Boolean
88 89 90 |
# File 'app/models/wbase/userable.rb', line 88 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 |