/** * 设置重新找回记录 * * 在findpwd中保存格式为:0000-00-00:num|0000-00-00:num * 0000-00-00:最后更新该记录的时间 * num : 最后更新记录的时候此种方式已经尝试的次数 * |: 在|左侧的,是用“邮箱”方式找回的记录,在|右侧,是用“手机”方式找回的记录 * @param string $type * @return true */ public function setRecode($type = self::WAY_EMAIL) { $findPwd = $this->info['findpwd']; $recodes = array(0 => '', 1 => ''); $typeCode = $type == self::WAY_MOBILE ? 0 : 1; $tryTime = $type == self::WAY_MOBILE ? $this->byMobileNum : $this->byEmailNum; /*如果重来没有尝试找回过密码*/ if (!$findPwd) { $recodes[$typeCode] = Pw::time2str(Pw::getTime(), 'Y-m-d') . ':1'; } else { list($recodes[0], $recodes[1]) = explode('|', $findPwd); /*如果该方式的找回密码方式没有尝试过*/ if (!($recode = $recodes[$typeCode])) { $recodes[$typeCode] = Pw::time2str(Pw::getTime(), 'Y-m-d') . ':1'; /*如果该方式的找回密码方式尝试过*/ } else { list($time, $num) = explode(':', $recode); /*如果该方式的上次找回密码不是在今天发生,那么这是今天第一次找回密码*/ if ($time != Pw::time2str(Pw::getTime(), 'Y-m-d')) { $recodes[$typeCode] = Pw::time2str(Pw::getTime(), 'Y-m-d') . ':1'; /*如果今天不是第一次尝试找回密码,并且今天尝试找回密码的次数已经超过规定次数,抛出错误*/ } elseif ($num >= $tryTime) { return new PwError('USER:findpwd.over.limit.' . $type); /*否则记录今天找回密码的次数*/ } else { $recodes[$typeCode] = $time . ':' . ($num + 1); } } } /* @var $userDs PwUser */ $userDs = Wekit::load('user.PwUser'); $userdm = new PwUserInfoDm($this->info['uid']); $userdm->setFindpwd(implode('|', $recodes)); return $userDs->editUser($userdm, PwUser::FETCH_DATA); }