update authenticate with app_token

This commit is contained in:
Thein Lin Kyaw
2020-01-15 11:28:57 +06:30
parent 684b408d0b
commit f89d436aeb
2 changed files with 13 additions and 16 deletions

View File

@@ -38,25 +38,22 @@ class Employee < ApplicationRecord
end end
end end
return nil return nil
end end
def self.authenticate_by_token(session_token) def self.authenticate_by_token(token)
if (session_token) if token
user = Employee.find_by_token_session(session_token) if user = Employee.find_by_token_session(token)
expiry_time = login_expiry_time expiry_time = login_expiry_time
if user && !user.session_expiry.nil? if user.session_expiry && user.session_expiry.utc > DateTime.now.utc
if user && user.session_expiry.utc > DateTime.now.utc
#Extend the login time each time authenticatation take place #Extend the login time each time authenticatation take place
user.session_expiry = user.session_expiry.utc + expiry_time.minutes user.session_expiry = user.session_expiry.utc + expiry_time.minutes
user.save user.save
return true return true
else end
return false elsif user = Employee.find_by_app_token(token)
return true
end end
end end
end
return false return false
end end