Example #1
0
 public function handleEditArticleAction()
 {
     if (!$this->getRequest()->isXmlHttpRequest()) {
         parent::notify("页面不存在");
         return false;
     }
     $uid = $this->getSession("uid");
     $email = $this->getSession("email");
     if (!isset($uid) || empty($uid) || !isset($email) || empty($email)) {
         $this->notify("请先登录", "http://" . $_SERVER["HTTP_HOST"] . "/login");
         return false;
     }
     Yaf_Dispatcher::getInstance()->disableView();
     $id = parent::getPost("id");
     $article = $this->m_study->Where("id=" . $id . " AND uid=" . $uid)->SelectOne();
     if (!$article) {
         die(json_encode(array("status" => 0, "msg" => "只能编辑自己的文章")));
     }
     if (!intval($article["status"])) {
         $this->notify("页面不存在");
         Yaf_Dispatcher::getInstance()->disableView();
         return false;
     }
     $title = parent::getPost("title");
     $category = (int) parent::getPost("category");
     $brief = parent::getPost("brief");
     $content = deep_htmlspecialchars(parent::getPost("content", false));
     $result = $this->m_study->UpdateByID(array("study_name" => $title, "sort_id" => $category, "content" => $content, "brief" => $brief), $id);
     if ($result) {
         die(json_encode(array("status" => 1, "msg" => "编辑文章成功", "url" => "http://" . $_SERVER["HTTP_HOST"] . "/study/detail?id=" . $id)));
     } else {
         die(json_encode(array("status" => 0, "msg" => "编辑文章失败")));
     }
 }
Example #2
0
 /**
  * 异步轮询消息
  */
 public function getMsgAction()
 {
     Yaf_Dispatcher::getInstance()->disableView();
     if (!$this->getRequest()->isXmlHttpRequest()) {
         parent::notify("页面不存在");
     }
     $uid = $this->getSession("uid");
     $redis = Yaf_Registry::get('redis');
     $msg = $redis->get("message_" . $uid);
     if ($msg) {
         $data = json_decode($msg, true);
         if (!$data["comment"]["status"]) {
             //$data["comment"]["status"]=0;//标记为已读
             $redis->set("message_" . $uid, json_encode($data));
             echo json_encode(array("status" => 1, "total" => $data["comment"]["total"], "type" => 1));
             exit;
         }
         if (!$data["reply"]["status"]) {
             //$data["reply"]["status"]=0;//标记为已读
             $redis->set("message_" . $uid, json_encode($data));
             echo json_encode(array("status" => 1, "total" => $data["reply"]["total"], "type" => 2));
             exit;
         }
     }
 }
Example #3
0
 public function handleRegAction()
 {
     Yaf_Dispatcher::getInstance()->disableView();
     if (!$this->getRequest()->isXmlHttpRequest()) {
         parent::notify("页面不存在");
     }
     //过滤判断
     $email = parent::getPost("email", false);
     if (!regex($email, "require")) {
         die(json_encode(array("status" => 0, "msg" => "邮箱不能为空")));
     }
     if (!regex($email, "email")) {
         die(json_encode(array("status" => 0, "msg" => "邮箱格式不正确")));
     }
     if (!empty($this->m_user->checkEmail($email))) {
         die(json_encode(array("status" => 0, "msg" => "邮箱已经注册过,请直接登录")));
     }
     $username = parent::getPost("username", false);
     if (!regex($username, "require")) {
         die(json_encode(array("status" => 0, "msg" => "昵称不能为空")));
     }
     if (!regex($username, "two")) {
         die(json_encode(array("status" => 0, "msg" => "昵称至少2个字符")));
     }
     if (!empty($this->m_user->checkUsername($username))) {
         die(json_encode(array("status" => 0, "msg" => "昵称已经存在,请换一个")));
     }
     $password = parent::getPost("password", false);
     if (!regex($password, "require")) {
         die(json_encode(array("statuc" => 0, "msg" => "密码不能为空")));
     }
     if (!regex($password, "six")) {
         die(json_encode(array("statuc" => 0, "msg" => "密码必须6-18位")));
     }
     $repassword = parent::getPost("repassword", false);
     if (!regex($repassword, "require")) {
         die(json_encode(array("statuc" => 0, "msg" => "确认密码不能为空")));
     }
     if ($password != $repassword) {
         die(json_encode(array("statuc" => 0, "msg" => "前后密码不一致")));
     }
     $checkcode = parent::getPost("checkcode", false);
     if (strtolower($checkcode) != strtolower(parent::getSession("verify_code"))) {
         die(json_encode(array("statuc" => 0, "msg" => "验证码不正确")));
     }
     $time = time();
     $token = md5($username . $password . $time);
     $data = array();
     $data["email"] = $email;
     $data["avatar"] = "/img/face.jpg";
     $data["username"] = $username;
     $data["password"] = md5($password);
     $data["reg_time"] = $time;
     $data["login_time"] = time();
     $data["login_ip"] = getClientIP();
     $data["point"] = 5;
     //注册point +5
     $data["token"] = $token;
     //用户名+密码+注册时间md5生成
     $data["token_expire"] = time() + 60 * 60 * 24 * 365;
     //token失效时间为365天
     $uid = $this->m_user->Insert($data);
     //如果插入成功
     if ($uid) {
         $verifyUrl = "http://thaidh.com/login/active/verify/";
         $link = "<a href='" . $verifyUrl . $token . "' target='_blank'>" . $verifyUrl . $token . "</a>";
         $body = "亲爱的" . $username . ":<br/>感谢您在泰语导航注册账号。<br/>请点击下面的链接激活您的账号。<br/>" . $link . "<br/>如果以上链接无法点击,请将它复制到浏览器地址栏,进行访问,该链接48小时内有效";
         //邮件内容
         if (sendMail($email, "新用户注册激活邮件", $body)) {
             //登录成功写入SESSION并且跳转到首页
             parent::setSession('uid', $uid);
             parent::setSession('email', $email);
             die(json_encode(array("status" => 1, "msg" => "恭喜您,注册成功!<br/>请登录到您的邮箱及时激活您的账号,如果没有找到,请到垃圾箱查找")));
         } else {
             die(json_encode(array("status" => 0, "msg" => "邮件发送失败,可能您填写的邮箱国内服务器到不了")));
         }
     } else {
         die(json_encode(array("status" => 0, "msg" => "注册失败,请稍候再试")));
     }
 }