-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to unlock florida st door (#800)
- Loading branch information
1 parent
b9f57bf
commit 75a3504
Showing
13 changed files
with
131 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
//= link admin.css | ||
//= link door.js | ||
//= link dues.js | ||
//= link membership_note.js | ||
// | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
$(document).ready(() => { | ||
const checkDoorAccessibility = async () => { | ||
try { | ||
const response = await fetch(`${window.accessControlUri}/api/v1/status`); | ||
if (!response.ok) { | ||
throw 'door control not ready'; | ||
} | ||
$("#unlock-door").removeClass('disabled'); | ||
} catch (e) { | ||
$("#unlock-door").addClass('disabled'); | ||
} | ||
}; | ||
|
||
// Poll if door control is available and update button state | ||
checkDoorAccessibility(); | ||
setInterval(checkDoorAccessibility, 5000); | ||
|
||
$("#unlock-door").click(async () => { | ||
if ($("#unlock-door").hasClass('disabled')) { | ||
alert('Door control not accessible. Are you on the space Wi-Fi?'); | ||
return; | ||
} | ||
|
||
try { | ||
// Fetch a short-lived token to authenticate with door control | ||
const tokenResponse = await fetch(`/members/users/${window.userId}/access_control_token`); | ||
if (!tokenResponse.ok) { | ||
throw 'failed to get door token'; | ||
} | ||
const tokenJson = await tokenResponse.json(); | ||
|
||
// Unlock the door | ||
const openResponse = await fetch(`${window.accessControlUri}/api/v1/unlock`, { | ||
method: 'POST', | ||
headers: { | ||
'Authorization': `Bearer ${tokenJson.token}` | ||
}, | ||
body: JSON.stringify({ | ||
seconds: window.accessControlUnlockSeconds, | ||
}), | ||
}); | ||
const openJson = await openResponse.json(); | ||
if (!openResponse.ok) { | ||
throw openJson.message; | ||
} | ||
|
||
$("#unlock-error").addClass('hidden') | ||
$("#unlock-success").removeClass('hidden'); | ||
|
||
// Hide the success message when the door should be locked again | ||
clearTimeout(window.successTimeoutId); | ||
window.successTimeoutId = setTimeout(() => { | ||
$("#unlock-success").addClass('hidden'); | ||
}, window.accessControlUnlockSeconds * 1000); | ||
} catch (e) { | ||
$("#unlock-error").removeClass('hidden'); | ||
$("#error-text").text(`Failed to unlock door: ${e}`); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'jwt' | ||
|
||
class Members::AccessController < Members::MembersController | ||
def token | ||
return head :unprocessable_entity unless current_user.space_access? | ||
|
||
payload = { | ||
sub: current_user.email, | ||
nbf: Time.now.to_i - 30, | ||
exp: Time.now.to_i + 30 | ||
} | ||
|
||
render json: { token: JWT.encode(payload, ENV['ACCESS_CONTROL_SIGNING_KEY'], 'HS256') } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters