From c1b9b716691aeaccb97aec550fb2782cc856f53b Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Thu, 23 Mar 2017 10:26:40 -0600 Subject: [PATCH] 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: 078801ce8546e8405047dc783f3cf39cd88668b6 --- bindata.go.REMOVED.git-id | 2 +- handlers.go | 8 ++++++++ templates/index.tmpl | 43 +++++++++++++++++++++++++++++++-------- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/bindata.go.REMOVED.git-id b/bindata.go.REMOVED.git-id index bf5f6b2..21d3f15 100644 --- a/bindata.go.REMOVED.git-id +++ b/bindata.go.REMOVED.git-id @@ -1 +1 @@ -c19fe3dc9ffad04d7007790f9903978aa803d05c \ No newline at end of file +083d9060ba97213d049e1f19f11ff57620b5956e \ No newline at end of file diff --git a/handlers.go b/handlers.go index eaf2111..e980bcf 100755 --- a/handlers.go +++ b/handlers.go @@ -73,6 +73,14 @@ func handlePageRequest(c *gin.Context) { version := c.DefaultQuery("version", "ajksldfjl") 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 { p.Update("*This page has now self-destructed.*\n\n" + p.Text.GetCurrent()) p.Erase() diff --git a/templates/index.tmpl b/templates/index.tmpl index d5d289c..1568bc2 100755 --- a/templates/index.tmpl +++ b/templates/index.tmpl @@ -193,11 +193,12 @@ $('#saveEditButton').addClass("failure"); } $('#saveEditButton').text(data.message); - if ($('#lockPage').val() == "Lock") { - $('#lockPage').text("Unlock"); - } else { - $('#lockPage').text("Lock"); - } + if (data.success == true && $('#lockPage').text() == "Lock") { + window.location = "/{{ .Page }}/view"; + } + if (data.success == true && $('#lockPage').text() == "Unlock") { + window.location = "/{{ .Page }}/edit"; + } }, error: function(xhr, error) { $('#saveEditButton').removeClass() @@ -218,10 +219,19 @@ passphrase: passphrase }), success: function(data) { - $('#saveEditButton').text(data.message); - if (data.success == true) { - window.location = "/{{ .Page }}/view"; + $('#saveEditButton').removeClass() + if (data.success == true) { + $('#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) { $('#saveEditButton').text(error); @@ -329,17 +339,32 @@
  • View
  • -
  • List
  • + {{ if (or (.IsLocked) (.IsEncrypted) )}} + {{ if .IsLocked }} +
  • Locked
  • + {{ else }} +
  • Encrypted
  • + {{ end }} + {{else}}
  • List
  • Edit
  • + {{end}}