-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
186 additions
and
61 deletions.
There are no files selected for viewing
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
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<html> | ||
<head> | ||
<title>GUN restricted SEA</title> | ||
</head> | ||
<body> | ||
<h1>Hello from authenticated with SEA</h1> | ||
<div> | ||
Visit the unauthed site | ||
<p id="unauthed"></p> | ||
</div> | ||
<form action="/" id="gunForm"> | ||
<input type="text" id="gunField"> | ||
</form> | ||
<div> | ||
<ul id="gunList"></ul> | ||
</div> | ||
<script src="http://localhost:8000/gun.js"></script> | ||
<script src="http://localhost:8000/gun/lib/cryptomodules.js"></script> | ||
<script src="http://localhost:8000/gun/sea.js"></script> | ||
<script src="authenticated-sea.js"></script> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
localStorage.clear() | ||
|
||
function init () { | ||
addListener(document.getElementById('gunForm'), 'submit', addLine) | ||
} | ||
|
||
const gun = Gun(`http://localhost:8000/gun`) | ||
const user = gun.user() | ||
|
||
user.create('alice', 'asdf', login) | ||
|
||
function login(ack){ | ||
console.log("login...") | ||
user.auth('alice', 'asdf', write) | ||
} | ||
|
||
function write (data) { | ||
user.get('lines').set('ready') | ||
generateUnauthLink(data.pub) | ||
} | ||
|
||
function generateUnauthLink (key) { | ||
const p = document.getElementById('unauthed') | ||
p.innerHTML = `<a href="http://localhost:4000?key=${key}" target="_blank">press me</a>` | ||
} | ||
|
||
function addListener (element, type, func) { | ||
element.removeEventListener(type, func) | ||
element.addEventListener(type, func) | ||
} | ||
|
||
function addLine (e) { | ||
e.preventDefault() | ||
const field = document.getElementById('gunField') | ||
user.get('lines').set(field.value) | ||
field.value = '' | ||
} | ||
|
||
function createLi (data) { | ||
const li = document.createElement('li') | ||
li.innerHTML = data | ||
return li | ||
} | ||
|
||
function updateLines () { | ||
console.log('updateLines') | ||
const ul = document.getElementById('gunList') | ||
ul.innerHTML = '' | ||
user.get('lines').map().val((value, index) => { | ||
const li = createLi(value) | ||
ul.appendChild(li) | ||
}) | ||
} | ||
|
||
gun.on('auth', () => { | ||
updateLines() | ||
}) | ||
|
||
function ready (fn) { | ||
if (document.readyState !== 'loading') { | ||
fn() | ||
} else { | ||
document.addEventListener('DOMContentLoaded', fn) | ||
} | ||
} | ||
|
||
ready(init) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<html> | ||
<head> | ||
<title>GUN restricted test</title> | ||
</head> | ||
<body> | ||
<h1>Hello from unauthenticated SEA</h1> | ||
<form action="/" id="gunForm"> | ||
<input type="text" id="gunField"> | ||
</form> | ||
<div> | ||
<ul id="gunList"></ul> | ||
</div> | ||
<script src="http://localhost:8000/gun.js"></script> | ||
<script src="http://localhost:8000/gun/lib/cryptomodules.js"></script> | ||
<script src="http://localhost:8000/gun/sea.js"></script> | ||
<script src="not-authenticated-sea.js"></script> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
localStorage.clear() | ||
const url = new URL(window.location.href) | ||
const publicKey = url.searchParams.get('key') | ||
|
||
function init () { | ||
addListener(document.getElementById('gunForm'), 'submit', addLine) | ||
} | ||
|
||
const gun = Gun('http://localhost:8000/gun') | ||
|
||
function addListener (element, type, func) { | ||
element.removeEventListener(type, func) | ||
element.addEventListener(type, func) | ||
} | ||
|
||
function addLine (e) { | ||
e.preventDefault() | ||
const field = document.getElementById('gunField') | ||
gun.get('lines').set(field.value) | ||
field.value = '' | ||
} | ||
|
||
function createLi (data) { | ||
const li = document.createElement('li') | ||
li.innerHTML = data | ||
return li | ||
} | ||
|
||
function updateLines () { | ||
const ul = document.getElementById('gunList') | ||
ul.innerHTML = '' | ||
gun.get(`pub/${publicKey}`).get('lines').map().val((value, index) => { | ||
const li = createLi(value) | ||
ul.appendChild(li) | ||
}) | ||
} | ||
|
||
gun.get(`pub/${publicKey}`).get('lines').on(() => { | ||
updateLines() | ||
}) | ||
|
||
function ready (fn) { | ||
if (document.readyState !== 'loading') { | ||
fn() | ||
} else { | ||
document.addEventListener('DOMContentLoaded', fn) | ||
} | ||
} | ||
|
||
ready(init) |