2017-10-10 16:00:08 -07:00
|
|
|
function loginToChannel (event) {
|
|
|
|
const userName = document.getElementById('channel-login-name-input').value;
|
|
|
|
const password = document.getElementById('channel-login-password-input').value;
|
|
|
|
// prevent default
|
|
|
|
event.preventDefault()
|
2017-11-02 15:47:55 -07:00
|
|
|
validationFunctions.validateNewChannelLogin(userName, password)
|
2017-10-12 14:37:25 -07:00
|
|
|
.then(() => {
|
|
|
|
return sendAuthRequest(userName, password, '/login')
|
|
|
|
})
|
2017-10-10 16:00:08 -07:00
|
|
|
.then(result => {
|
2018-01-05 16:47:55 -08:00
|
|
|
window.location = '/';
|
2017-10-10 16:00:08 -07:00
|
|
|
})
|
|
|
|
.catch(error => {
|
2017-10-10 16:51:07 -07:00
|
|
|
const loginErrorDisplayElement = document.getElementById('login-error-display-element');
|
2017-10-12 14:37:25 -07:00
|
|
|
if (error.name){
|
2017-11-02 15:47:55 -07:00
|
|
|
validationFunctions.showError(loginErrorDisplayElement, error.message);
|
2017-10-12 14:37:25 -07:00
|
|
|
} else {
|
2017-11-02 15:47:55 -07:00
|
|
|
validationFunctions.showError(loginErrorDisplayElement, 'There was an error logging into your channel');
|
2017-10-12 14:37:25 -07:00
|
|
|
}
|
2017-10-10 16:00:08 -07:00
|
|
|
})
|
|
|
|
}
|