二次开发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" οnclick="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');
        }




©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页