1class ScriptFindpwd extends Script { 2 constructor(params) { 3 super(params) 4 this.$dom = document.querySelector(`#${this.attrId}`) 5 this.$form = this.$dom.querySelector(`form`) 6 this.$step1 = this.$dom.querySelector('.unit-findpwd__step-1') 7 this.$step2 = this.$dom.querySelector('.unit-findpwd__step-2') 8 this.$step3 = this.$dom.querySelector('.unit-findpwd__step-3') 9 this.$email = this.$dom.querySelector('.unit-findpwd__email') 10 this.$emailSite = this.$dom.querySelector('.unit-findpwd__email-site') 11 this.$code = this.$dom.querySelector('.unit-findpwd__code') 12 this.$codeSubmit = this.$dom.querySelector('.unit-findpwd__code-submit') 13 this.$password = this.$dom.querySelector(`.unit-findpwd__password`) 14 this.$password2 = this.$dom.querySelector(`.unit-findpwd__password2`) 15 this.$step2Error = this.$dom.querySelector('.unit-findpwd__step-2-error') 16 this.$emailGroup = this.$dom.querySelector('.unit-findpwd__email-group') 17 this.$submitContinue = this.$dom.querySelector('.unit-findpwd__group-continue') 18 this.$reminderLink = this.$dom.querySelector('.unit-findpwd__step-2-reminder_link') 19 this.step = 1 20 this.email = '' 21 this.verifyToken = '' 22 this.codeErrorNum = 0 23 } 24 /** åå§åï¼æ¯æå¼æ¥ */ 25 init() { 26 this.setStep(1) 27 this.bindCodeSubmitEvent() 28 this.bindFormSubmitEvent() 29 } 30 31 bindFormSubmitEvent() { 32 this.$form.onsubmit = event => { 33 event.preventDefault() 34 this.submit() 35 } 36 } 37 38 /** ç»å®éªè¯ç éåäºä»¶ */ 39 bindCodeSubmitEvent() { 40 41 this.$codeSubmit.addEventListener('click', () => { 42 this.retryCode() 43 }) 44 45 this.$reminderLink.addEventListener('click', async () => { 46 const isSendCode = await this.retryCode() 47 if (isSendCode) new Message().success(this.utilts.$t('The verification code has been sent')) 48 }) 49 } 50 51 /** æäº¤ */ 52 async submit() { 53 this.$form.classList.add('was-validated') 54 switch (this.step) { 55 case 1: 56 // æ£æ¥é®ç®± 57 if (!this.checkEmail()) break 58 // è°ç¨æ¥å£æ¥çå½åé®ç®±æ¯å¦åå¨ 59 if (!await this.checkAccount()) { 60 new Message().warn(this.utilts.$t('Account is not exists')) 61 break 62 } 63 // è ¾è®¯éªè¯ 64 if (!await this.utilts.checkTCaptcha('inquiry')) break 65 this.email = this.$email.value // å°è¾å ¥éªè¯æåçé®ç®±ä¿å䏿¥ 66 // åééªè¯ç 67 this.sendVerifyCode().then(res => { 68 this.$code.value = '' 69 // ä¸ä¸æ¥ 70 this.setStep(2) 71 }) 72 break 73 case 2: 74 // æ£æ¥éªè¯ç 75 this.verifyToken = await this.checkCodeSync() 76 if (!this.verifyToken) { break } 77 this.$password.value = '' 78 this.$password2.value = '' 79 // ä¸ä¸æ¥ 80 this.setStep(3) 81 break 82 case 3: 83 // 确认å¯ç 84 if (!this.checkPassWord()) { 85 break 86 } 87 // // ä¿®æ¹å¯ç 88 if (!await this.postResetPassWord()) break 89 // å»ç»å½ 90 this.gotoLogin() 91 break 92 } 93 } 94 95 checkEmail() { 96 const emailRexp = /[a-zA-Z0-9_\-]+(\.[a-zA-Z0-9_\-]+)*@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*(\.[a-zA-Z]{2,})$/ 97 if (!emailRexp.test(this.$email.value)) { 98 new Message().warn(this.utilts.$t('email format does not match')) 99 return false 100 } else { 101 return true 102 } 103 } 104 checkCodeSync() { 105 return new Promise(async (resolve, reject) => { 106 if (!this.$code.value) { 107 new Message().warn(this.utilts.$t('Please enter the verification code')) 108 resolve(false) 109 } else { 110 if (this.codeErrorNum >= 3) { 111 if (!await this.utilts.checkTCaptcha('inquiry')) { 112 resolve(false) 113 return 114 } 115 this.codeErrorNum = 0 116 } 117 this.requestCheckCode() 118 .then(token => resolve(token)) 119 .catch(_err => resolve(false)) 120 } 121 }) 122 } 123 checkPassWord() { 124 const reg = /(?=.*([a-zA-Z].*))(?=.*[0-9].*)[a-zA-Z0-9-*/+.~!@#$%^&*()]{6,20}$/ 125 if (!reg.test(this.$password.value)) { 126 new Message().warn(this.utilts.$t('Password contains at least numbers and letters length should be 6-20')) 127 return false 128 } else if (this.$password.value !== this.$password2.value) { 129 new Message().warn(this.utilts.$t('Confirm password is inconsistent with new password')) 130 return false 131 } 132 return this.$password.checkValidity() && reg.test(this.$password.value) && 133 this.$password.value === this.$password2.value 134 } 135 136 setStep(value) { 137 switch (value) { 138 case 1: 139 // å°æ¥éª¤1ï¼æ´æ°è§å¾ï¼æ¾ç¤ºé®ç®± 140 this.$step2.classList.remove('show') 141 this.$step3.classList.remove('show') 142 this.$step1.classList.add('show') 143 break 144 case 2: 145 // å°æ¥éª¤2ï¼æ´æ°è§å¾ï¼éªè¯ç 146 this.$step1.classList.remove('show') 147 this.$step3.classList.remove('show') 148 this.$step2.classList.add('show') 149 this.$emailSite.innerHTML = this.$email.value 150 break 151 case 3: 152 // å°æ¥éª¤3ï¼æ´æ°è§å¾ï¼æ°å¯ç 153 this.$step1.classList.remove('show') 154 this.$step2.classList.remove('show') 155 this.$step3.classList.add('show') 156 break 157 } 158 this.step = value 159 this.$form.classList.remove('was-validated') 160 } 161 162 /** å»ç»é */ 163 gotoLogin() { 164 new Message().success(this.utilts.$t('Update password success')) 165 window.location.href = globalThis.Server.getRinseHref('login.html', window.app.info.site) 166 } 167 168 169 /** 1.夿ä¼åè´¦å·æ¯å¦åå¨ */ 170 checkAccount() { 171 return this._getApi('/member/exists-by-account', { account: this.$email.value, site_id: window.app.info.site.site_id }) 172 } 173 174 /** 2.åéé®ä»¶éªè¯ç */ 175 sendVerifyCode() { 176 return new Promise((resolve, _reject) => { 177 this._getApi('/member-verify/send-code', { email: this.email }) 178 .then(res => resolve(res)) 179 .catch(err => { 180 new Message().error(err) 181 }) 182 }) 183 } 184 185 /** 3.éªè¯é®ä»¶éªè¯ç */ 186 requestCheckCode() { 187 return new Promise((resolve, _reject) => { 188 const params = { email: this.email, code: this.$code.value } 189 this._getApi('/member-verify/check-code', params, 'POST') 190 .then(res => { 191 // éªè¯ç é误 192 if (res.code === 120) { 193 this.codeErrorNum += 1 194 new Message().warn(this.utilts.$t(res.msg)) 195 resolve(null) 196 } 197 // éªè¯ç è¿æ 198 else if (res.code === 110) { 199 new Message().warn(this.utilts.$t(res.msg)) 200 this._showReSendCode() 201 resolve(null) 202 } 203 else resolve(res.verifyToken) 204 }) 205 .catch(_err => { 206 this._showReSendCode() 207 }) 208 }) 209 } 210 211 /** 4.éªè¯ç æ ¡éªå设置æ°å¯ç */ 212 postResetPassWord() { 213 const password = this.utilts.encodeBase64(this.$password.value) 214 const confirm_password = this.utilts.encodeBase64(this.$password2.value) 215 const params = { email: this.email, verifyToken: this.verifyToken, password, confirm_password } 216 return this._getApi('/member-verify/set-password', params, 'POST') 217 } 218 219 /** 忬¡åééªè¯ç */ 220 retryCode() { 221 return new Promise(async (resolve, _reject) => { 222 if (await this.utilts.checkTCaptcha('inquiry')) { 223 this.sendVerifyCode().then(_res => { 224 resolve(true) 225 this.$form.classList.remove('was-validated') 226 this.$code.value = '' 227 this.$step2Error.classList.add('d-none') // éè忬¡åé 228 this.$emailGroup.classList.remove('d-none') // æ¾ç¤ºè¾å ¥é®ç®±éªè¯ç 229 this.$submitContinue.classList.remove('d-none') // æ¾ç¤ºç»§ç» 230 this.$reminderLink.classList.remove('d-none') // æ¾ç¤ºæªæ¶å°éªè¯ç åé 231 }) 232 } else resolve(false) 233 }) 234 } 235 236 _getApi(url, params, method = 'GET') { 237 return new Promise((resolve, reject) => { 238 this.utilts.request({ url, method, params }) 239 .then(res => { 240 // æ£ç¡®æ°æ® 241 if (res.code === 0) resolve(res.data) 242 }).catch(err => { 243 //120éªè¯ç é误 110éªè¯ç è¿æ 244 if (err.code === 120 || err.code === 110) resolve(err) 245 else reject(err.msg) 246 }) 247 }) 248 } 249 250 /** æ¾ç¤ºéªè¯ç è¿æåæ¬¡åééªè¯ç */ 251 _showReSendCode() { 252 this.$step2Error.classList.remove('d-none') // æ¾ç¤ºå次åééè 253 this.$emailGroup.classList.add('d-none') // éèè¾å ¥é®ç®±éªè¯ç 254 this.$submitContinue.classList.add('d-none') // éèè¾å ¥é®ç®±éªè¯ç 255 this.$reminderLink.classList.add('d-none') // éèæªæ¶å°éªè¯ç åé 256 } 257} 258 259
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.