Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function Login($username, $password)
 {
     // IF THERE IS NO USERNAME THEN DON'T BOTHER CHECKING THE DATABASE
     if (!$username) {
         return false;
     }
     $result = false;
     //limpa o cache ao logar
     $this->ClearCache();
     $criteria = new UsuarioCriteria();
     $filtro = new CriteriaFilter('Login,Email', $username);
     $criteria->AddFilter($filtro);
     try {
         $user = $this->_phreezer->GetByCriteria("Usuario", $criteria);
         // WE NEED TO STRIP OFF THE "!!!" PREFIX THAT WAS ADDED IN "OnSave" BELOW:
         $hash = substr($user->Senha, 3);
         if (password_verify($password, $hash)) {
             // THE USERNAME/PASSWORD COMBO IS CORRECT!
             // WHAT THIS IS DOING IS BASICALLY CLONING THE USER RESULT
             // FROM THE DATABASE INTO THE CURRENT RECORD.
             $this->LoadFromObject($user);
             $result = true;
         } else {
             // THE USERNAME WAS FOUND BUT THE PASSWORD DIDN'T MATCH
             $result = false;
         }
     } catch (NotFoundException $nfex) {
         // NO ACCOUNT WAS FOUND WITH THE GIVEN USERNAME
         $result = false;
     }
     return $result;
 }
Esempio n. 2
0
 /**
  * API Method queries for Usuario records and render as JSON
  */
 public function Query()
 {
     try {
         $criteria = new UsuarioCriteria();
         $criteria->IdUsuario_GreaterThan = 1;
         // para não lista o usuario Master
         // TODO: this will limit results based on all properties included in the filter list
         $filter = RequestUtil::Get('filter');
         if ($filter) {
             $criteria->AddFilter(new CriteriaFilter('Nome,Email,Login,TipoUsuario', '%' . $filter . '%'));
         }
         // TODO: this is generic query filtering based only on criteria properties
         foreach (array_keys($_REQUEST) as $prop) {
             $prop_normal = ucfirst($prop);
             $prop_equals = $prop_normal . '_Equals';
             if (property_exists($criteria, $prop_normal)) {
                 $criteria->{$prop_normal} = RequestUtil::Get($prop);
             } elseif (property_exists($criteria, $prop_equals)) {
                 // this is a convenience so that the _Equals suffix is not needed
                 $criteria->{$prop_equals} = RequestUtil::Get($prop);
             }
         }
         $output = new stdClass();
         // if a sort order was specified then specify in the criteria
         $output->orderBy = RequestUtil::Get('orderBy');
         $output->orderDesc = RequestUtil::Get('orderDesc') != '';
         if ($output->orderBy) {
             $criteria->SetOrder($output->orderBy, $output->orderDesc);
         }
         $page = RequestUtil::Get('page');
         if ($page != '') {
             // if page is specified, use this instead (at the expense of one extra count query)
             $pagesize = $this->GetDefaultPageSize();
             $usuarios = $this->Phreezer->Query('Usuario', $criteria)->GetDataPage($page, $pagesize);
             $output->rows = $usuarios->ToObjectArray(true, $this->SimpleObjectParams());
             $output->totalResults = $usuarios->TotalResults;
             $output->totalPages = $usuarios->TotalPages;
             $output->pageSize = $usuarios->PageSize;
             $output->currentPage = $usuarios->CurrentPage;
         } else {
             // return all results
             $usuarios = $this->Phreezer->Query('Usuario', $criteria);
             $output->rows = $usuarios->ToObjectArray(true, $this->SimpleObjectParams());
             $output->totalResults = count($output->rows);
             $output->totalPages = 1;
             $output->pageSize = $output->totalResults;
             $output->currentPage = 1;
         }
         $this->RenderJSON($output, $this->JSONPCallback());
     } catch (Exception $ex) {
         $this->RenderExceptionJSON($ex);
     }
 }