public function actionSendMail() { if (!empty($_POST)) { Yii::import('ext.yii-mail.YiiMailMessage'); $message = new YiiMailMessage(); $message->setBody($_POST['content']); $message->subject = $_POST['subject']; $message->from = $_POST['email']; $message->to = Yii::app()->params['adminEmail']; if (Yii::app()->mail->send($message)) { $model = new Comments(); $model->title = $_POST['subject']; $model->content = $_POST['content']; $model->email = $_POST['email']; $model->name = $_POST['fullName']; $model->phone = $_POST['phone']; $model->created = time(); if ($model->save()) { return jsonOut(array('error' => false, 'message' => 'Cảm ơn bạn đã gửi thông tin, chúng tôi sẽ phản hồi cho bạn trong thời gian sớm nhất!')); } else { return json_encode(array('error' => true, 'message' => 'Lỗi hệ thống, gửi thông tin không thành công.')); } } else { return json_encode(array('error' => true, 'message' => 'Gửi thông tin không thành công')); } } }
/** * Recovery password */ public function actionRecovery() { $form = new UserRecoveryForm(); if (Yii::app()->user->id) { $this->redirect(Yii::app()->controller->module->returnUrl); } else { $email = isset($_GET['email']) ? $_GET['email'] : ''; $activkey = isset($_GET['activkey']) ? $_GET['activkey'] : ''; if ($email && $activkey) { $form2 = new UserChangePassword(); $find = User::model()->notsafe()->findByAttributes(array('email' => $email)); if (isset($find) && $find->activkey == $activkey) { if (isset($_POST['UserChangePassword'])) { $form2->attributes = $_POST['UserChangePassword']; if ($form2->validate()) { $find->password = Yii::app()->controller->module->encrypting($form2->password); $find->activkey = Yii::app()->controller->module->encrypting(microtime() . $form2->password); if ($find->status == 0) { $find->status = 1; } $find->save(); Yii::app()->user->setFlash('recoveryMessage', UserModule::t("New password is saved.")); $this->redirect(Yii::app()->controller->module->recoveryUrl); } } $this->render('changepassword', array('form' => $form2)); } else { Yii::app()->user->setFlash('recoveryMessage', UserModule::t("Incorrect recovery link.")); $this->redirect(Yii::app()->controller->module->recoveryUrl); } } else { if (isset($_POST['UserRecoveryForm'])) { $form->attributes = $_POST['UserRecoveryForm']; if ($form->validate()) { $user = User::model()->notsafe()->findbyPk($form->user_id); $activation_url = 'http://' . $_SERVER['HTTP_HOST'] . $this->createUrl(implode(Yii::app()->controller->module->recoveryUrl), array("activkey" => $user->activkey, "email" => $user->email)); $subject = UserModule::t("Bạn đã có yêu cầu phục hồi mật khẩu từ {site_name}", array('{site_name}' => Yii::app()->name)); $message = UserModule::t("Bạn đã có yêu cầu phục hồi mật khẩu từ {site_name}. Để nhận được mật khẩu mới bạn hãy vào link sau: {activation_url}.", array('{site_name}' => Yii::app()->name, '{activation_url}' => $activation_url)); if (Yii::app()->request->isAjaxRequest) { jsonOut(array('error' => false, 'msg' => 'Xin vui lòng kiểm tra email. Một hướng dẫn đã chuyển đến email của bạn.'), false); } UserModule::sendMail($user->email, $subject, $message); Yii::app()->user->setFlash('recoveryMessage', UserModule::t("Please check your email. An instructions was sent to your email address.")); $this->refresh(); } else { if (Yii::app()->request->isAjaxRequest) { jsonOut(array('error' => true, 'msg' => CActiveForm::validate($form))); } } } $this->render('recovery', array('form' => $form)); } } }
function ajaxOut($out) { if (!preg_match("/MSIE/", $_SERVER['HTTP_USER_AGENT'])) { jsonOut($out); } else { jlOut($out, 'text'); } }
public function actionSetPrimary() { if (!empty($_POST['album']) && !empty($_POST['image_id'])) { Images::model()->updateAll(array('is_primary' => 0), 'album_id=:album_id', array(':album_id' => $_POST['album'])); Images::model()->updateByPk($_POST['image_id'], array('is_primary' => 1)); jsonOut(array('error' => false, 'msg' => 'Chọn hình đại diện thành công.')); } }
//Save JSON $arr = array("nest" => array(), "hamburger" => "tasty"); array_push($arr["nest"], array("chicken" => "white", "beef" => "red")); saveJSON("nest", $arr); echo var_dump($arr); break; case 'msg': //Save JSON postAppMessage('io.overplay.mainframe', 'io.overplay.test', array("msg" => 'payload')); echo 'ok'; break; case 'msg2': //Save JSON postAppMessage('io.overplay.mainframe', 'io.overplay.testa', array("msg" => 'payload')); echo 'ok'; break; case 'poptest': $msg = popAppMessage('io.overplay.testa'); echo json_encode($msg); break; case 'null': $ar = array(); array_push($ar, null); array_push($ar, "alpha"); array_push($ar, null); array_push($ar, "beta"); jsonOut(json_encode($ar)); } } else { badReq('no test parameter'); }
} else { badReq('No data for that app'); } } else { badReq('missing appid'); } } else { if (isset($_REQUEST['appid'])) { //If the file does not exist, we will get FALSE as the $rval $rval = loadJSON(dpathFor($_REQUEST['appid']), false); if ($rval) { if (count($rval['payload']) == 0) { //empty object which PHP will incorrectly send down ad an array echo jsonOut(json_encode($rval, JSON_FORCE_OBJECT)); } else { echo jsonOut(json_encode($rval)); } } else { //Of course the below does not work in PHP 5.2! //http_response_code(404); //THIS f*****g hack should work on Chumbster $sapi_type = php_sapi_name(); if (substr($sapi_type, 0, 3) == 'cgi') { header("Status: 404 Not Found"); } else { header("HTTP/1.1 404 Not Found"); } //TODO CHumby F**K, of course JSON_FORCE_OBJECT is not PHP 5.2 echo json_encode(array('error' => 'no data for that app'), JSON_FORCE_OBJECT); } } else {
} } else { badReq('Wrong verb or no appid'); } break; case 'move': if (isPOST() && isset($_REQUEST['appid'])) { $res = moveApp($_REQUEST['appid']); header('Content-Type: application/json'); jsonOut(json_encode($res)); } else { badReq('Wrong verb or no appid'); } break; case 'moveToSlot': if (isPOST() && isset($_REQUEST['appid']) && isset($_REQUEST['slot'])) { $res = moveAppToSlot($_REQUEST['appid'], $_REQUEST['slot']); header('Content-Type: application/json'); jsonOut(json_encode($res)); } else { badReq('Wrong verb or no appid or no slot, dick ' . $_REQUEST['appid']); } break; case 'appsbystate': header('Content-Type: application/json'); jsonOut(json_encode(appsByState())); break; } } else { badReq('no command parameter, dipshit'); }