public function actionEnterCode() { if (Yii::app()->user->isGuest) { $this->redirect(array('/user/login')); } $code_card = Yii::app()->getModule('user')->codeCard; if (empty($code_card['require'])) { $this->_finishLogin(); } if (Yii::app()->user->hasState('valid_login_code_is_set')) { $this->_finishLogin(); } $error = ''; if (!empty($_POST['code']) && !empty($_POST['session_id'])) { $add_data = $_POST['code']; $session_id = $_POST['session_id']; $request_type = 'validate_code'; } else { $add_data = ''; $session_id = ''; $request_type = 'logon'; } $request = array('request_type' => $request_type, 'user_id' => Yii::app()->user->getId(), 'add_data' => $add_data, 'session_id' => $session_id); $reply = array('error' => ''); CodeCard::request($request, $reply); if ($reply['error']) { $error = UserModule::t($reply['error']); } elseif ($reply['reply_type'] == 'success') { // set state and redirect to previous page or profile Yii::app()->user->setState('valid_login_code_is_set', true); $this->_finishLogin(); } $view = 'codeCard'; if (Yii::app()->getModule('user')->view) { $alt_view = Yii::app()->getModule('user')->view . '.login.' . $view; if (is_readable(Yii::getPathOfAlias($alt_view) . '.php')) { $view = $alt_view; } } $this->render($view, array('reply' => $reply, 'error' => $error)); }
public function actionGenCodeCard($request_type) { // Validate settings if (!Yii::app()->user->checkAccess("UserAdmin")) { $this->redirect(array('view', 'id' => $model->id)); } $code_card = Yii::app()->getModule('user')->codeCard; if (empty($code_card['host']) || empty($code_card['apy_key']) || empty($code_card['crypt_key'])) { $this->redirect(array('view', 'id' => $model->id)); } $model = $this->loadModel(); $profile = $model->profile; $error = ''; if ($request_type == 'validate_code') { if (empty($_POST['code']) || empty($_POST['session_id'])) { $this->redirect(array('view', 'id' => $model->id)); } $add_data = $_POST['code']; $session_id = $_POST['session_id']; } else { $add_data = $model->id; $session_id = ''; } $request = array('request_type' => $request_type, 'user_id' => Yii::app()->user->getId(), 'add_data' => $add_data, 'session_id' => $session_id); $reply = array('error' => ''); CodeCard::request($request, $reply); if ($reply['error']) { $error = UserModule::t($reply['error']); } elseif ($reply['reply_type'] == 'code_card') { // Savec codeCard expire date $profile->setAttribute('code_card_expire_date', $reply['add_data']['expire_date']); $profile->save(); // Save codeCard as PDF $pdf = new TCPDF('L', PDF_UNIT, 'BUSINESS_CARD_ES', true, 'UTF-8', false); //Basic setup $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); // set margins $pdf->SetMargins(0, 2, 4, true); $pdf->SetHeaderMargin(0); $pdf->SetFooterMargin(0); // set font $pdf->SetFont('helvetica', '', 8); $pdf->setCellHeightRatio(1.1); // add a page $pdf->AddPage(); $html = $this->renderPartial('codeCard', array('reply' => $reply), true); //echo $html; //exit; // output the HTML content $pdf->writeHTML($html, false); // reset pointer to the last page $pdf->lastPage(); $pdf->Output('CodeCard.pdf', 'D'); exit; } if ($reply['reply_type'] == 'validate_code') { $view = 'validate_code'; } else { $view = 'codeCard_empty'; } if (Yii::app()->getModule('user')->view) { $alt_view = Yii::app()->getModule('user')->view . '.admin.' . $view; if (is_readable(Yii::getPathOfAlias($alt_view) . '.php')) { $view = $alt_view; $this->layout = Yii::app()->getModule('user')->layout; } } $this->render($view, array('model' => $model, 'reply' => $reply, 'error' => $error)); }