View页面
<div class="main regalogin" id="item4"> <div class="main regalogin"> <div class="main regalogin reset_succeed"> <div class="register_contant_head"> <h2>重置密码</h2> <div class="clear"></div> </div> <div class="register_content"> <div class="regContent"> <form id="resetFrm" method="post"> <div class="regLine passwordbox"> <div class="item1"><span>*</span>手机/邮箱:</div> <div class="item2"><INPUT name="recvval" id="j_emailphone" maxLength="50" type="text" value="18676664709" placeholder="请输入手机号或邮箱号" errtip="#err_emailphone"></div> <div class="item3 messagenotic before">请输入手机号码或邮箱</div> <div class="item4 messagenotic" id="err_emailphone" style="display:none"></div> <div class="clear"></div> </div> <div class="regLine"> <div class="item1"><span>*</span>验证码:</div> <div class="item21"><INPUT name="code" id="validateCode" class="input2" type="text" placeholder="请输入验证码"> <a href="javascript:void(0);" id="j_getcode" class="verify_code">获取验证码</a> <!-- <input id="btnSendCode" type="button" value="发送验证码" οnclick="sendMessage()" />--> </div> <div class="item31"></div> <div class="clear"></div> </div> <div class="regLine passwordbox"> <div class="item1"><span>*</span>密码:</div> <div class="item2"><input name="pswd" type="password" maxlength="20" id="pswd" placeholder="请输入密码"></div> <div class="item3 messagenotic" style="display: none;">密码由4-20个字符组成,区分大小写</div> <div class="item5" style="display: block;"></div> <div class="clear"></div> </div> <div class="regLine passwordbox"> <div class="item1"><span>*</span>确认密码:</div> <div class="item2"><input name="repswd" type="password" maxlength="20" id="repswd" placeholder="请再次输入密码"></div> <div class="item4 messagenotic" style="display: none;">两次输入密码不一致</div> <div class="item5" style="display: none;"></div> <div class="clear"></div> </div> <div class="clear"></div> <div class="register_bottom"> <a href="javascript:void(0)" title="确定" id="j_subbtn">确定</a> </div> </form> </div> </div> <div class="realo_ewm"> <img src="<?php echo $base_url;?>static_supermarket/image/qrcode.jpg" /><br /> <span>扫一扫,有惊喜哦!</span> </div> <div class="clear"></div> </div> <script type="text/javascript"> var resetModule = { cmd: '', verifyobj: $('#j_getcode'), recvValue: '', //验证手机格式是否正确 validateMobilePhone: function (mobilePhone) { var reg = /^(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/; if ( reg.test(mobilePhone) ) { return true; } else { return false; } }, //验证邮箱格式是否正确 validateEmail: function (email) { var reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/; if ( !reg.test(email) ) { return false; } return true; }, _ajax: function(data){ var that = this; $.ajax({ type: "post",//使用post方法访问后台 url: base_url+'member/ajax/', data:data, dataType : 'json', error: function(){ if( this.registerBtn.hasClass('disabled') ){ this.registerBtn.removeClass('disabled'); }; $("#validateCode").val(''); }, success: function(result){ if(result.callback) { that[result.callback](result); }else{ } } }); }, checkSubmit: function(){ var code = $.trim( $('#validateCode').val() ); if ("" === code) { alert("验证码不能为空"); return false; } var pswd = $.trim( $('#pswd').val() ); var repswd = $.trim( $('#repswd').val() ); if (pswd === '') { alert("请输入密码"); return false; } if (pswd !== repswd) { alert("2次密码输入不一致"); return false; } return true; }, checkEmailPhone: function(){ var that = this; var obj = $('#j_emailphone'); var val = $.trim(obj.val()); var errtip = $(obj.attr("errtip")); if ("" === val) { errtip.prev().hide(); errtip.text("请输入手机号码或邮箱").show(); return false; } that.recvValue = val; if ( that.validateEmail(val) ) { that.cmd = 'verify_mail'; return true; } if ( that.validateMobilePhone(val)) { that.cmd = 'mobile'; return true; } errtip.prev().hide(); errtip.text("手机号码或邮箱格式不正确").show(); return false; }, getCodeSuccess: function(data){ if(data.error){ if((data.error == -301) || (data.error == -601)){ alert("发送失败:" + data.error); } else { alert("发送失败,请稍候重试"); } }else if(data.success){ } }, //绑定jq事件 init: function(){ var that = this; $('#j_emailphone').blur(function(){ that.checkEmailPhone(); }).focus(function(){ var errtip = $($(this).attr("errtip")); errtip.hide().prev().show(); }); $('#j_getcode').click(function(){ if (that.checkEmailPhone()) { if(that.verifyobj.hasClass("disabled")){ return; } //发送ajax data = {"cmd": that.cmd}; if(data){ that.verifyobj.addClass("disabled"); data["value"] = that.recvValue; data["callback"] = "getCodeSuccess"; that._ajax(data); } } else { return false; } }); $('#j_subbtn').click(function(){ $('#resetFrm').submit(); }); $('#resetFrm').submit(function(){ if (!that.checkSubmit()) { return false; } var send = $('#resetFrm').serialize(); $.post(base_url+'member/reset/', send, function(res){ if (0 === res.error) { alert(res.msg); setTimeout('window.location.href="http://lccs.p2pworks.com/member/reset_succeed"',1000); } else { alert(res.msg); } }, 'json'); return false; }); } }; resetModule.init(); </script>
Controller页面
<?php /** * * 2015-12-25 * 个人中心,登陆、登出 */ class Member extends LCCS_Controller { public function __construct() { parent::__construct (); $this->load->library('verifycode_lib','verifycode_lib'); $this->load->model('service/login_service','login_service'); $this->template->set_layout ( "default_login" ); } public function index() { $this->home(); } public function verify_img($nouse=''){ $this->load->library('verifycode_lib','verifycode_lib'); $this->verifycode_lib->create(); } /* * @author dengfei * 个人中心详情 */ public function home(){ $this->load->model('discuz/member_profile','profile'); $this->load->model('discuz/member_personal','personal'); $uid=$this->session_user['UserID']; $list=$this->profile->get_user_byid($uid); $name=$this->personal->get_user_byid($uid); $username=$name['username']; $num=$list['idcard']; $head=0; $tail=5; $idcard=$this->digitalReplacedAsterisk($head,$tail,$num); $gender=array( '3'=>'保密', '1'=>'男', '2'=>'女' ); $data=array('username'=>$username, 'realname'=>$list['realname'], 'gender'=>$gender[$list['gender']], 'idcard'=>$idcard, 'birthyear'=>$list['birthyear'], 'birthmonth'=>$list['birthmonth'], 'birthday'=>$list['birthday'], 'resideprovince'=>$list['resideprovince'], 'residecity'=>$list['residecity'], 'education'=>$list['education'], 'interest'=>$list['interest'] ); $this->template->build('home/home',$data); } /* * @author dengfei * 数字替换为*号 * $head 头部显示数字长度 * $tail 尾部显示数字长度 * $num 要替换的字符 */ public function digitalReplacedAsterisk($head, $tail, $num){ return substr($num,0,$head).str_replace(array(0,1,2,3,4,5,6,7,8,9),'*',substr($num,$head,(strlen($num)-$head-$tail))).substr($num,-$tail); } public function reset_succeed(){ $this->template->build('home/reset_succeed'); } public function register(){ $this->template->build('layouts/register'); } public function ajax(){ $data = $this->input->post(); $re = array('error'=>'参数不对','msg'=>''); if(isset($data['callback'])){ $re['callback'] = $data['callback']; unset($data['callback']); } $op = '_'.$data['cmd']; '_verify_mail'; unset($data['cmd']); if(method_exists($this, $op)){ $msg=$this->$op($data); if($msg && !isset($msg['success'])){ $re['error'] = $msg; } else{ unset($re['error']); $re['msg'] = $msg; } } echo json_encode($re); } private function _logout(){ return $this->session_service->session_logout(); } private function _register($data){ $verify_code = $data['validcode']; unset($data['validcode']); $this->load->library('verifycode_lib','verifycode_lib'); if(!$this->verifycode_lib->check($verify_code)){ return -401; } $this->load->model('discuz/common_member','common_member'); $where = array('username'=>$data['username']); $list = $this->common_member->get_users($where); if($list && count($list)){ return -301; } $this->load->model('discuz/member_profile', 'member_profile'); $uid = $this->member_profile->get_id_bymobile($data['mobile']); if($uid>0){ return -601; } $salt = _rand(6, 'str'); $password = md5(md5($data['password']).$salt); $uc_members_data = array( 'username' => $data['username'], 'password' => $password, 'regip' => $_SERVER["REMOTE_ADDR"], 'salt' => $salt ); if(isset($data['email']))$uc_members_data['email'] = $data['email']; $this->load->model('discuz/uc_members', 'uc_members'); $uid = $this->uc_members->user_insert($uc_members_data); $ucsynlogin=''; if($uid){ $data['uid'] = $uid; $member_data = array( 'uid' => $data['uid'], 'username' => $data['username'], 'password' => $password, ); if(isset($data['email']))$member_data['email'] = $member_data['email']; $this->load->model('discuz/common_member', 'member'); $this->member->user_insert($member_data); if(isset($data['mobile'])){ $member_profile_data = array( 'uid' => $data['uid'], 'mobile' => !empty($data['mobile'])? $data['mobile']:'', ); $this->member_profile->user_insert($member_profile_data); } $ucsynlogin = $this->session_service->session_login($data); }else{ return -501; } $this->load->library('common_html_lib'); return array('success'=>$ucsynlogin,'url'=>common_html_lib::get_back_url()); } private function _verify_mail($data){ $email = $data['value']; $this->load->library('verifycode_lib','verifycode_lib'); return $this->verifycode_lib->verify_mail($email); } private function _verify_mobile($data){ $mobile = $data['value']; $this->load->model('discuz/member_profile', 'member_profile'); $uid = $this->member_profile->get_id_bymobile($mobile); if($uid>0){ return -601; } $this->load->library('verifycode_lib','verifycode_lib'); return $this->verifycode_lib->verify_mobile($mobile); } public function _checkaccount($data){ $account = $data['value']; $this->load->model('discuz/common_member','common_member'); $where = array('username'=>$account); $list = $this->common_member->get_users($where); if($list && count($list)){ return -301; } return false; } /* * @author * 个人中心信息修改 */ public function update(){ $uid=$this->session_user['UserID'];//UID $req = $this->input->post (); $username = $req['username'];//用户名 $realname = $req['realname'];//真实姓名 $idcard = $req['idcard']; $gender = $req['gender'];//姓别 $education = $req['education']; //学历 $interest = $req['interest'];//兴趣爱好 $province = $req['province'];//省 $city = $req['city'];//市 $Wdate = $req['Wdate'];//时间 $birthyear = substr($Wdate,0,4); $birthmonth = substr($Wdate,5,2); $birthday = substr($Wdate,8,2); $newgender=array( '男'=>'1', '女'=>'2', '不限'=>'3' ); $gender=$newgender[$gender]; if ($realname) { $data['realname'] = $realname; } $data=array( 'uid'=>$uid, 'realname'=>$realname, 'idcard'=>$idcard, 'gender'=>$gender, 'education'=>$education, 'interest'=>$interest, 'resideprovince'=>$province, 'residecity'=>$city, 'birthyear'=>$birthyear, 'birthmonth'=>$birthmonth, 'birthday'=>$birthday ); //判断数组中是否有空值 foreach ($data as $k=>$v){ if($v==''){ unset($data[$k]); } } //表非空字段 $insert_data = array( 'bio' =>'', 'interest' => '', 'field1' => '', 'field2' => '', 'field3' => '', 'field4' => '', 'field5' => '', 'field6' => '', 'field7' => '', 'field8' => '', ); //组合数组提交 $insert_data=$data+$insert_data; $where=array('uid'=>$uid); $this->load->model('discuz/member_profile','profile'); $list=$this->profile->get_user_byid($uid); if($uid==$list['uid']) { $t=$this->profile->change_user($data, $where); echo json_encode($t); }else{ $this->profile->user_insert($insert_data); } } private function _mobile($data){ $mobile = $data['value']; // $this->load->model('discuz/member_profile', 'member_profile'); // $uid = $this->member_profile->get_id_bymobile($mobile); // if($uid>0){ // $this->load->library('verifycode_lib','verifycode_lib'); return $this->verifycode_lib->verify_mobile($mobile); // }else{ // return -601; // } } /* * 安全中心 * @author * */ public function safe(){ $this->template->build('home/safe'); } /* *安全中心密码修改 *@author * */ public function reset() { $uid = $this->session_user['UserID']; if (!$this->input->is_ajax_request()) { $this->template->build('home/reset'); return; } $this->load->library('verifycode_lib','verifycode_lib'); if(!$this->verifycode_lib->check($_POST['code'])){ exit( json_encode(array('error'=>1, 'msg'=>'验证码不正确')) ); } if ($_POST['pswd'] != $_POST['repswd']) { exit( json_encode(array('error'=>1, 'msg'=>'2次密码输入不一致')) ); } $this->load->model('discuz/member_personal','personal'); $password=md5(md5($_POST['repswd'])); $data=array('password'=>$password); $where=array('uid'=>$uid); $this->personal->update_psd($data,$where); exit( json_encode(array('error'=>0,'msg'=>'修改成功')) ); } /* * 安全中心手机邮箱修改 * @author * */ public function first(){ $uid = $this->session_user['UserID']; if (!$this->input->is_ajax_request()) { $this->template->build('home/phone_phone_one'); return; } $this->load->library('verifycode_lib','verifycode_lib'); if(!$this->verifycode_lib->check($_POST['code'])){ exit( json_encode(array('error'=>1, 'msg'=>'验证码不正确')) ); }else{ exit(json_encode(array('error'=>0,'msg'=>''))); } } public function double(){ $uid = $this->session_user['UserID']; if (!$this->input->is_ajax_request()) { $this->template->build('home/phone_phone_two'); return; } $this->load->library('verifycode_lib','verifycode_lib'); if(!$this->verifycode_lib->check($_POST['code'])){ exit( json_encode(array('error'=>1, 'msg'=>'验证码不正确')) ); } $res = $this->input->post(); $res=$res['recvval']; if(preg_match_all("/([a-z0-9_\-\.]+)@(([a-z0-9]+[_\-]?)\.)+[a-z]{2,3}/i", $res, $matches)) { $this->load->model('discuz/member_personal','personal');//邮箱 $data=array('email'=>$matches[0][0]); $where=array('uid'=>$uid); $this->personal->update_psd($data,$where); exit( json_encode(array('error'=>0,'msg'=>'修改成功')) ); }else{ $this->load->model('discuz/member_profile','profile');//手机号 $data=array('mobile'=>$res); $where=array('uid'=>$uid); $this->profile->change_user($data,$where); exit( json_encode(array('error'=>0,'msg'=>'修改成功')) ); } } public function quadruple(){ $this->template->build('home/phone_phone_three'); } } ?>