1
0
mirror of https://github.com/schollz/cowyo.git synced 2023-08-10 21:13:00 +03:00

Remove menu options when locking/encrypting

Former-commit-id: 9020d91d5e3f4ab07cc5ec8e5abfc68d7f30cc05 [formerly c501c57e329676731abd211e6f26619806db2bc6] [formerly 8c7c7f37bb87845da3af2e1a40ccf5bf73852846 [formerly 13d370370f4f68203998d8eee7ebacec61a6a2a6]]
Former-commit-id: da6da64e8940ef34512f9abc8ed5480a9d132a64 [formerly 6902d14822e41218409d23c5e8669afa370e1fb9]
Former-commit-id: a02186b53b69eff7a51d8cb61e9af0470113e7df
Former-commit-id: 078801ce85
This commit is contained in:
Zack Scholl 2017-03-23 10:26:40 -06:00
parent edcd2e7d09
commit c1b9b71669
3 changed files with 43 additions and 10 deletions

View File

@ -1 +1 @@
c19fe3dc9ffad04d7007790f9903978aa803d05c 083d9060ba97213d049e1f19f11ff57620b5956e

View File

@ -73,6 +73,14 @@ func handlePageRequest(c *gin.Context) {
version := c.DefaultQuery("version", "ajksldfjl") version := c.DefaultQuery("version", "ajksldfjl")
p := Open(page) p := Open(page)
// Disallow anything but viewing locked/encrypted pages
if (p.IsEncrypted || p.IsLocked) && command[0:2] != "/v" {
c.Redirect(302, "/"+page+"/view")
return
}
// Destroy page if it is opened and primed
if p.IsPrimedForSelfDestruct && !p.IsLocked && !p.IsEncrypted { if p.IsPrimedForSelfDestruct && !p.IsLocked && !p.IsEncrypted {
p.Update("*This page has now self-destructed.*\n\n" + p.Text.GetCurrent()) p.Update("*This page has now self-destructed.*\n\n" + p.Text.GetCurrent())
p.Erase() p.Erase()

View File

@ -193,11 +193,12 @@
$('#saveEditButton').addClass("failure"); $('#saveEditButton').addClass("failure");
} }
$('#saveEditButton').text(data.message); $('#saveEditButton').text(data.message);
if ($('#lockPage').val() == "Lock") { if (data.success == true && $('#lockPage').text() == "Lock") {
$('#lockPage').text("Unlock"); window.location = "/{{ .Page }}/view";
} else { }
$('#lockPage').text("Lock"); if (data.success == true && $('#lockPage').text() == "Unlock") {
} window.location = "/{{ .Page }}/edit";
}
}, },
error: function(xhr, error) { error: function(xhr, error) {
$('#saveEditButton').removeClass() $('#saveEditButton').removeClass()
@ -218,10 +219,19 @@
passphrase: passphrase passphrase: passphrase
}), }),
success: function(data) { success: function(data) {
$('#saveEditButton').text(data.message); $('#saveEditButton').removeClass()
if (data.success == true) { if (data.success == true) {
window.location = "/{{ .Page }}/view"; $('#saveEditButton').addClass("success");
} else {
$('#saveEditButton').addClass("failure");
} }
$('#saveEditButton').text(data.message);
if (data.success == true && $('#encryptPage').text() == "Encrypt") {
window.location = "/{{ .Page }}/view";
}
if (data.success == true && $('#encryptPage').text() == "Decrypt") {
window.location = "/{{ .Page }}/edit";
}
}, },
error: function(xhr, error) { error: function(xhr, error) {
$('#saveEditButton').text(error); $('#saveEditButton').text(error);
@ -329,17 +339,32 @@
<ul class="pure-menu-children"> <ul class="pure-menu-children">
<li class="pure-menu-item"><a href="/" class="pure-menu-link">New</a></li> <li class="pure-menu-item"><a href="/" class="pure-menu-link">New</a></li>
<hr> <hr>
{{ if (or (.IsLocked) (.IsEncrypted) )}}
{{ if .IsLocked }}
<li class="pure-menu-item"><a href="#" class="pure-menu-link" id="lockPage">{{ if .IsLocked }}Unlock{{ else }}Lock{{end}}</a></li>
{{ else }}
<li class="pure-menu-item"><a href="#" class="pure-menu-link" id="encryptPage">{{ if .IsEncrypted }}Decrypt{{ else }}Encrypt{{end}}</a></li>
{{ end }}
{{ else }}
<li class="pure-menu-item"><a href="#" class="pure-menu-link" id="encryptPage">{{ if .IsEncrypted }}Decrypt{{ else }}Encrypt{{end}}</a></li> <li class="pure-menu-item"><a href="#" class="pure-menu-link" id="encryptPage">{{ if .IsEncrypted }}Decrypt{{ else }}Encrypt{{end}}</a></li>
<li class="pure-menu-item"><a href="#" class="pure-menu-link" id="lockPage">{{ if .IsLocked }}Unlock{{ else }}Lock{{end}}</a></li> <li class="pure-menu-item"><a href="#" class="pure-menu-link" id="lockPage">{{ if .IsLocked }}Unlock{{ else }}Lock{{end}}</a></li>
<li class="pure-menu-item"><a href="/{{ .Page }}/history" class="pure-menu-link">History</a></li> <li class="pure-menu-item"><a href="/{{ .Page }}/history" class="pure-menu-link">History</a></li>
<hr> <hr>
<li class="pure-menu-item"><a href="#" class="pure-menu-link" id="selfDestructPage">Self-destruct</a></li> <li class="pure-menu-item"><a href="#" class="pure-menu-link" id="selfDestructPage">Self-destruct</a></li>
<li class="pure-menu-item"><a href="#" class="pure-menu-link" id="erasePage">Erase</a></li> <li class="pure-menu-item"><a href="#" class="pure-menu-link" id="erasePage">Erase</a></li>
{{ end }}
</ul> </ul>
</li> </li>
<li class="pure-menu-item {{ with .ViewPage }}pure-menu-selected{{ end }}"><a href="/{{ .Page }}/view" class="pure-menu-link">View</a></li> <li class="pure-menu-item {{ with .ViewPage }}pure-menu-selected{{ end }}"><a href="/{{ .Page }}/view" class="pure-menu-link">View</a></li>
<li class="pure-menu-item {{ with .ListPage }}pure-menu-selected{{ end }}"><a href="/{{ .Page }}/list" class="pure-menu-link">List</a></li> {{ if (or (.IsLocked) (.IsEncrypted) )}}
{{ if .IsLocked }}
<li class="pure-menu-item">Locked</li>
{{ else }}
<li class="pure-menu-item">Encrypted</li>
{{ end }}
{{else}}<li class="pure-menu-item {{ with .ListPage }}pure-menu-selected{{ end }}"><a href="/{{ .Page }}/list" class="pure-menu-link">List</a></li>
<li class="pure-menu-item {{ with .EditPage }}pure-menu-selected{{ end }}"><a href="/{{ .Page }}/edit" class="pure-menu-link"><span id="saveEditButton">Edit</span></a></li> <li class="pure-menu-item {{ with .EditPage }}pure-menu-selected{{ end }}"><a href="/{{ .Page }}/edit" class="pure-menu-link"><span id="saveEditButton">Edit</span></a></li>
{{end}}
</ul> </ul>