/
newEntry.html
69 lines (66 loc) · 2.41 KB
/
newEntry.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
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<?!= include('styles'); ?>
</head>
<body>
<form id="newEntryForm">
<table>
<tr>
<td>Name:</td>
<td><input type='text' name='name' id='name'></td>
</tr>
<tr>
<td>URL:</td>
<td><input type='text' name='url' id='url'></td>
</tr>
<tr>
<td>Username:</td>
<td><input type='text' name='username' id='username'></td>
</tr>
<tr>
<td>Password:</td>
<td><input type='password' name='password' id='password'></td>
</tr>
<tr>
<td>Shared Secret:</td>
<td><input type='password' name='sharedsecret' id='sharedsecret'></td>
</tr>
<tr>
<td>Re-type shared Secret:</td>
<td><input type='password' name='resharedsecret' id='resharedsecret'></td>
</tr>
<tr>
<td><input type="button" value="Save" name="submit" id="submitButton" onclick="submitForm()"/></td>
<td><span id="errorMessage"></span></td>
</tr>
</table>
<span id='errorMsg'></span>
</form>
<script src='https://cdnjs.cloudflare.com/ajax/libs/sjcl/1.0.7/sjcl.min.js'></script>
<script>
function submitForm() {
if (document.getElementById('sharedsecret').value != document.getElementById('resharedsecret').value) {
document.getElementById('errorMsg').innerHTML = 'Shared secret does not match';
return
}
document.getElementById('errorMsg').innerHTML = ''
document.getElementById('submitButton').value = "Saving...";
password = document.getElementById('password').value
sharedsecret = document.getElementById('sharedsecret').value
encryptedPassword = sjcl.encrypt(sharedsecret, password)
document.getElementById('password').value = encryptedPassword
document.getElementById('sharedsecret').value = ''
document.getElementById('resharedsecret').value = ''
google.script.run.withSuccessHandler(function(){
document.getElementById('submitButton').value = "Saved";
google.script.host.close();
}).withFailureHandler(function(error){
document.getElementById('submitButton').value = "Failed";
document.getElementById('errorMsg').innerHTML = error;
}).createNewEntry(document.getElementById('newEntryForm'));
}
</script>
</body>
</html>