feat: Rename password by encryption key
All checks were successful
/ pre-commit (push) Successful in 1m9s
All checks were successful
/ pre-commit (push) Successful in 1m9s
Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
parent
634326190c
commit
8e1dd686d3
16 changed files with 118 additions and 117 deletions
|
@ -109,15 +109,15 @@ func (h *CreateNoteWithFormHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
|
|||
}
|
||||
|
||||
h.logger.Debug("checking inputs")
|
||||
noPassword := r.FormValue("no-password")
|
||||
password := r.FormValue("password")
|
||||
noEncryption := r.FormValue("no-encryption")
|
||||
encryptionKey := r.FormValue("encryption-key")
|
||||
expiration := r.FormValue("expiration")
|
||||
deleteAfterRead := r.FormValue("delete-after-read")
|
||||
language := r.FormValue("language")
|
||||
|
||||
if password == "" && noPassword == "" {
|
||||
h.logger.Debug("generating password")
|
||||
password = internal.GenerateChars(passwordLength)
|
||||
if encryptionKey == "" && noEncryption == "" {
|
||||
h.logger.Debug("generating encryption key")
|
||||
encryptionKey = internal.GenerateChars(encryptionKeyLength)
|
||||
}
|
||||
|
||||
h.logger.Debug("computing expiration")
|
||||
|
@ -129,7 +129,7 @@ func (h *CreateNoteWithFormHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
|
|||
}
|
||||
|
||||
h.logger.Debug("saving note to the database")
|
||||
note, err := h.db.Create(content, password, password != "", expirationInt, deleteAfterRead != "", language)
|
||||
note, err := h.db.Create(content, encryptionKey, encryptionKey != "", expirationInt, deleteAfterRead != "", language)
|
||||
if err != nil {
|
||||
h.PageData.Err = err
|
||||
h.Templates.ExecuteTemplate(w, templateName, h.PageData)
|
||||
|
@ -143,8 +143,8 @@ func (h *CreateNoteWithFormHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
|
|||
}
|
||||
|
||||
h.PageData.URL = fmt.Sprintf("%s%s/%s", scheme, r.Host, note.ID)
|
||||
if password != "" {
|
||||
h.PageData.URL += "/" + password
|
||||
if encryptionKey != "" {
|
||||
h.PageData.URL += "/" + encryptionKey
|
||||
}
|
||||
|
||||
h.logger.Debug("rendering page")
|
||||
|
@ -197,7 +197,7 @@ func (h *GetProtectedWebNoteHandler) ServeHTTP(w http.ResponseWriter, r *http.Re
|
|||
|
||||
vars := mux.Vars(r)
|
||||
id := vars["id"]
|
||||
password := vars["password"]
|
||||
encryptionKey := vars["encryptionKey"]
|
||||
|
||||
note, err := h.db.Get(id)
|
||||
|
||||
|
@ -213,8 +213,8 @@ func (h *GetProtectedWebNoteHandler) ServeHTTP(w http.ResponseWriter, r *http.Re
|
|||
return
|
||||
}
|
||||
|
||||
if password != "" && note.Encrypted {
|
||||
note.Content, err = internal.Decrypt(note.Content, password)
|
||||
if encryptionKey != "" && note.Encrypted {
|
||||
note.Content, err = internal.Decrypt(note.Content, encryptionKey)
|
||||
if err != nil {
|
||||
h.PageData.Err = fmt.Errorf("could not decrypt note: %v", err)
|
||||
h.Templates.ExecuteTemplate(w, templateName, h.PageData)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue