标签:
js部分
var options = { //target: ‘#divToUpdate‘, url: ‘/visitor/registeuser/activateUser‘, type:‘POST‘, dataType:"json", success:function(data) { var txt_content = document.getElementById("error_tips_text"); var div_tips = document.getElementById("error_tips"); var username_text = document.getElementById("username"); var mail_text = document.getElementById("email"); var btn = document.getElementById("active"); var login = document.getElementById("login"); if(data.error == ‘-2‘){ //location.reload(); txt_content.value = ‘无效的帐号,请重新输入‘; txt_content.style.display = "block"; username_text.value = ‘‘; mail_text.value = ‘‘; setTimeout(function(){txt_content.style.display = "none";}, 2000); }else if(data.error == ‘-1‘){ txt_content.value = ‘填写的邮箱与账号绑定的邮箱不匹配,请重新输入‘; txt_content.style.display = "block"; mail_text.value = ‘‘; setTimeout(function(){txt_content.style.display = "none";}, 2000); }else if(data.error == ‘-4‘){ txt_content.value = ‘帐号已经是激活状态,无需再激活‘; txt_content.style.display = "block"; mail_text.value = ‘‘; setTimeout(function(){txt_content.style.display = "none";}, 2000); } else if(data.error == ‘0‘){ login.style.height = "auto"; div_tips.style.width = "335px"; txt_content.innerHTML = ‘激活邮件已经发送到注册邮箱:‘; txt_content.innerHTML += "\r\n"+mail_text.value+‘,请您接收并激活链接。‘; txt_content.style.display = "block"; username_text.setAttribute("readonly", true); mail_text.setAttribute("readonly", true); btn.setAttribute("disabled", true); btn.value="成功激活"; }else{ txt_content.style.display = "block"; txt_content.value = ‘激活邮件发送失败,请稍后再试!‘; setTimeout(function(){location.reload();}, 2000); } }, error: function(data) { // error code alert(‘帐号激活不成功,请重新尝试‘); location.reload(); //window.location.href=‘/math/jietindex‘; } }; //pass options to ajaxForm $(‘#login_main_det‘).ajaxForm(options);
html部分
<?php $tittle = ‘激活账号-‘.SYS_NAME; $css = ‘loginuser‘; $js = ‘activeform,jquery.form,jquery.validate‘; $keywords = SITE_KEYWORD; $description = ‘登录‘.SYS_NAME.‘,在线快速搜题,答案就在这里,快来挖取吧‘; include $this->gettpl(‘/zheader/header‘); ?> <!-- login start --> <div class="login_wrap" id="login"> <div class="login_main"> <div class="login_main_title"> <a href="/visitor/loginuser.html" class="login_com" >激活账号</a> </div> <form class="login_main_det" id="login_main_det" action="/visitor/registeuser/activateUser" method="post"> <div class="login_main_det_li"> <div class="warning" id="error_tips"> <textarea class="warn_text" id="error_tips_text" style="width:100%;word-break:break-all;overflow:hidden;line-height:2.0"></textarea> </div> <input type="text" class="m_d_l_input" name="username" id="username" placeholder="请输入用户名"/> <div class="error_alert"></div> </div> <div class="login_main_det_li"> <input type="text" class="m_d_l_input" name="email" id="email" placeholder="请输入注册的邮箱"/> <div class="error_alert"></div> </div> <div class="login_main_det_li"> <input type="hidden" name="formhash" value="<?php echo FORMHASH;?>" /> <input type="hidden" name="resolution" class="resolution" value="" /> <input type="submit" class="img_button" value="激活"/> </div> </form> <div class="login_main_link"> <div class="login_main_link_de">没有帐号? 请先 <a href="/visitor/registeuser.html" title="注册页面">注册</a> </div> <div class="login_main_link_de">已有帐号? 欢迎 <a href="/visitor/loginuser.html" title="登录页面">登录</a> </div> <div class="login_main_link_de">忘记密码,请点击 <a href="/visitor/forpswd.html" title="忘记密码">忘记密码</a> </div> </div> </div> </div>
css部分
.warn_text{ margin-top: 8px; margin-bottom: 20px; display:none; font-size:16px; color:#007bc6; width:335px; padding: 10px 10px; border: 1px solid #ec6628; }
php部分
/** * activateUser 激活账号 * @author denghy 20150616 * * */ public function activateUser(){ if($this->is_post() && $this->submitcheck()) { $username = strval(getgpc(‘username‘, ‘P‘)); $email = strval(getgpc(‘email‘,‘P‘)); $model = $this->get_model("user/users"); $site = $model->check_user($username); if($site == false) { //$this->show_msg(‘无效的帐号,请重新输入‘, 4, ‘‘, 2, 2); $res_error = ERROR_INVALID_NAME; }elseif($site[‘state‘] != 0){ //$this->show_msg(‘帐号已是激活状态,请换一个账号‘, 4, ‘‘, 2, 2); $res_error = ERROR_NAME_EXISTED; }elseif($site[‘email‘] != $email){ //$this->show_msg(‘填写的邮箱与账号绑定的邮箱不匹配,请重新输入‘, 4, ‘‘, 2, 2); $res_error = ERROR_INVALID_PARAM; }else{ include ‘smtp/my_smtp.php‘; // $mailbody = Check_actnum(); //激活码 $smtpemailto = $email;//用户注册的邮箱 $EncodeStr = urlencode($username); $mailsubject = "a=".$EncodeStr."&p=".$site[‘password‘]; $regdet = array($username,$email); if (my_sendmail($smtpemailto,$mailsubject,$regdet,‘‘,3)){ //$this->show_msg("激活邮件已经发送到注册邮箱: <br />$email<br /> 请您接收并激活链接。", 3, ‘/visitor/loginuser‘,5,1); $res_error = ERROR_SUCCESS; }else{ $res_error = ERROR_OTHER; //$this->show_msg(‘激活邮件发送失败,请稍后再试!‘, 4, ‘‘, 2, 2); } } $data = array( ‘error‘ => $res_error ); echo json_encode($data); }else{ $this->show_msg(‘非法操作!‘, 4, ‘‘, 1, 2); } }
标签:
原文地址:http://www.cnblogs.com/tipcoo/p/5000974.html