ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 账号安全:优化教师账号强制绑定手机和修改密码的规则 修改的内容主要是: 1、教师账号必须绑定手机。即原来的强制绑定手机或邮箱,修改为强制绑定手机。 2、修改密码必须通过手机验证码。即每次修改密码都需要输入绑定的手机号获取验证码才能修改。 3、账号若一个月没有登录,需要验证手机。 具体页面显示见原型。 ***** 使用未名账号体系的课堂,弹窗顺序如下: 强制绑定手机 > 未登录超过1个月的身份验证 > 强制修改密码 > 版本更新内容提示 即账号安全提示的优先级要高于版本更新内容提示 ![](https://box.kancloud.cn/f8360a1352abd4373dbcc594ac8c2d19_341x748.png) ## 文件入口 D:\wamp\www\ketang.test\weike\themes\custom3\views\version2\login\themeType3\indexTeacher_cus.php ## 密码重置 http://ketang311.wm3dao.com/?r=user/getUserPwd&phone=15920914758&userId=672669&code=794362&isFromPhone=true&pageType=phone ## 修改密码入口 http://ketang.test/index.php?r=ktUser/password ***** ``` $(function(){ // Show bind phone > Show identity verify > Show modify password > Show notice box var isShowBindPhone = <?php echo V2IdentityService::factory()->getBoundPhone($userID) ? 0 : 1?>; if (isShowBindPhone) { tb_show('安全提示', '#TB_inline?width=400&height=250&inlineId=bind-box&modal=true', false); } else { var isVerifyIdentity = <?php echo V2UserService::factory()->isVerifyIdentity($userID) ? 1 : 0?>; isVerifyIdentity = 0; // todo test code, need to remove if (isVerifyIdentity) { // todo your code // tb_show('身份验证弹窗', '#TB_inline?width=400&height=250&inlineId=bind-box&modal=true'); } else { var isTipModifiedPwd = <?php echo V4SystemService::factory()->isTipModifiedPwd() ? 1 : 0?>; if (isTipModifiedPwd) { tb_show('安全提示', '#TB_inline?width=400&height=250&inlineId=safe-box&modal=true', false); } else { var isShowNotice = <?php echo UserService::factory() ->getUpdateNoticeValue($userID, WK::UPDATE_NOTIC_ITEM_ID_V3) ? 0 : 1?>; if (isShowNotice) { wk.notice.config('<?php echo $this->createUrl("/site/popNoticeV3", [ "width" => 802, 'height' => 550 ])?>', '<?php echo $this->createUrl("/login/saveNoticeBoxValue", ['itemID' => WK::UPDATE_NOTIC_ITEM_ID_V3])?>'); wk.notice.init(); } } } } //if (isTipModifiedPwd) { // tb_show('安全提示','#TB_inline?width=400&height=250&inlineId=safe-box&modal=true',false); //} // //checkIsBindEmailPhone(); //// 检测用户是否已经绑定了邮箱或手机,默认密码是否是123456 by wangbo 2019-2-28 //function checkIsBindEmailPhone() { // var url = "<?php //echo $this->createUrl('ktUser/checkUserDefaultPassword');?>//"; // $.get(url, function(data){ // // noBindEmailOrPhone : 检测用户是否已经绑定了邮箱或手机 // if (data == "noBindEmailOrPhone") { // tb_show('安全提示','#TB_inline?width=400&height=250&inlineId=bind-box&modal=true',false); // } // // UnsafePass : 判断是否为初始密码123456 // if (data == "UnsafePass") { // tb_show('安全提示','#TB_inline?width=400&height=250&inlineId=unpass-box&modal=true',false); // } // }); //} // 用户信息 by wuzhc (function(){ $.ajax({ url: "<?php echo $this->createUrl('ktUser/teacherInfo');?>", data:{}, type: "get", dataType:'json', success:function(data){ var user = data.user || {}; $("#site-sch").html(user.school); $("#site-subj").html(user.subject); $("#site-rank").html(user.rank); $("#site-activeness").html(user.activeness); }, error:function(){ console.log('获取用户信息失败'); } }); })(); // 资源统计 by wuzhc (function(){ $.ajax({ url: "<?php echo $this->createUrl('ktUser/teacherStat');?>", data:{}, type: "get", dataType:'json', success:function(data){ var list = data.data || []; for (var i = 0, len = list.length; i < len; i++) { var key = 'site-' + list[i].type; $("#"+key).text(list[i].total); } }, error:function(){ console.log('数据统计失败'); } }); })(); //跳转自UC同步登录 pengjch 2017-09-20 var synUc = "<?php echo $this->createUrl('default/synuclogin',array('appid'=>''));?>"; $(".js_jspx").click(function (e) { e.preventDefault(e); window.open(synUc+$(this).data('appid')); }) $(".js_jssq").click(function (e) { e.preventDefault(e); window.open(synUc+$(this).data('appid')); }) $(".js_shaike").click(function (e) { e.preventDefault(e); window.open(synUc+$(this).data('appid')); }) $(".js_ktyj").click(function (e) { e.preventDefault(e); window.open(synUc+$(this).data('appid')); }) }); ``` ### 未登录超过1个月的弹窗 ![](https://box.kancloud.cn/6541eff835aed6022faae7182d7e74e2_1326x501.png) ### 验证码 http://ketang311.wm3dao.com/index.php?r=user/getUserPwd ![](./img/R/2019-04-04_100845.png) D:\wamp\www\ketang.test\framework\web\widgets\captcha\CCaptcha.php D:\wamp\www\ketang.test\weike\protected\controllers\UserController.php ``` /** * 找回密码:发送手机号码 * @var String $phone 手机号码 * @var String $code 验证码 * @var int $userId 用户ID * @var array $userArr 存放绑定该手机号码的所有用户 * @author Cyrus 2013/10/30 */ public function actionSendPhonePwd() { if (!Yii::app()->user->isGuest) { //未登录情况下方能执行操作 echo CJSON::encode(array('result' => 'unlogin')); Yii::app()->end(); } $phone = RequestUtils::getNormalRequest('phone'); $code = RequestUtils::getNormalRequest('code'); $userId = RequestUtils::getNormalRequest('userId'); if (!VerifyUtils::checkMobile($phone)) { //手机格式不正确 echo CJSON::encode(array('result' => 'noPhone')); Yii::app()->end(); } $phoneDetail = V2IdentityService::factory()->getPhone(null,Yii::app()->params['APPLICATION_PARENT_MAP'][WEB_APP_ID],$phone); if (!$phoneDetail) { //手机号码不存在 echo CJSON::encode(array('result' => 'noExists')); Yii::app()->end(); } if ($code) { if (!$userId) { echo CJSON::encode(array('result' => 'error')); } if (Yii::app()->session['phone_code'] == $code) { $rs = V2IdentityService::factory()->checkPhoneCode($phone, $code); if ($rs) { echo CJSON::encode(array('result' => 'success', 'userId' => $userId, 'phone' => $phone, 'code' => Yii::app()->session['phone_code'])); Yii::app()->end(); } echo CJSON::encode(array('result' => 'error')); Yii::app()->end(); } echo CJSON::encode(array('result' => 'verifyError')); Yii::app()->end(); } else { //发送手机验证码 /** @var string $captchaCode 验证码,防止用户重复发送手机验证短信 add by wuzhc 2016-07-14 */ $captchaCode = RequestUtils::getNormalRequest('captchaCode'); if ($captchaCode != $this->createAction('captcha')->getVerifyCode()) { echo CJSON::encode(array('result' => 'codeError')); Yii::app()->end(); } //$phone_code = VerifyUtils::getRandomCode(6); if ($phoneDetail) { //$rs = true; //$rs = IdentityService::factory()->sendCodeToPhone($phone, $phone_code); $phone_code = V2IdentityService::factory()->sendPhoneCode($phoneDetail->fdUserID,$phone); if ($phone_code) { //发送成功 Yii::app()->session['phone_code'] = $phone_code; //验证码存入session echo CJSON::encode(array('result' => 'success', 'record' => 'one', 'userId' => $phoneDetail->user->id)); Yii::app()->end(); } else { $result = $phone_code == -1 ? 'sendLimit' : 'error'; echo CJSON::encode(array('result' => $result)); Yii::app()->end(); } } echo CJSON::encode(array('result' => 'error')); Yii::app()->end(); } } ``` 发送短信,要在服务器上测试。 {"result":"success","record":"one","userId":"672669"} //成功返回 D:\wamp\www\ketang.test\weike\protected\controllers\SiteController.php ``` public function actionVerifyIdentitySendPhonePwd() { if (Yii::app()->user->isGuest) { //登录情况下方能执行操作 echo CJSON::encode(array('result' => 'unlogin')); Yii::app()->end(); } $phone = RequestUtils::getNormalRequest('phone'); $code = RequestUtils::getNormalRequest('code'); // $userId = RequestUtils::getNormalRequest('userId'); if (!VerifyUtils::checkMobile($phone)) { //手机格式不正确 echo CJSON::encode(array('result' => 'noPhone')); Yii::app()->end(); } $phoneDetails = IdentityService::factory()->getBindPhoneUser($phone); if (!$phoneDetails) { //手机号码不存在 echo CJSON::encode(array('result' => 'noExists')); Yii::app()->end(); } $phoneDetail = V2IdentityService::factory()->getPhone(null,Yii::app()->params['APPLICATION_PARENT_MAP'][WEB_APP_ID],$phone); if (!$phoneDetail) { //手机号码不存在 echo CJSON::encode(array('result' => 'noExists')); Yii::app()->end(); } $captchaCode = RequestUtils::getNormalRequest('captchaCode'); if ($captchaCode != $this->createAction('captcha')->getVerifyCode()) { echo CJSON::encode(array('result' => 'codeError')); Yii::app()->end(); } if ($phoneDetail) { $phone_code = V2IdentityService::factory()->sendPhoneCode($phoneDetail->fdUserID,$phone); if ($phone_code) { //发送成功 Yii::app()->session['phone_code'] = $phone_code; //验证码存入session echo CJSON::encode(array('result' => 'success', 'record' => 'one', 'userId' => $phoneDetail->user->id)); Yii::app()->end(); } else { $result = $phone_code == -1 ? 'sendLimit' : 'error'; echo CJSON::encode(array('result' => $result)); Yii::app()->end(); } } echo CJSON::encode(array('result' => 'error')); Yii::app()->end(); } ``` 参考:http://ketang311.wm3dao.com/index.php?r=user/getUserPwd ### 倒计时功能 √ ``` /** 倒计时 * @param total 总时间 * @param str 字符 * @param original 选择器 */ function counter(count,original) { var countdown = setInterval(CountDown, 1000); function CountDown() { original.addClass("button_off").html("重新发送("+count+")"); if (count == 0) { original.removeClass("button_off").html("重新发送"); clearInterval(countdown); } count--; } } ``` ### 验证短信是否正确 √ /?r=site/verifyIdentitySendPhonePwd D:\wamp\www\ketang.test\weike\protected\controllers\SiteController.php