Beispiel #1
0
 /**
  * Add Todo
  * action from Ajax
  * @author Jack <*****@*****.**>
  * @created_date 2015-11-06
  * @updated_date 2015-11-06
  */
 public function addAction()
 {
     $request = new \Phalcon\Http\Request();
     //  check is Post
     if ($request->isPost()) {
         //  check request with Ajax
         if ($request->isAjax()) {
             //  get value from $_POST['name'], $_POST['job']
             $name = $request->getPost('name');
             $job = $request->getPost('job');
             //  get value from schema
             $json = file_get_contents($this->schema);
             $variable = json_decode($json);
             $count = 0;
             foreach ($variable->data as $key => $value) {
                 $data[$key]['id'] = $value->id;
                 $data[$key]['created'] = $value->created;
                 $data[$key]['name'] = $value->name;
                 $data[$key]['job'] = $value->job;
                 $count++;
             }
             $data[$count]['id'] = uniqid();
             $data[$count]['created'] = date('Y-m-d h:i:s');
             $data[$count]['name'] = $name;
             $data[$count]['job'] = $job;
             $insertData['data'] = $data;
             $variable = json_encode($insertData);
             file_put_contents($this->schema, $variable);
         }
     }
 }
Beispiel #2
0
 public function saveAction()
 {
     $contactform = new Contactform();
     $this->view->disable();
     $request = new \Phalcon\Http\Request();
     if ($request->isPost() == true) {
         $data = array();
         $contactform->name = $this->request->getPost("name");
         $contactform->email = $this->request->getPost("email");
         $contactform->subject = $this->request->getPost("subject");
         $contactform->message = $this->request->getPost("message");
         if ($contactform->save()) {
             $result['state'] = 'success';
             $result['message'] = 'Your message has been received';
         } else {
             $result['state'] = 'failure';
             foreach ($contactform->getMessages() as $message) {
                 $result['message'][] = $message;
             }
         }
         echo json_encode($result);
         if ($request->isAjax() == true) {
         }
     }
 }
Beispiel #3
0
 public function beforeDispatch(Event $event, Dispatcher $dispatcher)
 {
     $controller = $dispatcher->getControllerName();
     /* if you are attempting to access login controller, allow it to execute  */
     if ($controller == "login" || $controller == "register") {
         return;
     }
     /* get the username/password from the post  */
     $request = new \Phalcon\Http\Request();
     $username = $request->getPost("username");
     $password = $request->getPost("password");
     $auth_model = new Users();
     /* authenticate if attempt to login has been made */
     if (!empty($username) && !empty($password)) {
         $this->authenticate($username, $password, $auth_model);
     }
     /* logout auth */
     if ($controller == "logout") {
         $this->session->set("authorize", serialize((object) array()));
         $response = new \Phalcon\Http\Response();
         $response->redirect()->sendHeaders();
         exit;
     }
     /* if authentication failed for some reason */
     if (!$this->isAuthenticated()) {
         if ($request->isAjax()) {
             /* send failure response */
             $response = new \Phalcon\Http\Response();
             $response->setContent(json_encode(array('error' => 'invalid_auth')))->send();
             exit;
         } else {
             /* stay on the login page  */
             $dispatcher->forward(array('controller' => 'login', 'action' => 'index'));
             return false;
         }
     }
 }
<?php

$request = new Phalcon\Http\Request();
if ($request->isPost() == true) {
    if ($request->isAjax() == true) {
        echo 'Request was made using POST and AJAX';
    }
}
Beispiel #5
0
 /**
  * 校验是否有权限访问
  */
 protected function _checkPerm()
 {
     if (isset($this->casInfo['usuper']) && $this->casInfo['usuper']) {
         // 超级管理员
         return true;
     }
     $allowPerm = $this->_allowPerm();
     if (isset($allowPerm[$this->ctrl]) && in_array($this->act, $allowPerm[$this->ctrl])) {
         return true;
     }
     // ajax
     $request = new \Phalcon\Http\Request();
     if ($request->isAjax()) {
         return true;
     }
     if ($permMenu = $this->casInfo['permMenu']) {
         foreach ($permMenu as $menu) {
             if ($menu['m_controller'] == $this->ctrl && $menu['m_action'] == $this->act) {
                 return true;
             }
         }
     }
     return false;
 }