Example #1
0
 function parse($url)
 {
     $params = parent::parse($url);
     if (isset($params['slug'])) {
         $username = $params['slug'];
         App::import("Component", "Users.ControllerList");
         $contList = new ControllerListComponent(new ComponentCollection());
         $conts = $contList->getControllers();
         unset($conts[-2]);
         unset($conts[-1]);
         $conts = array_map('strtolower', $conts);
         $usernameTmp = strtolower(str_replace(' ', '', ucwords(str_replace('_', ' ', $username))));
         if (!in_array($usernameTmp, $conts)) {
             $plugins = App::objects('plugins');
             $plugins = array_map('strtolower', $plugins);
             if (in_array($usernameTmp, $plugins)) {
                 return false;
             }
             $customRoutes = Router::$routes;
             $usernameTmp = '/' . $username;
             foreach ($customRoutes as $customRoute) {
                 if (strpos(strtolower($customRoute->template), strtolower($usernameTmp)) !== false) {
                     return false;
                 }
             }
             App::import("Model", "Users.User");
             $userModel = new User();
             $isUser = $userModel->findByUsername($params['slug']);
             if ($isUser) {
                 $params['pass'][0] = $params['slug'];
                 return $params;
             }
         }
         return false;
     }
     return false;
 }
Example #2
0
 /**
  * Used to validate banned usernames
  *
  * @access public
  * @return boolean
  */
 public function isBanned()
 {
     $bannedUsers = explode(',', strtolower(BANNED_USERNAMES));
     $bannedUsers = array_map('trim', $bannedUsers);
     $checkMore = true;
     if (!empty($bannedUsers)) {
         if (isset($this->data['User']['id'])) {
             $oldUsername = $this->getUserNameById($this->data['User']['id']);
         }
         if (!isset($oldUsername) || $oldUsername != $this->data['User']['username']) {
             if (in_array(strtolower($this->data['User']['username']), $bannedUsers)) {
                 $this->validationErrors['username'][0] = "You cannot set this username";
                 $checkMore = false;
             }
         }
     }
     if ($checkMore) {
         App::import("Component", "Users.ControllerList");
         $contList = new ControllerListComponent(new ComponentCollection());
         $conts = $contList->getControllers();
         unset($conts[-2]);
         unset($conts[-1]);
         $conts = array_map('strtolower', $conts);
         $usernameTmp = strtolower(str_replace(' ', '', ucwords(str_replace('_', ' ', $this->data['User']['username']))));
         if (in_array($usernameTmp, $conts)) {
             $this->validationErrors['username'][0] = "You cannot set this username";
             $checkMore = false;
         }
         if ($checkMore) {
             $plugins = App::objects('plugins');
             $plugins = array_map('strtolower', $plugins);
             if (in_array($usernameTmp, $plugins)) {
                 $this->validationErrors['username'][0] = "You cannot set this username";
                 $checkMore = false;
             }
             if ($checkMore) {
                 $customRoutes = Router::$routes;
                 $usernameTmp = '/' . $this->data['User']['username'];
                 foreach ($customRoutes as $customRoute) {
                     if (strpos(strtolower($customRoute->template), strtolower($usernameTmp)) !== false) {
                         $this->validationErrors['username'][0] = "You cannot set this username";
                         break;
                     }
                 }
             }
         }
     }
     return true;
 }