Created
October 11, 2018 14:16
-
-
Save reazuliqbal/ce97657a52ddca27544579c13bc63a04 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
wlsjs.api.setOptions({url: 'https://rpc.wls.services'}); | |
$(document).ready(async function () { | |
$('#add-authority').submit(async function (e) { | |
let username = $('#add-username').val(); | |
let authorized = $('#add-authorized').val(); | |
let role = $('#add-role').val(); | |
let key = $('#add-key').val(); | |
let feedback = $('#add-feedback'); | |
feedback.empty().removeClass('alert-success').removeClass('alert-danger'); | |
wlsjs.api.getAccounts([username, authorized], function (err, res) { | |
if (res && res.length !== 2) { | |
feedback.addClass('alert-danger').text('User or Authorized account does not exist.'); | |
} else { | |
wlsjs.broadcast.addAccountAuth({ | |
signingKey: key, | |
username: username, | |
authorizedUsername: authorized, | |
role: role, | |
weight: 1, | |
}, function (err, res) { | |
console.log(res); | |
if (res) { | |
feedback.addClass('alert-success').html('<strong>@'+ authorized +'</strong> has been given <code>'+ role +'</code> authority to your account.'); | |
$('form#add-authority').get(0).reset(); | |
} else { | |
feedback.addClass('alert-danger').text('There was an error, please try again later.'); | |
} | |
}); | |
} | |
}); | |
e.preventDefault(); | |
}); | |
$('#remove-authority').submit(async function (e) { | |
let username = $('#remove-username').val(); | |
let authorized = $('#remove-authorized').val(); | |
let role = $('#remove-role').val(); | |
let key = $('#remove-key').val(); | |
let feedback = $('#remove-feedback'); | |
feedback.empty().removeClass('alert-success').removeClass('alert-danger'); | |
wlsjs.api.getAccounts([username, authorized], function (err, res) { | |
if (res && res.length !== 2) { | |
feedback.addClass('alert-danger').text('User or Authorized account does not exist.'); | |
} else { | |
wlsjs.broadcast.removeAccountAuth({ | |
signingKey: key, | |
username: username, | |
authorizedUsername: authorized, | |
role: role, | |
}, function (err, res) { | |
console.log(res); | |
if (res) { | |
feedback.addClass('alert-success').html('<strong>@'+ authorized +'</strong> has been removed from <code>'+ role +'</code> authority.'); | |
$('form#remove-authority').get(0).reset(); | |
} else { | |
feedback.addClass('alert-danger').text('There was an error, please try again later.'); | |
} | |
}); | |
} | |
}); | |
e.preventDefault(); | |
}); | |
// Resets the form if Tab is changed | |
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { | |
// e.target // newly activated tab | |
$(e.relatedTarget.hash).find('form').get(0).reset(); | |
}) | |
}); |
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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | |
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous"> | |
<title>Whaleshares Connect</title> | |
</head> | |
<body> | |
<div class="container"> | |
<div class="row justify-content-center"> | |
<div class="col-md-7 mt-5"> | |
<h1 class="text-center">Whaleshares Connect</h1> | |
<ul class="nav nav-tabs nav-pills nav-justified mt-5" id="myTab" role="tablist"> | |
<li class="nav-item"> | |
<a class="nav-link active" id="add-tab" data-toggle="tab" href="#add" role="tab" aria-controls="add" aria-selected="true">Add Authority</a> | |
</li> | |
<li class="nav-item"> | |
<a class="nav-link" id="remove-tab" data-toggle="tab" href="#remove" role="tab" aria-controls="remove" aria-selected="false">Remove Authority</a> | |
</li> | |
</ul> | |
<div class="tab-content" id="myTabContent"> | |
<!-- TABBED CONTENT: ADD AUTHORITY --> | |
<div class="tab-pane fade show active" id="add" role="tabpanel" aria-labelledby="add-tab"> | |
<div class="alert mt-3" id="add-feedback"></div> | |
<form id="add-authority" class="mt-3" method="post"> | |
<div class="form-group"> | |
<label for="add-username">Username</label> | |
<input type="text" name="add-username" id="add-username" class="form-control"> | |
<div class="form-text text-muted">Enter your Whaleshares username.</div> | |
</div> | |
<div class="form-group"> | |
<label for="add-authorized">Authorized User</label> | |
<input type="text" name="add-authorized" id="add-authorized" class="form-control"> | |
<div class="form-text text-muted">Enter the username you want to give authority to.</div> | |
</div> | |
<div class="form-group"> | |
<label for="add-role">Authorized Role</label> | |
<select name="add-role" id="add-role" class="form-control"> | |
<option value="posting">Posting</option> | |
<option value="active">Active</option> | |
</select> | |
<div class="form-text text-muted">Select a authority role that should be given.</div> | |
</div> | |
<div class="form-group"> | |
<label for="add-key">Active Key</label> | |
<input type="password" name="add-key" id="add-key" class="form-control"> | |
<div class="form-text text-muted">Enter private active key of your account.</div> | |
</div> | |
<button type="submit" class="btn btn-info">Add Authority</button> | |
</form> | |
</div> | |
<!-- TABBED CONTENT: REMOVE AUTHORITY --> | |
<div class="tab-pane fade" id="remove" role="tabpanel" aria-labelledby="remove-tab"> | |
<div class="alert mt-3" id="remove-feedback"></div> | |
<form id="remove-authority" class="mt-3" method="post"> | |
<div class="form-group"> | |
<label for="remove-username">Username</label> | |
<input type="text" name="remove-username" id="remove-username" class="form-control"> | |
<div class="form-text text-muted">Enter your Whaleshares username.</div> | |
</div> | |
<div class="form-group"> | |
<label for="remove-authorized">Authorized User</label> | |
<input type="text" name="remove-authorized" id="remove-authorized" class="form-control"> | |
<div class="form-text text-muted">Enter the username you want to remove authority from.</div> | |
</div> | |
<div class="form-group"> | |
<label for="remove-role">Authorized Role</label> | |
<select name="remove-role" id="remove-role" class="form-control"> | |
<option value="posting">Posting</option> | |
<option value="active">Active</option> | |
</select> | |
<div class="form-text text-muted">Select a authority role that should be removed.</div> | |
</div> | |
<div class="form-group"> | |
<label for="remove-key">Active Key</label> | |
<input type="password" name="remove-key" id="remove-key" class="form-control"> | |
<div class="form-text text-muted">Enter private active key of your account.</div> | |
</div> | |
<button type="submit" class="btn btn-secondary">Remove Authority</button> | |
</form> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
<script src="js/wlsjs.min.js"></script> | |
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> | |
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script> | |
<script src="js/app.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment