二次開發shopnc默認的修改密碼流程

二開默認的修改密碼流程:

忘記密碼,輸入用戶名和註冊郵箱,發送驗證碼到該郵箱,通過該驗證碼直接進入修改密碼。

find_password_jym.php模板(輸入驗證碼模板)

<form action="index.php?act=login&op=find_password_modify" name="find_password_modify" id="find_password_modify">
    <input type="text" name="jym" id="jym"/>
    <input type="hidden" name="username" value="<?php echo $output['member_username'];?>"/>
    <input type="submit" value="提交" />
</form>


find_password_new.php模板的源代碼

<?php defined('InShopNC') or exit('Access Invalid!');?>
<style type="text/css">
.public-top-layout, .head-app, .head-search-bar, .head-user-menu, .public-nav-layout, .nch-breadcrumb-layout, #faq {
	display: none !important;
}
.public-head-layout {
	margin: 10px auto -10px auto;
}
.wrapper {
	width: 1000px;
}
#footer {
	border-top: none!important;
	padding-top: 30px;
}
</style>
<div class="nc-login-layout">
  <div class="left-pic"> <img src="<?php echo $output['lpic'];?>"  border="0"> </div>
  <div class="nc-login">
    <div class="nc-login-title">
      <h3><?php echo $lang['login_index_find_password'];?></h3>
    </div>
    <div class="nc-login-content" id="demo-form-site">
      <form action="index.php?act=login&op=find_password_new" method="POST" id="find_password_form">
        <?php Security::getToken();?>
        <input type="hidden" name="form_submit" value="ok" />
        <input name="nchash" type="hidden" value="<?php echo getNchash();?>" />
        <dl>
          <dt><?php echo $lang['login_password_you_account'];?></dt>
          <dd style="min-height:54px;">
            <input type="text" class="text" name="username" id="username"/>
            <label></label>
          </dd>
        </dl>
        <dl>
          <dt><?php echo $lang['login_password_you_email'];?></dt>
          <dd style="min-height:54px;">
            <input type="text" class="text" name="email"/>
            <label></label>
          </dd>
        </dl>
        <dl>
          <dt><?php echo $lang['login_register_code'];?></dt>
          <dd style="min-height:54px;">
            <input type="text" name="captcha" class="text w50 fl" id="captcha" maxlength="4" size="10" />
            <img src="index.php?act=seccode&op=makecode&nchash=<?php echo getNchash();?>" title="<?php echo $lang['login_index_change_checkcode'];?>" name="codeimage" border="0" id="codeimage" class="fl ml5"> <a href="javascript:void(0);" class="ml5" onclick="javascript:document.getElementById('codeimage').src='index.php?act=seccode&op=makecode&nchash=<?php echo getNchash();?>&t=' + Math.random();"><?php echo $lang['login_password_change_code']; ?></a>
            <label></label>
          </dd>
        </dl>
        <dl class="mb30">
          <dt></dt>
          <dd>
            <input type="button" class="submit" value="重置密碼" name="Submit" id="Submit">
          </dd>
        </dl>
        <input type="hidden" value="<?php echo $output['ref_url']?>" name="ref_url">
      </form>
    </div>
    <div class="nc-login-bottom"></div>
  </div>
</div>
<script type="text/javascript">
$(function(){
    $('#Submit').click(function(){
        if($("#find_password_form").valid()){
        	//ajaxpost('find_password_form', '', '', 'onerror');
                $("#find_password_form").submit();
        } else{
        	document.getElementById('codeimage').src='<?php echo SHOP_SITE_URL?>/index.php?act=seccode&op=makecode&nchash=<?php echo getNchash();?>&t=' + Math.random();
        }
    });
    $('#find_password_form').validate({
        errorPlacement: function(error, element){
            var error_td = element.parent('dd');
            error_td.find('label').hide();
            error_td.append(error);
        },
        rules : {
            username : {
                required : true
            },
            email : {
                required : true,
                email : true
            },
            captcha : {
                required : true,
                minlength: 4,
                remote   : {
                    url : 'index.php?act=seccode&op=check&nchash=<?php echo getNchash();?>',
                    type: 'get',
                    data:{
                        captcha : function(){
                            return $('#captcha').val();
                        }
                    }
                }
            } 
        },
        messages : {
            username : {
                required : '<?php echo $lang['login_usersave_login_usersave_username_isnull'];?>'
            },
            email  : {
                required : '<?php echo $lang['login_password_input_email'];?>',
                email : '<?php echo $lang['login_password_wrong_email'];?>'
            },
            captcha : {
                required : '<?php echo $lang['login_usersave_code_isnull']	;?>',
                minlength : '<?php echo $lang['login_usersave_wrong_code'];?>',
                remote   : '<?php echo $lang['login_usersave_wrong_code'];?>'
            }
        }
    });
});
</script> 
find_password_new1.php模板源代碼

<?php defined('InShopNC') or exit('Access Invalid!');?>
<style type="text/css">
.public-top-layout, .head-app, .head-search-bar, .head-user-menu, .public-nav-layout, .nch-breadcrumb-layout, #faq {
	display: none !important;
}
.public-head-layout {
	margin: 10px auto -10px auto;
}
.wrapper {
	width: 1000px;
}
#footer {
	border-top: none!important;
	padding-top: 30px;
}
</style>
<div class="nc-login-layout">
  <div class="left-pic"> <img src="<?php echo $output['lpic'];?>"  border="0"> </div>
  <div class="nc-login">
    <div class="nc-login-title">
      <h3><?php echo $lang['login_index_find_password'];?></h3>
    </div>
    <div class="nc-login-content" id="demo-form-site">
        <form action="index.php?act=login&op=find_password_modify" method="post" name="find_password_modify" id="find_password_modify">
            <input type="hidden" name="username" id="username" value="<?php echo $output['username'];?>"/>
            <dl>
                <dt>輸入您郵箱的校驗碼</dt>
                <dd style="min-height:54px;">
                  <input type="text" name="jym" id="jym" />
                  <label></label>
                </dd>
              </dl>
            <dl class="mb30">
                <dt></dt>
                <dd>
                  <input type="button" class="submit" value="下一步" name="Submit" id="Submit">
                </dd>
            </dl>
        </form>
    </div>
    <div class="nc-login-bottom"></div>
  </div>
</div>
<script type="text/javascript">
$(function(){
    $('#Submit').click(function(){
        if($("#find_password_modify").valid()){
        	//ajaxpost('find_password_form', '', '', 'onerror');
                $("#find_password_modify").submit();
        } else{
        	document.getElementById('codeimage').src='<?php echo SHOP_SITE_URL?>/index.php?act=seccode&op=makecode&nchash=<?php echo getNchash();?>&t=' + Math.random();
        }
    });
    $('#find_password_modify').validate({
        errorPlacement: function(error, element){
            var error_td = element.parent('dd');
            error_td.find('label').hide();
            error_td.append(error);
        },
        rules : {
            username : {
                required : true
            },
            jym:{
                required:true,
                minlength:6
            }
        },
        messages : {
            username : {
                required : '<?php echo $lang['login_usersave_login_usersave_username_isnull'];?>'
            },
            jym  : {
                required : '請輸入郵箱裏的校驗碼',
                minlength : '校驗碼不能小於6位'
            }
        }
    });
});
</script> 
find_password_new2.php模板源碼

<?php defined('InShopNC') or exit('Access Invalid!');?>
<style type="text/css">
.public-top-layout, .head-app, .head-search-bar, .head-user-menu, .public-nav-layout, .nch-breadcrumb-layout, #faq {
	display: none !important;
}
.public-head-layout {
	margin: 10px auto -10px auto;
}
.wrapper {
	width: 1000px;
}
#footer {
	border-top: none!important;
	padding-top: 30px;
}
</style>
<div class="nc-login-layout">
  <div class="left-pic"> <img src="<?php echo $output['lpic'];?>"  border="0"> </div>
  <div class="nc-login">
    <div class="nc-login-title">
      <h3><?php echo $lang['login_index_find_password'];?></h3>
    </div>
    <div class="nc-login-content" id="demo-form-site">
        <form method="post" id="password_form" name="password_form" action="index.php?act=login&op=find_password_modify2">
      <input type="hidden" name="form_submit" value="ok"  />
      
      <input type="hidden" name="username" value="<?php echo $output['username'];?>" />
      <dl>
        <dt><i class="required">*</i>新密碼:</dt>
        <dd>
          <input type="password"  maxlength="40" class="password" name="password" id="password"/>
          <label class="hint">6-20位字符,可由英文、數字及標點符號組成。</label></dd>
      </dl>
      <dl>
        <dt><i class="required">*</i>確認新密碼:</dt>
        <dd>
          <input type="password" maxlength="40" class="password" name="confirm_password" id="confirm_password" />
          <label for="confirm_password" generated="true" class="error"></label>
        </dd>
      </dl>
      <dl class="bottom">
        <dt> </dt>
        <dd><label class="submit-border">
          <input type="submit" class="submit" value="重置密碼" /></label>
        </dd>
      </dl>
    </form>
    </div>
    <div class="nc-login-bottom"></div>
  </div>
</div>
<script type="text/javascript">
$(function(){
    $('#password_form').validate({
        submitHandler:function(form){
            ajaxpost('password_form', '', '', 'onerror')
        },
        rules:{
            password:{
                required:true,
                minlength:6,
                maxlength:20
            },
            confirm_password:{
                required:true,
                equalTo:'#password'
            }
            
        },
        message:{
            password:{
                 required  : '<i class="icon-exclamation-sign"></i>請正確輸入密碼',
                 minlength:'<i class="icon-exclamation-sign"></i>請正確輸入密碼',
                 maxlength:'<i class="icon-exclamation-sign"></i>請正確輸入密碼'
            },
            confirm_password:{
                required   : '<i class="icon-exclamation-sign"></i>請正確輸入密碼',
                equalTo    : '<i class="icon-exclamation-sign"></i>兩次密碼輸入不一致'
            }
        }
       
    });
});
</script> 




修改login控制器中的forget_passwordOp方法替換默認的模板文件


輸入用戶名、註冊郵箱地址發送驗證碼到郵箱

/**
         * 忘記密碼,輸入賬戶名、正確的郵箱地址發送,校驗碼到郵箱
         * @author yang
         */
        public function find_password_newOp(){
            Language::read('home_login_register');
                $_pic = @unserialize(C('login_pic'));
                if ($_pic[0] != ''){
                        Tpl::output('lpic',UPLOAD_SITE_URL.'/'.ATTACH_LOGIN.'/'.$_pic[array_rand($_pic)]);
                }else{
                        Tpl::output('lpic',UPLOAD_SITE_URL.'/'.ATTACH_LOGIN.'/'.rand(1,4).'.jpg');
                }
                $result = chksubmit(true,true,'num');
		if ($result !== false){
		    if ($result === -11){
		        showDialog('非法提交');
		    }elseif ($result === -12){
		        showDialog('驗證碼錯誤');
		    }
		}
                if(empty($_POST['username'])){
			showDialog('用戶賬戶不能爲空');
		}
                if (process::islock('forget')) {
		    showDialog($lang['nc_common_op_repeat'],'reload');
		}
                $member_model	= Model('member');
		$member	= $member_model->getMemberInfo(array('member_name'=>$_POST['username']));
		if(empty($member) or !is_array($member)){
			showDialog('用戶賬戶不存在','reload');
		}
		if(empty($_POST['email'])){
			showDialog('郵箱地址不能爲空','reload');
		}
                if(strtoupper($_POST['email'])!=strtoupper($member['member_email'])){
			showDialog('您的郵箱不正確','reload');
		}
		//產生校驗碼
                $verify_code = rand(100,999).rand(100,999);
                $data = array();
                $data['auth_code'] = $verify_code;
                $data['send_acode_time'] = TIMESTAMP;
                $update = $member_model->editMemberCommon($data,array('member_id'=>$member['member_id']));
                if (!$update) {
                    exit(json_encode(array('state'=>'false','msg'=>'系統發生錯誤,如有疑問請與管理員聯繫')));
                }
                $model_tpl = Model('mail_templates');
                $tpl_info = $model_tpl->getTplInfo(array('code'=>'authenticate'));

                $param = array();
                $param['send_time'] = date('Y-m-d H:i',TIMESTAMP);
                $param['verify_code'] = $verify_code;
                $param['site_name']	= C('site_name');
                $subject = ncReplaceText($tpl_info['title'],$param);
                $message = ncReplaceText($tpl_info['content'],$param);
                $email	= new Email();
                $result	= $email->send_sys_email($member["member_email"],$subject,$message);
                if ($result) {
                    Tpl::output('username',$member['member_name']);
                    Tpl::showpage("find_password_new1");
                    //showDialog('驗證碼已發出,請注意查收','index.php?act=login&op=find_password_new&type=1&username='.$member['member_name'],'succ');
                } else {
                    showDialog('驗證碼發送失敗','reload');
                }
        }
