1class ScriptRegister extends Script { 2 constructor(params) { 3 super(params) 4 this.$form = document.querySelector(`#${this.attrId} form`) 5 this.$email = this.$form.querySelector('[type="email"]') 6 this.utils = Utilts.ins() 7 this.successHandles = [ 8 () => { this.utilts.setGtag('register') } 9 ] 10 } 11 /** åå§åï¼æ¯æå¼æ¥ */ 12 async init() { 13 this.inputInitEvent() 14 15 this.$form.onsubmit = event => { 16 // åæ¶é»è®¤äºä»¶ 17 event.preventDefault() 18 // 黿¢å泡äºä»¶ 19 event.stopPropagation() 20 // æäº¤ 21 this.submit() 22 } 23 } 24 25 handleRegisterSuccess() { 26 for (const handle of this.successHandles) { 27 if (typeof handle === 'function') { 28 handle() 29 } 30 } 31 } 32 33 /**表åæäº¤ */ 34 submit() { 35 const isTrue = this.checkSubmit() 36 if (!isTrue) return 37 if (Utilts.ins().checkDesign()) return 38 const that = this 39 const formData = new FormData(this.$form) 40 // æäº¤è¯·æ±ï¼ ï¼é¨ååæ°ææ¶æ²¡æï¼ 41 this.utils.request({ 42 url: '/member/register', 43 method: 'POST', 44 params: { 45 email: formData.get('email'), 46 password: this.utilts.encodeBase64(formData.get('password')), 47 confirm_password: this.utilts.encodeBase64(formData.get('confirm_password')), 48 site_id: window.app.info.site.site_id, 49 visitor_code: window.app.info.user.visitor_code, 50 visitor_id: window.app.info.user.visitor_id 51 }, 52 message: false 53 }) 54 .then(() => { 55 that.handleRegisterSuccess() 56 new Modal().confirm(Utilts.ins().$t('Register Success')) 57 .then(() => { 58 // new Message().loading('Heading to the login page') 59 // window.location.href = globalThis.Server.getRinseHref('/login.html', window.app.info.site) 60 //ç´æ¥ç»å½ 61 new Message().loading(Utilts.ins().$t('Welcome to the website')) 62 window.app.utilts.login({ username: formData.get('email'), password: formData.get('password') }) 63 }) 64 .catch(() => { 65 new Message().warn(Utilts.ins().$t('Cancel the login')) 66 for (const input of this.$form.querySelectorAll('input')) input.value = '' 67 }) 68 }) 69 .catch(err => { 70 new Message().error(err.msg) 71 }) 72 } 73 checkSubmit() { 74 let form_item = this.$form.querySelectorAll('.form-control') 75 for (const el of form_item) { 76 if (!this._checkForm(el)) return false 77 } 78 return true 79 } 80 /**表åå ç´ äºä»¶åå§å */ 81 inputInitEvent() { 82 let form_item = this.$form.querySelectorAll('.form-control') 83 for (const el of form_item) { 84 el.addEventListener('blur', () => this._checkForm(el)) 85 } 86 } 87 _checkForm(el) { 88 let val = el.value 89 const type = el.getAttribute('name') 90 let isTrue = true 91 // é®ç®±æ ¼å¼ 92 if (type === 'email') { 93 const reg = /^[^\.][a-zA-Z0-9\!\#\$\%\&\'\"\*\+\-\/\=\?\^\_\`\{\|\}\~\.]+@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,8})$/ 94 isTrue = this.checkFormValid(el, !reg.test(val)) 95 } 96 else if (type === 'password') { 97 const reg2 = /(?=.*([a-zA-Z].*))(?=.*[0-9].*)[a-zA-Z0-9-*/+.~!@#$%^&*()]{6,20}$/; 98 // å¯ç é¿åº¦3å°20å 99 isTrue = this.checkFormValid(el, !reg2.test(val)) 100 this.$form.querySelector('[name="confirm_password"]').setAttribute('pattern', val) 101 } 102 // 确认å¯ç ä¸å¯ç ä¸è´ 103 else if (type === 'confirm_password') { 104 const isValid = (val === '' || val !== this.$form.querySelector('[name="password"]').value) 105 isTrue = this.checkFormValid(el, isValid) 106 } 107 return isTrue 108 } 109 /**éªè¯è¡¨å */ 110 checkFormValid(el, match) { 111 // å¹é éªè¯è§å 112 if (match) { 113 // 表åç¦æ¢æäº¤ï¼ 表åå ç´ æç¤ºéè¯¯ä¿¡æ¯ 114 el.classList.remove('is-valid') 115 el.classList.add('is-invalid') 116 this.$form.classList.remove('was-validated') 117 return false 118 } 119 else { 120 // 表åè§£æ¾æäº¤ 121 el.classList.remove('is-invalid') 122 el.classList.add('is-valid') 123 return true 124 } 125 } 126}
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.