139 lines
3.4 KiB
JavaScript
139 lines
3.4 KiB
JavaScript
import SKNetTask from "../ts/gear_2.3.4/net/SKNetTask";
|
|
import MsgAlert from "../ts/game/msg/MsgAlert";
|
|
|
|
cc.Class({
|
|
extends: cc.Component,
|
|
properties: {
|
|
edit1: cc.EditBox,
|
|
edit2: cc.EditBox,
|
|
edit3: cc.EditBox,
|
|
edit4: cc.EditBox,
|
|
},
|
|
|
|
start () {
|
|
},
|
|
|
|
/*
|
|
* 點擊確認按鈕
|
|
*/
|
|
onConfirmClick () {
|
|
if (!this.verifyAllPassword()) {
|
|
return;
|
|
}
|
|
let data = {
|
|
account: this.edit4.string,
|
|
safecode: this.edit1.string,
|
|
password: this.edit2.string,
|
|
};
|
|
SKNetTask.getWithJson("/change_password",data,(code,result)=>{
|
|
if(error){
|
|
MsgAlert.addMsg(`修改密碼失敗,請檢查網絡!錯誤碼[${code}]`);
|
|
return;
|
|
}
|
|
cc.sys.localStorage.setItem('password',data.password);
|
|
let logic = cc.find('Canvas').getComponent('LoginLogic');
|
|
if (logic && logic.psdEditBox) {
|
|
logic.psdEditBox.string = data.password;
|
|
}
|
|
MsgAlert.addMsg('修改登錄密碼成功!');
|
|
this.node.active = false;
|
|
});
|
|
},
|
|
|
|
/*
|
|
* 點擊取消按鈕
|
|
*/
|
|
onCancelClick () {
|
|
this.node.active = false;
|
|
},
|
|
|
|
/*
|
|
* 驗證所有格式
|
|
*/
|
|
verifyAllPassword () {
|
|
if (!this.verifyPassword(this.edit1.string, { minlen: 4, maxlen: 12, }, '安全密碼')) {
|
|
return false;
|
|
}
|
|
if (!this.verifyPassword(this.edit2.string, { minlen: 6, maxlen: 20, }, '帳號密碼')) {
|
|
return false;
|
|
}
|
|
if (!this.verifyPassword(this.edit3.string, { minlen: 6, maxlen: 20, }, '帳號密碼')) {
|
|
return false;
|
|
}
|
|
if (this.edit2.string != this.edit3.string) {
|
|
MsgAlert.addMsg('兩次密碼不一致!');
|
|
return false;
|
|
}
|
|
if (!this.verifyPassword(this.edit4.string, { minlen: 6, maxlen: 20, onlynum: false, }, '帳號')) {
|
|
return false;
|
|
}
|
|
return true;
|
|
},
|
|
|
|
onEditEnd (event, param) {
|
|
if (this.edit1.string.length > 0 &&
|
|
!this.verifyPassword(this.edit1.string, { minlen: 4, maxlen: 12, }, '安全密碼')) {
|
|
return;
|
|
}
|
|
if (this.edit2.string.length > 0 &&
|
|
!this.verifyPassword(this.edit2.string, { minlen: 6, maxlen: 20, }, '帳號密碼')) {
|
|
return;
|
|
}
|
|
if (this.edit3.string.length > 0 &&
|
|
!this.verifyPassword(this.edit3.string, { minlen: 6, maxlen: 20, }, '帳號密碼')) {
|
|
return;
|
|
}
|
|
if (this.edit3.string.length > 0 && this.edit2.string.length > 0 && this.edit2.string != this.edit3.string) {
|
|
MsgAlert.addMsg('兩次密碼不一致!');
|
|
return;
|
|
}
|
|
if (this.edit4.string.length > 0 &&
|
|
!this.verifyPassword(this.edit4.string, { minlen: 6, maxlen: 20, onlynum: false, }, '帳號')) {
|
|
return;
|
|
}
|
|
},
|
|
|
|
/*
|
|
* 驗證密碼格式
|
|
*/
|
|
verifyPassword (pass, opt, tipName) {
|
|
tipName = tipName || '';
|
|
if (opt.minlen && pass.length < opt.minlen) {
|
|
MsgAlert.addMsg(`${tipName}密碼長度不能少於${opt.minlen}位!`);
|
|
return false;
|
|
}
|
|
if (opt.maxlen && pass.length > opt.maxlen) {
|
|
MsgAlert.addMsg(`${tipName}密碼長度不能大於${opt.maxlen}位!`);
|
|
return false;
|
|
}
|
|
if (opt.mixing) {
|
|
if (/^[0-9]+$/.test(pass) || /^[a-zA-Z]+$/.test(pass)) {
|
|
MsgAlert.addMsg(`${tipName}密碼必須含有字母和數字!`);
|
|
return false;
|
|
}
|
|
}
|
|
if (typeof(opt.onlynum) == 'boolean' && !opt.onlynum) {
|
|
if (/^[0-9]+$/.test(pass)) {
|
|
MsgAlert.addMsg(`${tipName}密碼必須含有字母和數字!`);
|
|
return false;
|
|
}
|
|
}
|
|
if (! /^[a-zA-z0-9]+$/.test(pass)) {
|
|
MsgAlert.addMsg(`${tipName}密碼必須為字母或數字!`);
|
|
return false;
|
|
}
|
|
return true;
|
|
},
|
|
|
|
/*
|
|
* 點擊修改密碼按鈕
|
|
*/
|
|
onChangePassClick () {
|
|
this.edit1.string = '';
|
|
this.edit2.string = '';
|
|
this.edit3.string = '';
|
|
this.edit4.string = '';
|
|
this.node.active = true;
|
|
},
|
|
});
|