spee.ch/views/login.handlebars

73 lines
3.2 KiB
Handlebars
Raw Normal View History

2017-09-17 02:50:22 +02:00
<div class="wrapper">
2017-09-18 19:14:06 +02:00
{{> topBar}}
<div class="full">
2017-09-19 17:47:24 +02:00
2017-09-18 19:14:06 +02:00
<h2>Log In</h2>
<p>Log in to an existing channel:</p>
2017-09-18 19:14:06 +02:00
<form id="login-form" action="/login" method="post">
<div>
<label>Username:</label>
2017-09-19 21:54:23 +02:00
@ <input type="text" name="username" class="input-text input-text--primary"/>
2017-09-18 19:14:06 +02:00
</div>
<div>
<label>Password:</label>
2017-09-19 21:54:23 +02:00
<input type="password" name="password" class="input-text input-text--primary"/>
2017-09-18 19:14:06 +02:00
</div>
<div>
<input type="submit" value="Log In"/>
</div>
</form>
2017-09-19 17:47:24 +02:00
<h2>Create New</h2>
<p>Create a brand new channel:</p>
2017-09-20 20:36:20 +02:00
<form id="publish-channel-form">
2017-09-19 17:47:24 +02:00
<div>
2017-09-20 20:36:20 +02:00
<div id="input-error-channel-name" class="info-message info-message--failure"></div>
2017-09-19 17:47:24 +02:00
<label>Channel name:</label>
@ <input type="text" name="username" value="" id="new-channel-name" class="input-text input-text--primary" oninput="checkChannelName(event.target.value)"/>
<span id="input-success-channel-name" class="info-message info-message--success"></span>
2017-09-19 17:47:24 +02:00
</div>
<div>
2017-09-20 20:36:20 +02:00
<div id="input-error-password" class="info-message info-message--failure"></div>
2017-09-19 17:47:24 +02:00
<label>Password:</label>
<input type="password" name="password" value="" id="new-channel-password" class="input-text input-text--primary"/>
2017-09-19 17:47:24 +02:00
</div>
</form>
2017-09-20 20:36:20 +02:00
<button value="Create" onclick="publishNewChannel(event)">Create Channel</button>
2017-09-18 19:14:06 +02:00
</div>
{{> footer}}
</div>
<script src="/assets/js/generalFunctions.js"></script>
<script src="/assets/js/validationFunctions.js"></script>
2017-09-20 18:49:05 +02:00
<script src="/assets/js/publishChannelFunctions.js"></script>
2017-09-20 20:36:20 +02:00
<script type="text/javascript">
function publishNewChannel (event) {
const channelName = `@${document.getElementById('new-channel-name').value}`;
const password = document.getElementById('new-channel-password').value;
const channelNameErrorDisplayElement = document.getElementById('input-error-channel-name');
const passwordErrorDisplayElement = document.getElementById('input-error-password');
// prevent default so this script can handle submission
event.preventDefault();
// validate submission
validateNewChannelSubmission(channelName, password)
.then(() => {
return sendSignupRequest(channelName, password) // post the request
})
.then(() => {
console.log('success');
document.getElementById('publish-channel-form').innerHTML = '<p>Your channel has been successfully created! Redirecting you now...</p>';
window.location.href = `/${channelName}`;
})
.catch(error => {
if (error.name === 'ChannelNameError'){
showError(channelNameErrorDisplayElement, error.message);
} else if (error.name === 'ChannelPasswordError'){
showError(passwordErrorDisplayElement, error.message);
} else {
console.log('failure:', error);
}
})
}
</script>