Last active
June 10, 2021 18:19
-
-
Save amcgregor/4c96944376bea9aac8e7f15ecfad2383 to your computer and use it in GitHub Desktop.
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
class CoreAuthenticationManager: | |
def start(self): | |
document.addEventListener('submit', delegated('#authenticate', self.processAuthenticationForm)) | |
def processAuthenticationForm(self, event, form): | |
event.preventDefault() | |
event.stopPropagation() | |
form.classList.remove('invalid') | |
identity = document.getElementById('auth-email') | |
password = document.getElementById('auth-password') | |
if not identity.value: | |
identity.focus() | |
return | |
if not password.value: | |
password.focus() | |
return | |
def callback(err, response, body): | |
if response.status == 401 or response.status == 403: | |
form.classList.add('invalid') | |
return | |
if response.status != 200: | |
form.classList.add('error') | |
return | |
result = JSON.parse(body) | |
if not result.ok: | |
form.dataset.message = result.message | |
form.classList.add('message') | |
return | |
# TODO: Temporarily while I refactor the NavigationManager... | |
window.location = window.location | |
# TODO: Same temporary note here re: NavigationManager... | |
request({'method': form.method, 'url': form.action, 'json': { | |
'identity': identity.value, | |
'password': password.value, | |
}, 'headers': { | |
'X-Requested-With': 'XMLHttpRequest', | |
}}, callback) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment