Esempio n. 1
0
 /**
  * Authenticates a user.
  * @return boolean whether authentication succeeds.
  */
 public function authenticate()
 {
     // CODE FOR LDAP
     // try {
     //     $ldap_check = new LDAPQuery($this->username, $this->password);
     //     if ($ldap_check->get_connection()) {
     //         if(!$ldap_check->get_bind()) $this->errorCode = self::ERROR_PASSWORD_INVALID;
     //         else $this->errorCode = self::ERROR_NONE;
     //     }
     // } catch (LDAPQueryException $e) {
     //     $this->errorCode = self::ERROR_LDAP_BINDING;
     // }
     if (LdapUsers::model()->exists('username=:username', array(':username' => $this->username)) && strlen($this->password) > 0) {
         $this->errorCode = self::ERROR_NONE;
     } else {
         $this->errorCode = self::ERROR_PASSWORD_INVALID;
     }
     // CODE FOR ADLDAP
     // try {
     //     if (Yii::app()->ldap->authenticate($this->username, $this->password)) {
     //         $this->errorCode = self::ERROR_NONE;
     //     } else {
     //         $this->errorCode = self::ERROR_PASSWORD_INVALID;
     //     }
     // } catch (adLDAPException $e) {
     //     $this->errorCode = self::ERROR_LDAP_BINDING;
     // }
     // send login details
     $sender = new GraphiteSender('statsd');
     $sender->send_login($this->errorCode);
     $sender = new GraphiteSender('direct');
     $sender->send_login($this->errorCode);
     return !$this->errorCode;
 }
Esempio n. 2
0
 public function actionList()
 {
     if (!isset($_GET['YII_CSRF_TOKEN'])) {
         throw new CHttpException(400, 'Bad Request');
     } else {
         if ($_GET['YII_CSRF_TOKEN'] != Yii::app()->request->csrfToken) {
             throw new CHttpException(400, 'Bad Request');
         }
     }
     $begin_time = microtime(true);
     $limit = isset($_GET['limit']) ? (int) $_GET['limit'] : Yii::app()->params['projects_per_page'];
     $page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
     $offset = ($page - 1) * $limit;
     $filter = array();
     if (isset($_GET['project_id'])) {
         if (!empty($_GET['project_id']) || $_GET['project_id'] == '0') {
             $filter['project_id'] = (int) $_GET['project_id'];
         }
     }
     if (isset($_GET['name'])) {
         if (!empty($_GET['name']) || $_GET['name'] == '0') {
             $filter['name'] = (string) $_GET['name'];
         }
     }
     if (isset($_GET['code'])) {
         if (!empty($_GET['code']) || $_GET['code'] == '0') {
             $filter['code'] = (string) $_GET['code'];
         }
     }
     if (isset($_GET['status'])) {
         if (!empty($_GET['status'])) {
             $filter['status'] = (string) $_GET['status'];
         }
     }
     $projects = $this->get_data($filter, $limit, $offset);
     $return_data = array('page' => $projects['offset'] / $limit + 1, 'totalPage' => $projects['total_count'] == 0 ? 1 : ceil($projects['total_count'] / $limit), 'totalData' => $projects['total_count'], 'limit' => $limit, 'resultData' => $projects['data']);
     // GRAPHITE MODULE CODE HERE
     $time = floor((microtime(true) - $begin_time) * 1000);
     //send time to graphite
     $sender = new GraphiteSender('statsd');
     $sender->send_projectlist($time);
     $sender = new GraphiteSender('direct');
     $sender->send_projectlist($time);
     echo CJSON::encode($return_data);
 }