Module: Signinable::ModelAdditions
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/signinable/model_additions.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
Instance Method Details
#signin(ip, user_agent, referer, custom_data: {}) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/signinable/model_additions.rb', line 101 def signin(ip, user_agent, referer, custom_data: {}) Signin.where(signinable: self).active.map(&:expire!) unless self.class.simultaneous_signings signin = Signin.create!( signinable: self, ip: ip, referer: referer, user_agent: user_agent, expiration_time: self.class.expiration_period.seconds.from_now, custom_data: custom_data ) self.jwt = self.class.generate_jwt(signin.token, signin.signinable_id) signin end |
#signout(jwt) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/signinable/model_additions.rb', line 118 def signout(jwt) jwt_payload = self.class.extract_jwt_payload(jwt) return unless jwt_payload return if jwt_payload[:expired] signin = Signin.find_by(token: jwt_payload[:data]['refresh_token']) return unless signin return if signin.expired? signin.expire! true end |