Authentication #170
6 changed files with 83 additions and 57 deletions
|
@ -14,7 +14,7 @@ module.exports = {
|
||||||
if (result === true) {
|
if (result === true) {
|
||||||
return lbryApi.publishClaim(publishParams);
|
return lbryApi.publishClaim(publishParams);
|
||||||
} else {
|
} else {
|
||||||
return new Error('That name has already been claimed by spee.ch. Please choose a new claim name.');
|
return new Error('That name has already been claimed by spee.ch.');
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// 3. upsert File record (update is in case the claim has been published before by this daemon)
|
// 3. upsert File record (update is in case the claim has been published before by this daemon)
|
||||||
|
|
|
@ -24,33 +24,3 @@ function sendSignupRequest (channelName, password) {
|
||||||
xhttp.send(params);
|
xhttp.send(params);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
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('signup-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);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -31,12 +31,12 @@ function validateFile(file) {
|
||||||
function validateClaimName (name) {
|
function validateClaimName (name) {
|
||||||
// ensure a name was entered
|
// ensure a name was entered
|
||||||
if (name.length < 1) {
|
if (name.length < 1) {
|
||||||
throw new NameError("You must enter a name for your claim");
|
throw new NameError("You must enter a name for your url");
|
||||||
}
|
}
|
||||||
// validate the characters in the 'name' field
|
// validate the characters in the 'name' field
|
||||||
const invalidCharacters = /[^A-Za-z0-9,-]/g.exec(name);
|
const invalidCharacters = /[^A-Za-z0-9,-]/g.exec(name);
|
||||||
if (invalidCharacters) {
|
if (invalidCharacters) {
|
||||||
throw new NameError('"' + invalidCharacters + '" characters are not allowed in the title.');
|
throw new NameError('"' + invalidCharacters + '" characters are not allowed in the url.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ function isNameAvailable (name, apiUrl) {
|
||||||
if (this.response == true) {
|
if (this.response == true) {
|
||||||
resolve();
|
resolve();
|
||||||
} else {
|
} else {
|
||||||
reject( new NameError("That name has already been claimed by another user. Please choose a different name."));
|
reject( new NameError("That name has already been claimed by someone else."));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
reject("request to check claim name failed with status:" + this.status);
|
reject("request to check claim name failed with status:" + this.status);
|
||||||
|
|
|
@ -20,23 +20,20 @@
|
||||||
|
|
||||||
<h2>Create New</h2>
|
<h2>Create New</h2>
|
||||||
<p>Create a brand new channel:</p>
|
<p>Create a brand new channel:</p>
|
||||||
<form id="signup-form" action="/signup" method="post">
|
<form id="publish-channel-form">
|
||||||
<div>
|
<div>
|
||||||
<span id="input-error-channel-name" class="info-message info-message--failure"></span><br/>
|
<div id="input-error-channel-name" class="info-message info-message--failure"></div>
|
||||||
<label>Channel name:</label>
|
<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)"/>
|
@ <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>
|
<span id="input-success-channel-name" class="info-message info-message--success"></span>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<span id="input-error-password" class="info-message info-message--failure"></span><br/>
|
<div id="input-error-password" class="info-message info-message--failure"></div>
|
||||||
<label>Password:</label>
|
<label>Password:</label>
|
||||||
<input type="password" name="password" value="" id="new-channel-password" class="input-text input-text--primary"/>
|
<input type="password" name="password" value="" id="new-channel-password" class="input-text input-text--primary"/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
|
||||||
<input type="submit" value="Create" onclick="publishNewChannel(event)"/>
|
|
||||||
</div>
|
|
||||||
</form>
|
</form>
|
||||||
|
<button value="Create" onclick="publishNewChannel(event)">Create Channel</button>
|
||||||
</div>
|
</div>
|
||||||
{{> footer}}
|
{{> footer}}
|
||||||
</div>
|
</div>
|
||||||
|
@ -44,3 +41,32 @@
|
||||||
<script src="/assets/js/generalFunctions.js"></script>
|
<script src="/assets/js/generalFunctions.js"></script>
|
||||||
<script src="/assets/js/validationFunctions.js"></script>
|
<script src="/assets/js/validationFunctions.js"></script>
|
||||||
<script src="/assets/js/publishChannelFunctions.js"></script>
|
<script src="/assets/js/publishChannelFunctions.js"></script>
|
||||||
|
<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>
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<div id="claim-channel-input-area">
|
<div id="claim-channel-input-area">
|
||||||
<span id="input-error-channel-select" class="info-message info-message--failure"></span>
|
|
||||||
<p>
|
<p>
|
||||||
|
<div id="input-error-channel-select" class="info-message info-message--failure"></div>
|
||||||
<label for="channel-name-select">Channel:</label>
|
<label for="channel-name-select">Channel:</label>
|
||||||
<select type="text" id="channel-name-select" name="channel" value="channel" onclick="check(event)">
|
<select type="text" id="channel-name-select" name="channel" value="channel" onclick="toggleChannel(event)">
|
||||||
{{#if user}}
|
{{#if user}}
|
||||||
<option value="{{user.channelName}}" >{{user.channelName}}</option>
|
<option value="{{user.channelName}}" >{{user.channelName}}</option>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
@ -12,25 +12,30 @@
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div id="channel-create-details" hidden="true">
|
<div id="channel-create-details" hidden="true">
|
||||||
<span id="input-error-channel-name" class="info-message info-message--failure"></span>
|
|
||||||
<p>
|
<p>
|
||||||
<label for="channelName">Channel Name: </label>
|
<form id="publish-channel-form">
|
||||||
@<input type="text" id="channel-name-input" class="input-text input-text--primary" placeholder="exampleChannel" value="" oninput="checkChannelName(event.target.value)">
|
<div>
|
||||||
<span id="input-success-channel-name" class="info-message info-message--success"></span>
|
<div id="input-error-channel-name" class="info-message info-message--failure"></div>
|
||||||
<br/>
|
<label for="channelName">Channel Name: </label>
|
||||||
|
@<input type="text" name="channelName" id="new-channel-name" class="input-text input-text--primary" placeholder="exampleChannel" value="" oninput="checkChannelName(event.target.value)">
|
||||||
|
<span id="input-success-channel-name" class="info-message info-message--success"></span>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div id="input-error-channel-password" class="info-message info-message--failure"></div>
|
||||||
|
<label for="channelPassword" >Password: </label>
|
||||||
|
<input type="password" name="channelPassword" id="new-channel-password" placeholder="" value="" class="input-text input-text--primary">
|
||||||
|
</div>
|
||||||
|
|
||||||
<label for="password" >Password: </label>
|
</form>
|
||||||
<input type="password" id="password" placeholder="" value="" class="input-text input-text--primary">
|
|
||||||
<br/>
|
|
||||||
</p>
|
</p>
|
||||||
<button >create</button>
|
<button onclick="publishNewChannel(event)">Create Channel</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
// toggle channel creation tool
|
|
||||||
const createChannelTool = document.getElementById('channel-create-details');
|
function toggleChannel (event) {
|
||||||
function check(event) {
|
const createChannelTool = document.getElementById('channel-create-details');
|
||||||
const selectedOption = event.target.selectedOptions[0].value;
|
const selectedOption = event.target.selectedOptions[0].value;
|
||||||
if (selectedOption != 'new') {
|
if (selectedOption != 'new') {
|
||||||
createChannelTool.hidden = true;
|
createChannelTool.hidden = true;
|
||||||
|
@ -39,8 +44,33 @@
|
||||||
createChannelTool.hidden = false;
|
createChannelTool.hidden = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function createChannel() {
|
|
||||||
|
|
||||||
|
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-channel-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('signup-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>
|
</script>
|
|
@ -12,8 +12,8 @@
|
||||||
<div class="col-right">
|
<div class="col-right">
|
||||||
<div id="publish-active-area">
|
<div id="publish-active-area">
|
||||||
<div class="stop-float">
|
<div class="stop-float">
|
||||||
<span id="input-error-claim-name" class="info-message info-message--failure" hidden="true"></span>
|
|
||||||
<p>
|
<p>
|
||||||
|
<div id="input-error-claim-name" class="info-message info-message--failure" hidden="true"></div>
|
||||||
Spee.ch/
|
Spee.ch/
|
||||||
<input type="text" id="claim-name-input" class="input-text input-text--primary" placeholder="your-url-here" oninput="checkClaimName(event.target.value)">
|
<input type="text" id="claim-name-input" class="input-text input-text--primary" placeholder="your-url-here" oninput="checkClaimName(event.target.value)">
|
||||||
<span id="input-success-claim-name" class="info-message info-message--success"></span>
|
<span id="input-success-claim-name" class="info-message info-message--success"></span>
|
||||||
|
|
Loading…
Reference in a new issue