OSDN Git Service

js: add script for password reset
authorhylom <hylom@users.sourceforge.jp>
Tue, 27 Nov 2018 12:03:22 +0000 (21:03 +0900)
committerhylom <hylom@users.sourceforge.jp>
Tue, 27 Nov 2018 12:03:22 +0000 (21:03 +0900)
src/newslash_web/public/js/password-reset.js [new file with mode: 0644]

diff --git a/src/newslash_web/public/js/password-reset.js b/src/newslash_web/public/js/password-reset.js
new file mode 100644 (file)
index 0000000..633c1f7
--- /dev/null
@@ -0,0 +1,47 @@
+var passwordReset = {};
+
+passwordReset.run = function run(params) {
+
+  Vue.component('message', {
+    props: ["key", ],
+    template: '#message',
+  });
+
+  var data = {
+    email: "",
+    message: "BLANK_ADDRESS",
+    state: "",
+  };
+
+  var methods = {};
+  methods.submit = function submit() {
+    this.state = "posting";
+    newslash.resetPassword(this.email).then(
+      (resp) => {
+        // ok
+        this.state = "succeed";
+        this.message = "SUCCEED";
+      },
+      (resp) => {
+        // failed
+        this.message = resp.error || "SERVER_ERROR";
+        this.state = "";
+      });
+  };
+
+  // form value validations
+  var watch = {};
+  watch.email = function watchEmail(val, oldVal) {
+    if (val.length == 0) { this.message = "BLANK_ADDRESS"; }
+    else if (val.search(/.@\w/) < 0) { this.message = "INVALID_ADDRESS"; }
+    else { this.message = ""; }
+  };
+
+  var vm = new Vue({
+    el: params.el,
+    data: data,
+    methods: methods,
+    watch: watch,
+  });
+
+};