Advertisement
Guest User

Untitled

a guest
Aug 4th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>GunFun</title>
  4. <script src="https://cdn.jsdelivr.net/npm/gun/gun.js"></script>
  5. <script src="https://cdn.jsdelivr.net/npm/gun/sea.js"></script>
  6. </head>
  7. <body>
  8.  
  9.  
  10. <p>Gun Fun</p>
  11. <form name="signupForm" onSubmit="return validateSignUp(event)">
  12. Username: <input name="username" type="text"/>
  13. Password: <input name="unsafePassword" type="password"/>
  14. <input type="submit" value="Sign up">
  15. </form>
  16.  
  17. <div id="accountStatus">
  18. Your not signed up in
  19. </div>
  20.  
  21.  
  22. <script>
  23.  
  24. var gun = Gun();
  25. var user = gun.user();
  26. console.log(gun);
  27.  
  28.  
  29. function validateSignUp(event) {
  30. event.preventDefault();
  31. console.log("validating");
  32. var username = document.forms["signupForm"]["username"].value;
  33. var password = document.forms["signupForm"]["unsafePassword"].value;
  34. if (username == "") {
  35. alert("Username must be filled out");
  36. return false;
  37. }
  38. if (password == "") {
  39. alert("password must be filled out");
  40. return false;
  41. }
  42. console.log(username, password);
  43. user.create(username, password, function(ack){
  44. user.auth(username, password, write(username));
  45. alert(JSON.stringify(ack));
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52. });
  53. }
  54.  
  55. function write(username){
  56. console.log("writing");
  57. var alice = {name: "Alice"};
  58. alice.boss = {name: "Fluffy", species: "Kitty", slave: alice};
  59. user.get('profile').put(alice, read());
  60. }
  61.  
  62. function read(){
  63. console.log("read...");
  64. user.get('profile').get('boss').get('slave').get('name').once(data =>
  65. console.log("The boss's slave's name is:", data) // Alice
  66. );
  67.  
  68. document.getElementById("accountStatus").innerHTML = "Your Signed Up! boss is " + data;
  69. }
  70.  
  71.  
  72.  
  73. </script>
  74. </body>
  75.  
  76. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement