14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/forcast/models/login/authorization.rb', line 14
def self.invalidate_token(given_token)
temporal_auth = Authorization.new()
decoded_token = JsonWebToken.decode(given_token)
if decoded_token.blank?
temporal_auth.errors.add(:base, I18n.t("activerecord.errors.token.not_exits"))
else
user_id = decoded_token[:user_id]
created_at_format = decoded_token[:birthday_date]
created_at = Time.parse(created_at_format)
auth = Authorization.find_by(user_id:user_id,active_time_stamp:created_at.to_i)
if auth.present? && auth.operative
auth.operative = false
auth.save
else
temporal_auth.errors.add(:base, I18n.t("activerecord.errors.token.already_invalid"))
end
end
temporal_auth
end
|