/** * 验证激活 * @return boolean 激活成功返回true */ protected function active() { $model = UserActive::model(); $active = $model->fetchUidByCode($this->code); if ($active) { unset($model); $model = User::model(); $user = $model->findByPk($active->id); if ($user && $user->email == $this->email) { $user->status = User::STATUS_ENABLE; return $user->save(); } } return false; }
/** * 生成用户激活码并加密返回 * @return string */ protected function code() { $code = Env::randStr(self::ACTIVE_CODE_LENGTH); $model = new UserActive(); $model->code = $code; $model->uid = $this->uid; if ($model->save()) { return base64_encode(Yii::app()->securityManager->encrypt($code)); } }