From: hylom Date: Tue, 27 Nov 2018 12:03:22 +0000 (+0900) Subject: js: add script for password reset X-Git-Tag: v0.1.6~14 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;ds=sidebyside;h=85b47e027f3e9ab125668eb96294ea36e4b9d6f4;p=newslash%2Fnewslash.git js: add script for password reset --- diff --git a/src/newslash_web/public/js/password-reset.js b/src/newslash_web/public/js/password-reset.js new file mode 100644 index 00000000..633c1f7a --- /dev/null +++ b/src/newslash_web/public/js/password-reset.js @@ -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, + }); + +};