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

Asks for password on page load (if encrypted)

This commit is contained in:
Zack Scholl 2016-03-14 11:43:28 -04:00
parent d4a48ea392
commit 00f28d7544

View File

@ -72,17 +72,44 @@ a.deleteable {
<script> <script>
$( document ).ready(function() { $( document ).ready(function() {
var texi = document.getElementsByClassName("texi");
Array.prototype.forEach.call(texi, function(el) { {{ if .Encrypted }}
katex.render(el.getAttribute("data-expr"), el, { displayMode: false }); var pass1 = "";
event.preventDefault();
swal({
title: "Encryption",
text: "Enter your passphrase:",
type: "input",
showCancelButton: true,
closeOnConfirm: false,
animation: "slide-from-top",
inputPlaceholder: "Write something"
}, function(inputValue) {
if (inputValue === false) return false;
if (inputValue === "") {
swal.showInputError("You need to write something!");
return false
}
pass1 = inputValue;
$.ajax({
type: "POST",
//the url where you want to sent the userName and password to
url: '/{{ .Title }}/decrypt',
dataType: 'json',
data: JSON.stringify({
text: " ",
password: pass1
}),
success: function (data) {
if (data['success'] == true) {
swal("Decryption", "Decrypted!", "success");
window.location.href = '/{{ .Title }}/view';
} else {
swal("Decryption", data['status'], "error");
}
}
}); });
var texp = document.getElementsByClassName("texp");
Array.prototype.forEach.call(texp, function(el) {
katex.render(el.getAttribute("data-expr"), el, { displayMode: true });
}); });
$('.postdecrypt').click(function(event) { $('.postdecrypt').click(function(event) {
var pass1 = ""; var pass1 = "";
event.preventDefault(); event.preventDefault();
@ -121,6 +148,21 @@ $( document ).ready(function() {
}); });
}); });
}); });
{{ end }}
var texi = document.getElementsByClassName("texi");
Array.prototype.forEach.call(texi, function(el) {
katex.render(el.getAttribute("data-expr"), el, { displayMode: false });
});
var texp = document.getElementsByClassName("texp");
Array.prototype.forEach.call(texp, function(el) {
katex.render(el.getAttribute("data-expr"), el, { displayMode: true });
});
}); });