UX: Improve key reset mechanism

UX: Improve key reset mechanism

diff --git a/assets/javascripts/discourse/components/encrypt-preferences-dropdown.js.es6 b/assets/javascripts/discourse/components/encrypt-preferences-dropdown.js.es6
index 5a62c0e..c16cafd 100644
--- a/assets/javascripts/discourse/components/encrypt-preferences-dropdown.js.es6
+++ b/assets/javascripts/discourse/components/encrypt-preferences-dropdown.js.es6
@@ -18,6 +18,11 @@ export default DropdownSelectBoxComponent.extend({
       id: "managePaperKeys",
       icon: "ticket-alt",
       name: I18n.t("encrypt.manage_paper_keys.title")
+    },
+    {
+      id: "reset",
+      icon: "trash-alt",
+      name: I18n.t("encrypt.preferences.reset")
     }
   ]
 });
diff --git a/assets/javascripts/discourse/connectors/user-preferences-account/encrypt.js.es6 b/assets/javascripts/discourse/connectors/user-preferences-account/encrypt.js.es6
index bf340c1..56d3001 100644
--- a/assets/javascripts/discourse/connectors/user-preferences-account/encrypt.js.es6
+++ b/assets/javascripts/discourse/connectors/user-preferences-account/encrypt.js.es6
@@ -172,6 +172,9 @@ export default {
         case "managePaperKeys":
           showModal("manage-paper-keys", { model: this.model });
           break;
+        case "reset":
+          showModal("reset-key-pair", { model: this.model });
+          break;
       }
     },
 
diff --git a/assets/javascripts/discourse/controllers/reset-key-pair.js.es6 b/assets/javascripts/discourse/controllers/reset-key-pair.js.es6
index 5d2814f..28bdf36 100644
--- a/assets/javascripts/discourse/controllers/reset-key-pair.js.es6
+++ b/assets/javascripts/discourse/controllers/reset-key-pair.js.es6
@@ -1,31 +1,51 @@
+import discourseComputed from "discourse-common/utils/decorators";
 import { ajax } from "discourse/lib/ajax";
 import { popupAjaxError } from "discourse/lib/ajax-error";
 import ModalFunctionality from "discourse/mixins/modal-functionality";
-import { reload } from "discourse/plugins/discourse-encrypt/lib/discourse";
+import { deleteDb } from "discourse/plugins/discourse-encrypt/lib/database";
+import { Promise } from "rsvp";
 
 export default Ember.Controller.extend(ModalFunctionality, {
   onShow() {
     this.setProperties({
       inProgress: false,
-      everything: true
+      everything: true,
+      confirmation: ""
     });
   },
 
+  @discourseComputed("inProgress", "currentUser.username", "confirmation")
+  disabled(inProgress, username, confirmation) {
+    return inProgress || username !== confirmation;
+  },
+
   actions: {
     reset() {
       this.set("inProgress", true);
-      ajax("/encrypt/reset", {
-        type: "POST",
-        data: {
-          user_id: this.get("model.id"),
-          everything: this.everything
-        }
-      })
+
+      Promise.all([
+        ajax("/encrypt/reset", {
+          type: "POST",
+          data: {
+            user_id: this.get("model.id"),
+            everything: this.everything
+          }
+        }),
+        deleteDb
+      ])
         .then(() => {
+          this.currentUser.setProperties({
+            encrypt_public: null,
+            encrypt_private: null
+          });
+
           this.appEvents.trigger("encrypt:status-changed");
-          reload();
+          this.send("closeModal");
         })
-        .catch(popupAjaxError);
+        .catch(popupAjaxError)
+        .finally(() => {
+          this.set("inProgress", false);
+        });
     }
   }
 });
diff --git a/assets/javascripts/discourse/templates/modal/reset-key-pair.hbs b/assets/javascripts/discourse/templates/modal/reset-key-pair.hbs
index 571ad35..4de0235 100644
--- a/assets/javascripts/discourse/templates/modal/reset-key-pair.hbs
+++ b/assets/javascripts/discourse/templates/modal/reset-key-pair.hbs
@@ -6,9 +6,11 @@
       {{i18n "encrypt.reset.everything"}}
     </label>
   </p>
+  <p>{{{i18n "encrypt.reset.confirm_instructions" username=currentUser.username}}}</p>
+  {{input type="text" value=confirmation}}
 {{/d-modal-body}}
 
 <div class="modal-footer">
-  {{d-button class="btn btn-danger" icon="trash-alt" label="encrypt.reset.title" action=(action "reset") disabled=inProgress}}
+  {{d-button class="btn btn-danger" icon="trash-alt" label="encrypt.reset.title" action=(action "reset") disabled=disabled}}
   {{d-modal-cancel close=(action "closeModal")}}
 </div>
diff --git a/assets/stylesheets/common/encrypt.scss b/assets/stylesheets/common/encrypt.scss
index 709d6d8..a717f14 100644
--- a/assets/stylesheets/common/encrypt.scss
+++ b/assets/stylesheets/common/encrypt.scss
@@ -10,6 +10,10 @@
   input#passphrase {
     width: 100%;
   }
+
+  .select-kit-row.is-highlighted[data-value="reset"] {
+    background-color: $danger-low;
+  }
 }
 
 pre.exported-key-pair,
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index c5d6876..5f5cbc0 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -79,5 +79,6 @@ en:
 
       reset:
         title: "Reset Encryption Key Pair"
-        instructions: "Are you sure you want to reset the encryption key? This operation deletes the encryption key forever unless it was previously exported."
+        instructions: "Are you sure you want to reset the encryption key? This operation deletes the encryption key forever and you will not be able to access any encrypted messages unless you previously exported it."
+        confirm_instructions: "Please type <code>{{username}}</code> to confirm:"
         everything: "Uninvite from all encrypted private conversations (if any)"

GitHub sha: 0e37ded9