2017-10-11 01:00:08 +02: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 23:47:55 +01:00
|
|
|
validationFunctions.validateNewChannelLogin(userName, password)
|
2017-10-12 23:37:25 +02:00
|
|
|
.then(() => {
|
|
|
|
return sendAuthRequest(userName, password, '/login')
|
|
|
|
})
|
2017-10-11 01:00:08 +02:00
|
|
|
.then(result => {
|
2018-01-06 01:47:55 +01:00
|
|
|
window.location = '/';
|
2017-10-11 01:00:08 +02:00
|
|
|
})
|
|
|
|
.catch(error => {
|
2017-10-11 01:51:07 +02:00
|
|
|
const loginErrorDisplayElement = document.getElementById('login-error-display-element');
|
2017-10-12 23:37:25 +02:00
|
|
|
if (error.name){
|
2017-11-02 23:47:55 +01:00
|
|
|
validationFunctions.showError(loginErrorDisplayElement, error.message);
|
2017-10-12 23:37:25 +02:00
|
|
|
} else {
|
2017-11-02 23:47:55 +01:00
|
|
|
validationFunctions.showError(loginErrorDisplayElement, 'There was an error logging into your channel');
|
2017-10-12 23:37:25 +02:00
|
|
|
}
|
2017-10-11 01:00:08 +02:00
|
|
|
})
|
|
|
|
}
|