reset_customer_password
生成 忘记密码 表单
表单输入
| 输入项 | 输入类型 | 字段名 | 是否必填 | 备注 |
|---|---|---|---|---|
| 邮箱 | customer[email] | 商家开启邮箱注册时必填 | ||
| 手机号 | phone | customer[phone] | 商家开启手机号注册时必填 | 手机号格式为: 国际封闭电话号码, 例如大陆手机号码:15600000000 |
| 区号 | text | customer[code] | 商家开启手机号注册时必填 | 区号为国际电话区号,例如大陆手机区号:86 |
| 密码 | password | customer[password] | 必填 | |
| 验证码 | text | customer[verifycode] | 必填 |
例子
{{#form 'reset_customer_password' id="reset-password-form"}}
<div class="account">
<label for="email">邮箱</label>
<input type="text" name="customer[email]" placeholder="邮箱" />
</div>
<div class="verifycode">
<input type="text" name="customer[verifycode]" placeholder="验证码" />
<button class="verifycode-button">发送</button>
</div>
<div class="password">
<label for="password">密码</label>
<input type="password" name="customer[password]" placeholder="密码" />
</div>
<div class="password">
<label for="passwordConfirm">确认密码</label>
<input type="password" name="customer[passwordConfirm]" placeholder="确认密码" />
</div>
<div class="submit">
<input class="submit-button" type="submit" value="重置密码">
</div>
{{/form}}
配合使用
以上代码需要结合下面的脚本一起使用
class PasswordNew {
constructor() {
this.form = document.querySelector('#reset-password-form');
this.form.addEventListener('submit', this.onSubmitHandler.bind(this));
this.verifyCodeButton = this.form.querySelector('.verifycode-button');
this.verifyCodeButton.addEventListener(
'click', this.onSendVerifyCodeHandler.bind(this)
);
this.passwordNew = new window.Shopline.customerAccount.PasswordNew(this.form)
}
// 发送邮箱或短信验证码逻辑
onSendVerifyCodeHandler(e) {
e.preventDefault();
if (this.verifyCodeButton.getAttribute('aria-disabled') === 'true') return;
this.verifyCodeButton.setAttribute('aria-disabled', true);
this.passwordNew.sendVerifyCode()
.then(response => {
if (response.errorMessage) {
this.verifyCodeError = true;
// 处理发送失败异常场景
}
})
.finally(() => {
if (!this.verifyCodeError) {
this.verifyCodeButton.removeAttribute('aria-disabled');
}
})
}
// 注册逻辑
onSubmitHandler(e) {
e.preventDefault();
this.passwordNew.submit()
.then(response => {
window.location.href = '/user/signIn';
})
.catch(error => {
// 处理注册失败异常场景
console.log(error)
})
}
}
window.Shopline.loadFeatures(
[
{
name: 'customer-account-api',
version: '0.3'
}
],
function(error) {
if (error) {
throw error;
}
new PasswordNew();
}
);
这篇文章对你有帮助吗?
SHOPLINE