-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
195 lines (161 loc) · 6.98 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Myfavouritesandwich - An Unhosted demo</title>
<link rel="stylesheet" href="css/uncompressed/reset.css" />
<link rel="stylesheet" href="css/uncompressed/text.css" />
<link rel="stylesheet" href="general.css" />
<link rel="stylesheet" href="css/uncompressed/layout.css" />
<script src="Base64.js"></script>
<script src="sjcl/sjcl.js"></script>
<script src="unhosted.js"></script>
<script>
////////////////////
// data access: //
////////////////////
var unhosted = Unhosted();
function unlockUnhostedAccount(userName, password) {
unhosted.setWalletService("https://wallet.myfavouritesandwich.org/");
unhosted.setHostedWebDAV("https://wallet.myfavouritesandwich.org/");
unhosted.setUserName(userName);
unhosted.setPassword(password);
unhosted.connect();
show();
}
function lockUnhostedAccount() {
unhosted.setUserName(null);
}
function registerUnhostedAccount(userName, password, password2) {
if(password != password2) {
return "Please enter the same password twice";
}
unhosted.setUserName(userName);
unhosted.setPassword(password);
return unhosted.register();
}
function loadSandwich() {
var sandwich = unhosted.dav.get("favSandwich.json");
if(sandwich) {
return sandwich;
} else {
return {ingredients:["", ""]};
}
}
function saveSandwich(ingredients) {
unhosted.dav.put("favSandwich.json", {"ingredients":ingredients});
}
/////////////////////
// presentation: //
/////////////////////
function showCurrentUser(userName) {
document.getElementById('currentUser').innerHTML=
'Current user is <strong>'
+unhosted.getUserName()
+'</strong> [<a onclick="lockUnhostedAccount();show();">Lock</a>]';
}
function showCurrentSandwich(sandwich) {
document.getElementById('showFirstIngredient').innerHTML = sandwich.ingredients[0];
document.getElementById('showSecondIngredient').innerHTML = sandwich.ingredients[1];
document.getElementById('firstIngredient').value = sandwich.ingredients[0];
document.getElementById('secondIngredient').value = sandwich.ingredients[1];
}
function showLocked() {
document.getElementById('unlockedView').style.display='none';
document.getElementById('lockedView').style.display='block';
}
function showUnlocked() {
document.getElementById('lockedView').style.display='none';
document.getElementById('unlockedView').style.display='block';
}
function show() {
var userName = unhosted.getUserName();
if(userName) {
var sandwich = loadSandwich();
showCurrentUser(userName);
showCurrentSandwich(sandwich);
showUnlocked();
} else {
showLocked();
}
}
</script>
</head>
<body onload="show()">
<div class="preload"></div>
<div class="preload2"></div>
<div id="preheader"></div>
<div id="plateContainer">
<figure id="plate"></figure>
</div>
<div id="mainWrap">
<div id="lockedView">
<header>
<h1>My Favourite Sandwich</h1>
<p>Login</p>
<input id="user" name="unhostedacct" onfocus="if(this.value=='[email protected]'){this.className='formfocus'; this.value=''}" onblur="if(!this.value){this.className='formblur'; this.value='[email protected]'}" type="text" value="[email protected]"/>
<br>Password:<input id="pwd" name="unhostedacct" type="password"/>
<br><input class="submit" name="submit" type="submit" value="Submit!"
onclick="unlockUnhostedAccount(document.getElementById('user').value, document.getElementById('pwd').value);show();">
<p class="hint">hint:<span> get an <a href="https://dev.unhosted.org/register.php">unhosted developer's account</a>.</span></p>
</header>
<div id="register">
<p><strong>Don't have an account? </strong> Register here:</p>
username:<input id="registerAcct" name="unhostedacct" type="text" value="[email protected]"/>
<br>password:<input id="registerPwd" name="unhostedacct" type="password"/>
<br>repeat:<input id="registerPwd2" name="unhostedacct" type="password"/>
<input class="submit" name="submit" type="submit" value="Create account"
onclick="document.getElementById('errorText').innerHTML=registerUnhostedAccount(
document.getElementById('registerAcct').value,
document.getElementById('registerPwd').value,
document.getElementById('registerPwd2').value
)">
<p><span id="errorText"></span></p>
</div>
</div>
<div id="unlockedView" class="hidden">
<div id="preheader">
<span>
<span id="currentUser"></span>
</span>
</div>
<header class="data">
<p>My favourite sandwich has <strong><span id="showFirstIngredient"></span></strong> and
<strong><span id="showSecondIngredient"></span></strong> on it</p>
<input id="firstIngredient" name="firstIngredient" onfocus="if(this.value=='1st ingredient'){this.className='formfocus'; this.value=''}" onblur="if(!this.value){this.className='formblur'; this.value='1st ingredient'}" type="text" value="1st ingredient"/>
<input id="secondIngredient" name="secondIngredient" onfocus="if(this.value=='2nd ingredient'){this.className='formfocus'; this.value=''}" onblur="if(!this.value){this.className='formblur'; this.value='2nd ingredient'}" type="text" value="2nd ingredient"/>
<input class="submitingredients" name="submit" type="submit" value="Submit!" onclick="saveSandwich(
[document.getElementById('firstIngredient').value,
document.getElementById('secondIngredient').value]);show();"/>
</header>
</div>
<div id="footerSpacer"></div>
<footer>
<div class="wrapper">
<div id="leftcolumn">
<h3>So... what is this all about?</h3>
<p>
This is a fictional site that demonstrates the unhosted architecture, a tutorial, so you can take a look at the code to understand how unhosted web apps work. View the application source code <a href="http://github.com/michiel-unhosted/myfavouritesandwich/blob/master/index.html" target="_blank">here</a>. The popup that handles the <a href="http://webfinger.org" target="_blank">WebFinger</a> is <a href="http://github.com/michiel-unhosted/myfavouritesandwich/blob/master/popup.html" target="_blank">here</a>, and <a href="http://github.com/michiel-unhosted/myfavouritesandwich/blob/master/cb.html" target="_blank">here</a> is the <a href="http://code.google.com/apis/accounts/docs/OAuth2.html#CS" target="_blank">OAuth2-cs</a> callback.
</p>
<p>
<strong>myfavouritesandwich.org is not a commercial website, nor is it affiliated with any trademark</strong>
</p>
</div>
<figure id="island"></figure>
<div id="rightcolumn">
<h3>What is Unhosted?</h3>
<p>
<strong>Unhosted is a project for strengthening free software against hosted software.
</strong>
An unhosted web app is only source code. Dynamic data is encrypted and decentralised, to per-user storage nodes. This benefits <strong>free software</strong>, as well as <strong>scalability</strong>, <strong>robustness</strong>, and <strong>online privacy</strong>.
</p>
<p>
<strong>Check it out at <a href="http://www.unhosted.org">http://www.unhosted.org/</a></strong>
</p>
</div>
<div class="clear">
</div>
</footer>
</div>
</body>
</html>