ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# 教师账号强制绑定手机或邮箱 # 未名教师账号登录时检测是否绑定手机/邮箱、是否为初始密码123456,流程如下: ![](./img/Login.jpg) *D:\wamp\www\ketang.test\weike\protected\controllers\LoginController.php* actionIndex() *D:\wamp\www\ketang.test\weike\themes\custom3\views\version2\login\themeType3\indexTeacher_cus.php* ``` 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") { } // UnsafePass : 判断是否为初始密码123456 if (data == "UnsafePass") { } }); } ``` ## 方法 是否已绑定手机或邮箱 是否为初始密码123456 ## 修改新密码流程 判断是否是第一次修改默认密码 ↓ 获取验证码(找到密码) http://ketang311.wm3dao.com/index.php?r=User/resetUserPwd ## 绑定手机或邮箱 ### 01 绑定邮箱页面 http://ketang311.wm3dao.com/index.php?r=ktUser/bindEmail ![](./img/L/01.png) ### 02 发送邮件验证 http://ketang311.wm3dao.com/index.php?r=ktUser/sendEmailBind ``` POST email: 3330819360@qq.com isResend: false ``` ![](./img/L/02.png) ### 03 邮件内容 ![](./img/L/03.png) 绑定邮箱链接: http://ketang311.wm3dao.com/index.php?r=ktUser/clickBindEmail&code=185628ee07059c738991121740e84136&email=3330819360%40qq.com&userId=474897 *D:\wamp\www\ketang.test\weike\protected\controllers\KtUserController.php* ``` $userId = RequestUtils::getNormalRequest('userId'); $email = RequestUtils::getNormalRequest('email'); $code = RequestUtils::getNormalRequest('code'); $emailDetail = Email::model()->findByAttributes(['fdUserID'=>$userId,'fdEmail'=>$email]); if ($code && $code != md5($emailDetail->fdCode) && $email != $emailDetail->fdEmail) { $this->redirect_msgBox(array('ktUser/bindEmail'),array('msg'=> '参数错误,请重新绑定!')); Yii::app()->end(); } ... IdentityService::factory()->isBindEmailByUserID($userId); //判断用户是否绑定邮箱 ... ``` ### 表 wksvc.tbEmail ``` CREATE TABLE `tbEmail` ( `id` int(11) NOT NULL AUTO_INCREMENT, `fdUserID` int(11) DEFAULT NULL COMMENT '对应tbUser.id', `fdEmail` varchar(64) DEFAULT NULL COMMENT '电子邮件地址', `fdCode` varchar(8) DEFAULT NULL COMMENT '验证码,邮件验证需要md5加密生成一个链接', `fdSent` datetime DEFAULT NULL COMMENT 'fdCode生成的时间', `fdVerified` datetime DEFAULT NULL COMMENT '验证时间,0表示未验证', `fdDefault` tinyint(4) NOT NULL COMMENT '缺省的电子邮箱地址\n 0-普通\n 1-缺省', PRIMARY KEY (`id`), KEY `FK_Reference_52` (`fdUserID`), KEY `email` (`fdEmail`) ) ENGINE=MyISAM AUTO_INCREMENT=117831 DEFAULT CHARSET=utf8 COMMENT='电子邮件地址表,一个人可以拥有多个电子邮'; ``` ![](./img/L/04.png) ## 绑定手机 http://ketang311.wm3dao.com/index.php?r=ktUser/bindPhone ### 1 绑定手机 ![](./img/L/05.png) ### 2 手机验证 http://ketang311.wm3dao.com/index.php?r=user/addPhoneBind ``` POST phone: 15920914758 ``` ![](./img/L/06.png) *D:\wamp\www\ketang.test\weike\protected\controllers\UserController.php* ``` V2IdentityService::factory()->getBoundPhone($userId); //获取用户绑定的手机号 ... $args = array( 'uid' => $uid, 'num' => $num, 'verified' => $verified, 'outsideHost' => $outsideHost, 'code' => $code ); return Phone::model()->find($this->findPhone($args)); ... ``` ### 3 表 wksvc.tbPhone ``` CREATE TABLE `tbPhone` ( `id` int(11) NOT NULL AUTO_INCREMENT, `fdUserID` int(11) NOT NULL, `fdPhone` varchar(32) NOT NULL, `fdCode` varchar(8) DEFAULT NULL COMMENT '验证码,通过短信下发', `fdSent` datetime DEFAULT NULL COMMENT 'fdCode生成并发放的时间', `fdVerified` datetime DEFAULT NULL COMMENT '短信验证时间,0表示未验证', `fdDefault` tinyint(4) NOT NULL COMMENT '', PRIMARY KEY (`id`), KEY `FK_Reference_53` (`fdUserID`), KEY `phone` (`fdPhone`) ) ENGINE=MyISAM AUTO_INCREMENT=137535 DEFAULT CHARSET=utf8 COMMENT=''; ```