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

Added noprompting for encryption

Former-commit-id: 3c1e99d8a999aab6b054bd0b8bbf7a43369ef971 [formerly ee8f5a6e2f793ed9e381ededcf1154da00022ad8] [formerly 55a0d258aa83ce2683aedfc9da60d0568d864945 [formerly a7589f1408]]
Former-commit-id: e724a3bb346d7e3ebc487788b84ad276a3da21cf [formerly 250b7ea3ff87f0db61f3e4a4b8c54925c7d86285]
Former-commit-id: 5b2412d02eb7e2c1bb2d82d502a0eac2de4cc792
This commit is contained in:
Zack Scholl 2016-03-14 14:31:28 -04:00
parent 0b3f38922e
commit 4db31614ae
3 changed files with 21 additions and 33 deletions

View File

@ -29,11 +29,9 @@ func encryptionRoute(c *gin.Context) {
fmt.Println(option, title) fmt.Println(option, title)
var jsonLoad EncryptionPost var jsonLoad EncryptionPost
if option == "/decrypt" { if option == "/decrypt" {
fmt.Println("Decrypting...")
if c.BindJSON(&jsonLoad) == nil { if c.BindJSON(&jsonLoad) == nil {
var err error var err error
currentText, _, _, _, encrypted := getCurrentText(title, -1) currentText, _, _, _, encrypted := getCurrentText(title, -1)
fmt.Println(currentText, encrypted, jsonLoad.Password)
if encrypted == true { if encrypted == true {
currentText, err = decryptString(currentText, jsonLoad.Password) currentText, err = decryptString(currentText, jsonLoad.Password)
if err != nil { if err != nil {
@ -65,7 +63,6 @@ func encryptionRoute(c *gin.Context) {
} }
if option == "/encrypt" { if option == "/encrypt" {
if c.BindJSON(&jsonLoad) == nil { if c.BindJSON(&jsonLoad) == nil {
fmt.Println(jsonLoad)
p := WikiData{strings.ToLower(title), "", []string{}, []string{}, true} p := WikiData{strings.ToLower(title), "", []string{}, []string{}, true}
p.save(encryptString(jsonLoad.Text, jsonLoad.Password)) p.save(encryptString(jsonLoad.Text, jsonLoad.Password))
c.JSON(200, gin.H{ c.JSON(200, gin.H{
@ -114,7 +111,6 @@ func editNote(c *gin.Context) {
c.Redirect(302, "/"+title+"/view") c.Redirect(302, "/"+title+"/view")
} }
numRows := len(strings.Split(currentText, "\n")) + 10 numRows := len(strings.Split(currentText, "\n")) + 10
if currentVersion {
c.HTML(http.StatusOK, "index.tmpl", gin.H{ c.HTML(http.StatusOK, "index.tmpl", gin.H{
"Title": title, "Title": title,
"WikiName": RuntimeArgs.WikiName, "WikiName": RuntimeArgs.WikiName,
@ -124,20 +120,8 @@ func editNote(c *gin.Context) {
"Versions": versions, "Versions": versions,
"TotalTime": totalTime, "TotalTime": totalTime,
"SocketType": RuntimeArgs.Socket, "SocketType": RuntimeArgs.Socket,
"NoEdit": !currentVersion,
}) })
} else {
c.HTML(http.StatusOK, "index.tmpl", gin.H{
"Title": title,
"WikiName": RuntimeArgs.WikiName,
"ExternalIP": RuntimeArgs.ExternalIP,
"CurrentText": currentText,
"NumRows": numRows,
"Versions": versions,
"TotalTime": totalTime,
"SocketType": RuntimeArgs.Socket,
"NoEdit": true,
})
}
} }
} }
@ -148,6 +132,7 @@ func everythingElse(c *gin.Context) {
title := c.Param("title") title := c.Param("title")
if option == "/view" { if option == "/view" {
version := c.DefaultQuery("version", "-1") version := c.DefaultQuery("version", "-1")
noprompt := c.DefaultQuery("noprompt", "-1")
versionNum, _ := strconv.Atoi(version) versionNum, _ := strconv.Atoi(version)
if strings.ToLower(title) == "about" { if strings.ToLower(title) == "about" {
versionNum = -1 versionNum = -1
@ -159,9 +144,9 @@ func everythingElse(c *gin.Context) {
p := WikiData{strings.ToLower(title), "", []string{}, []string{}, false} p := WikiData{strings.ToLower(title), "", []string{}, []string{}, false}
p.save("") p.save("")
} }
renderMarkdown(c, currentText, title, versions, "", totalTime, encrypted) renderMarkdown(c, currentText, title, versions, "", totalTime, encrypted, noprompt == "-1")
} else if title == "ls" && option == "/"+RuntimeArgs.AdminKey && len(RuntimeArgs.AdminKey) > 1 { } else if title == "ls" && option == "/"+RuntimeArgs.AdminKey && len(RuntimeArgs.AdminKey) > 1 {
renderMarkdown(c, listEverything(), "ls", nil, RuntimeArgs.AdminKey, time.Now().Sub(time.Now()), false) renderMarkdown(c, listEverything(), "ls", nil, RuntimeArgs.AdminKey, time.Now().Sub(time.Now()), false, false)
} else if option == "/list" { } else if option == "/list" {
renderList(c, title) renderList(c, title)
} else if title == "static" { } else if title == "static" {
@ -180,7 +165,7 @@ func serveStaticFile(c *gin.Context, option string) {
} }
} }
func renderMarkdown(c *gin.Context, currentText string, title string, versions []versionsInfo, AdminKey string, totalTime time.Duration, encrypted bool) { func renderMarkdown(c *gin.Context, currentText string, title string, versions []versionsInfo, AdminKey string, totalTime time.Duration, encrypted bool, noprompt bool) {
r, _ := regexp.Compile("\\[\\[(.*?)\\]\\]") r, _ := regexp.Compile("\\[\\[(.*?)\\]\\]")
for _, s := range r.FindAllString(currentText, -1) { for _, s := range r.FindAllString(currentText, -1) {
currentText = strings.Replace(currentText, s, "["+s[2:len(s)-2]+"](/"+s[2:len(s)-2]+"/view)", 1) currentText = strings.Replace(currentText, s, "["+s[2:len(s)-2]+"](/"+s[2:len(s)-2]+"/view)", 1)
@ -218,6 +203,7 @@ func renderMarkdown(c *gin.Context, currentText string, title string, versions [
"TotalTime": totalTime.String(), "TotalTime": totalTime.String(),
"AdminKey": AdminKey, "AdminKey": AdminKey,
"Encrypted": encrypted, "Encrypted": encrypted,
"Prompt": noprompt,
}) })
} }

View File

@ -174,7 +174,7 @@
success: function (data) { success: function (data) {
if (data['success'] == true) { if (data['success'] == true) {
swal("Encryption", "Encrypted!", "success"); swal("Encryption", "Encrypted!", "success");
window.location.href = '/{{ .Title }}/view'; window.location.href = '/{{ .Title }}/view?noprompt=1';
} else { } else {
swal("Encryption", "Something went wrong.", "error"); swal("Encryption", "Something went wrong.", "error");
} }

View File

@ -74,9 +74,10 @@ a.deleteable {
$( document ).ready(function() { $( document ).ready(function() {
{{ if .Encrypted }} {{ if .Encrypted }}
{{ if .Prompt }}
var pass1 = ""; var pass1 = "";
swal({ swal({
title: "Encryption", title: "Decryption",
text: "Enter your passphrase:", text: "Enter your passphrase:",
type: "input", type: "input",
showCancelButton: true, showCancelButton: true,
@ -109,11 +110,12 @@ $( document ).ready(function() {
} }
}); });
}); });
{{ end }}
$('.postdecrypt').click(function(event) { $('.postdecrypt').click(function(event) {
var pass1 = ""; var pass1 = "";
event.preventDefault(); event.preventDefault();
swal({ swal({
title: "Encryption", title: "Decryption",
text: "Enter your passphrase:", text: "Enter your passphrase:",
type: "input", type: "input",
showCancelButton: true, showCancelButton: true,