在輸入驗證碼進行校驗

/**
         * 輸入郵箱中得到的校驗碼,進行驗證,驗證通過後進入修改密碼頁面,
         * @author yang
         */
        public function find_password_modifyOp(){
            Language::read('home_login_register');
            $_pic = @unserialize(C('login_pic'));
            if ($_pic[0] != ''){
                    Tpl::output('lpic',UPLOAD_SITE_URL.'/'.ATTACH_LOGIN.'/'.$_pic[array_rand($_pic)]);
            }else{
                    Tpl::output('lpic',UPLOAD_SITE_URL.'/'.ATTACH_LOGIN.'/'.rand(1,4).'.jpg');
            }
            $member_model	= Model('member');
            $member	= $member_model->getMemberInfo(array('member_name'=>$_POST['username']));
            if(empty($member) or !is_array($member)){
                showDialog('用戶賬戶不存在','reload');
            }
            $member_common_info = $member_model->getMemberCommonInfo(array('member_id'=>$member['member_id']));
            
            if (empty($member_common_info) || !is_array($member_common_info)) {
                showMessage('驗證失敗,請重新獲取驗證碼','index.php?act=login&op=forget_password','html','error');
            }
            if ($member_common_info['auth_code'] != $_POST['jym'] || TIMESTAMP - $member_common_info['send_acode_time'] > 1800) {
                showMessage('驗證碼已被使用或超時,請重新獲取驗證碼','index.php?act=login&op=forget_password','html','error');
            }
            $data=array();
            $data['auth_code']='';
            $data['send_acode_time']=0;
            $update=$member_model->editMemberCommon($data,array('member_id'=>$member['member_id']));
            if (!$update) {
                showMessage('系統發生錯誤,如有疑問請與管理員聯繫',SHOP_SITE_URL,'html','error');
            }
            Tpl::output('username',$member['member_name']);
            Tpl::showpage('find_password_new2');
            exit;
            
        }
驗證成功後進入真正修改密碼階段

/**
         * 真正去修改密碼
         * @author yang
         */
        public function find_password_modify2Op(){
            $model_member=Model('member');
            $member	= $model_member->getMemberInfo(array('member_name'=>$_POST['username']));
            if(empty($member) or !is_array($member)){
                showDialog('用戶賬戶不存在','reload');
            }
            if(!chksubmit()) exit();
            $obj_validate=new Validate();
            $obj_validate->validateparam=array(
                array('input'=>$_POST['password'],'require'=>"true","message"=>"請正確輸入密碼"),
                array('input'=>$_POST['confirm_password'],'require'=>"true","validator"=>"Compare","operator"=>"==","to"=>$_POST['password'],"message"=>"兩次密碼輸入不一致"),
            );
            $error=$obj_validate->validate();
            if($error!=''){
                showValidateError($error);
            }
            $update=$model_member->editMember(array('member_id'=>$member['member_id']),array('member_passwd'=>md5($_POST['password'])));
            $message = $update ? '密碼修改成功' : '密碼修改失敗';
            showDialog($message,SHOP_SITE_URL,$update ? 'succ' : 'error');
        }




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章