Card upload would fail due to being logged out halfway thru; changed arduino auth mechanism
This commit is contained in:
parent
41a8431be5
commit
ef590793f2
|
@ -11,21 +11,14 @@ class Card < ActiveRecord::Base
|
||||||
door_access_url = APP_CONFIG['door_access_url']
|
door_access_url = APP_CONFIG['door_access_url']
|
||||||
door_access_password = APP_CONFIG['door_access_password']
|
door_access_password = APP_CONFIG['door_access_password']
|
||||||
|
|
||||||
# connect to door access system
|
cardid = self.id.to_s.rjust(3, '0')
|
||||||
source = open("#{door_access_url}?e=#{door_access_password}").read
|
|
||||||
results = source.scan(/ok/)
|
|
||||||
if(results.size > 0) then
|
|
||||||
#only continue if we've got an OK login
|
|
||||||
cardid = self.id.to_s.rjust(3, '0') #TODO: provide ability for
|
|
||||||
cardperm = self.card_permissions.to_s.rjust(3, '0')
|
cardperm = self.card_permissions.to_s.rjust(3, '0')
|
||||||
cardnum = self.card_number.rjust(8, '0')
|
cardnum = self.card_number.rjust(8, '0')
|
||||||
|
|
||||||
source = open("#{door_access_url}?m#{cardid}&p#{cardperm}&t#{cardnum}").read
|
# login and send the command all in one go (auto-logout is a feature of the arduino when used this way)
|
||||||
|
source = open("#{door_access_url}?m#{cardid}&p#{cardperm}&t#{cardnum}&e=#{door_access_password}").read
|
||||||
results = source.scan(/cur/)
|
results = source.scan(/cur/)
|
||||||
|
|
||||||
#logout
|
|
||||||
open("#{door_access_url}?e=0000")
|
|
||||||
|
|
||||||
if(results.size > 0) then
|
if(results.size > 0) then
|
||||||
#only return true if we got some kind of decent response
|
#only return true if we got some kind of decent response
|
||||||
return true
|
return true
|
||||||
|
@ -33,10 +26,6 @@ class Card < ActiveRecord::Base
|
||||||
# We didn't get a decent response.
|
# We didn't get a decent response.
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
else
|
|
||||||
# We didn't get an OK login.
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.upload_all_to_door
|
def self.upload_all_to_door
|
||||||
|
@ -47,30 +36,21 @@ class Card < ActiveRecord::Base
|
||||||
door_access_url = APP_CONFIG['door_access_url']
|
door_access_url = APP_CONFIG['door_access_url']
|
||||||
door_access_password = APP_CONFIG['door_access_password']
|
door_access_password = APP_CONFIG['door_access_password']
|
||||||
|
|
||||||
source = open("#{door_access_url}?e=#{door_access_password}").read
|
@cards.each do |u|
|
||||||
results = source.scan(/ok/)
|
cardid = u.id.to_s.rjust(3, '0')
|
||||||
if(results.size > 0) then
|
cardperm = u.card_permissions.to_s.rjust(3, '0')
|
||||||
@cards.each do |u|
|
cardnum = u.card_number.rjust(8, '0')
|
||||||
#only continue if we've got an OK login
|
|
||||||
cardid = u.id.to_s.rjust(3, '0')
|
|
||||||
cardperm = u.card_permissions.to_s.rjust(3, '0')
|
|
||||||
cardnum = u.card_number.rjust(8, '0')
|
|
||||||
|
|
||||||
source = open("#{door_access_url}?m#{cardid}&p#{cardperm}&t#{cardnum}").read
|
# login and send the command all in one go (auto-logout is a feature of the arduino when used this way)
|
||||||
results = source.scan(/cur/)
|
source = open("#{door_access_url}?m#{cardid}&p#{cardperm}&t#{cardnum}&e=#{door_access_password}").read
|
||||||
|
results = source.scan(/cur/)
|
||||||
|
|
||||||
if(results.size > 0) then
|
if(results.size > 0) then
|
||||||
#only return true if we got some kind of decent response
|
#only return true if we got some kind of decent response
|
||||||
@end_results.push([cardid,"OK"])
|
@end_results.push([cardid,"OK"])
|
||||||
else
|
else
|
||||||
@end_results.push([cardid,"FAIL"])
|
@end_results.push([cardid,"FAIL"])
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
#logout
|
|
||||||
open("#{door_access_url}?e=0000")
|
|
||||||
else
|
|
||||||
@end_results.push([cardid,"FAIL"])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return @end_results
|
return @end_results
|
||||||
|
|
Loading…
Reference in New Issue
Block a user