1 /** 2 * 3 * 修改密码 4 * 5 * @fileOverView 6 * @author <a href="mailto:zhang.gd@foxmail.com">Zhang Guangda</a> 7 * @date 2012-10-25 8 */ 9 define( 10 [ 11 "component/form", 12 "component/process_components", 13 "component/rsa", 14 "business/pwd_strength" 15 ], 16 function() { 17 var _html = '<div class="we_cell_form_box" attr="root"></div>', 18 _changeProcessHtml = '<a style="float:right" href="javascript:void(0)" attr="inner:changeBtn;click:changeProcess">通过手机修改>></a>', 19 _defaultUrl = $we.conf.ENV.__API + "/ajaxSafe/changePwd"; 20 21 /** 22 * 修改密码组件 23 * @lends $we.widget.modify_password 24 */ 25 $we.widget.reg("modify_password", { 26 /** 27 * @constructs 28 */ 29 init: function(el, params) { 30 this.el = el; 31 this.params = params || {}; 32 33 this.params.url = $we.utils.setValue(this.params.url, _defaultUrl); 34 }, 35 /** 36 * interfaces 37 * @memberOf $we.widget.modify_password# 38 */ 39 interfaces: { 40 /** 41 * render 42 * @memberOf $we.widget.modify_password# 43 */ 44 render: function() { 45 if (!$we.process.getData("independent")) { 46 this.tips = $we.widget.add("process.tips.small", this.el, { 47 content: "为了您的账号安全,请您修改密码。" 48 }); 49 } else { 50 if ($we.biz.use && $we.process.getData("phone")) this.append(this.el, _changeProcessHtml); 51 } 52 53 this.append(this.el, _html); 54 55 var me = this; 56 this.form = $we.widget.add("Form", this.node.root, { 57 form_elements: [{ 58 label: '输入当前密码', 59 type: 'password', 60 name: 'old_pwd', 61 events: "blur", 62 require: "true" 63 }, { 64 label: '输入新密码', 65 type: 'password', 66 name: 'new_pwd', 67 expression: function(e) { 68 var s=e.val(); 69 o = $we.pwdStrength(s); 70 if(o.errno != 0){ 71 return {valid:false,error_msg:o.msg}; 72 }else{ 73 return {valid:true}; 74 } 75 }, 76 info: '由6-30位字母和数字组成,不区分大小写,密码不可与用户名相同', 77 events: "blur", 78 require: "true" 79 }, { 80 label: '确认新密码', 81 type: 'password', 82 name: 'confirm_pwd', 83 expression: 'equal-new_pwd', 84 events: "blur", 85 require: "true" 86 }], 87 commit: function() { 88 me.notify("next"); 89 } 90 }); 91 }, 92 /** 93 * 检测是否合法 94 * @memberOf $we.widget.modify_password# 95 */ 96 checkValid: function() { 97 if (!this.form.valid()) 98 return false; 99 100 if (this.form.getValue("old_pwd") == this.form.getValue("new_pwd")) { 101 this.form.showError("confirm_pwd", "对不起,新密码不能与当前密码相同"); 102 return false; 103 } 104 105 return true; 106 107 }, 108 /** 109 * 修改密码 110 * @memberOf $we.widget.modify_password# 111 */ 112 modifyPassword: function(cb) { 113 if (this.sendingRequest) return; 114 115 this.sendingRequest = true; 116 var me = this; 117 $we.utils.request(this.params.url, { 118 oldpwd: $we.rsa.encrypt(this.form.getValue("old_pwd")), 119 newpwd: $we.rsa.encrypt(this.form.getValue("new_pwd")) 120 }, function(data) { 121 cb(data.data); 122 me.sendingRequest = false; 123 }, function(data) { 124 me.form.showError("confirm_pwd", data.msg || ""); 125 me.sendingRequest = false; 126 }, "POST", true); 127 } 128 }, 129 /** 130 * events 131 * @memberOf $we.widget.modify_password- 132 */ 133 events: { 134 /** 135 * 切换流程 136 * @memberOf $we.widget.modify_password- 137 */ 138 changeProcess: function() { 139 this.notify("close"); 140 // 如果是手机账号,那么切换流程的时候,把手机账号的提示的过程给跳过,然后再置回来 141 var isMainAccount = !!$we.process.getData("is_mobile_acc"); 142 if (isMainAccount) 143 $we.process.setData("is_mobile_acc", false); 144 $we.biz.use("modify_password_by_phone"); 145 if (isMainAccount) 146 $we.process.setData("is_mobile_acc", true); 147 } 148 }, 149 /** 150 * process 151 * @memberOf $we.widget.modify_password# 152 */ 153 process: { 154 /** 155 * start 156 * @memberOf $we.widget.modify_password# 157 */ 158 start: function() { 159 this.render(); 160 }, 161 /** 162 * end 163 * @memberOf $we.widget.modify_password# 164 */ 165 end: function() { 166 $(this.node.root).remove(); 167 this.tips && this.tips.remove(); 168 $(this.node.changeBtn).remove(); 169 }, 170 /** 171 * checkSucc 172 * @memberOf $we.widget.modify_password# 173 */ 174 checkSucc: function() { 175 if (this.checkValid()) { 176 var me = this; 177 this.modifyPassword(function(data) { 178 me.notify("goNext", data); 179 }); 180 } 181 } 182 } 183 }); 184 185 var _bindedHtml = '<div class="we_pop_content" attr="root"></div>'; 186 187 $we.widget.reg("modify_password.binded_account", { 188 init: function(el) { 189 this.el = el; 190 this.config = { 191 title: "您的账号为手机账号:"+$we.process.getData("phone")+"的绑定账号,被绑定账号与手机账号使用同一密码登录,请使用"+$we.process.getData("phone")+"登录后修改密码。" 192 }; 193 }, 194 interfaces: { 195 render: function() { 196 this.append(this.el, _html); 197 this.extend("process.tips.big", [this.node.root, this.config]); 198 var btmHtml = [ 199 '<strong>温馨提示:</strong><br />', 200 '如您需要解除与手机账号:'+$we.process.getData("phone")+'的绑定,可通过以下方法解除:<br />', 201 '1. 如您账号的绑定手机在身边,可用手机账号:'+$we.process.getData("phone")+'登录 ', 202 '<a target="_blank" href="/index.php?r=site/MenuAcctMagt">多账号管理</a>', 203 ' 解除绑定;<br />', 204 '2. 如您无法通过以上方法解除与手机账号的绑定,请通过 ', 205 '<a target="_blank" href="http://kf.sdo.com/sdch_unbind/apply_unbind.aspx">传真解绑</a>', 206 ' 服务解除手机绑定,解绑手机可同时解除与手机账号的关联。<br />' 207 ].join(""); 208 this.notify("renderBottom", btmHtml); 209 this.notify("setButton", {next:"完成"}); 210 } 211 }, 212 process: { 213 start: function() { this.render(); }, 214 end: function() { $(this.el).empty(); }, 215 checkSucc: function() { this.notify("close"); } 216 } 217 }); 218 219 return $we.widget.amd("modify_password"); 220 } 221 );