diff --git a/application/config/autoload.php b/application/config/autoload.php index 8ad1ddce9..f861094e4 100755 --- a/application/config/autoload.php +++ b/application/config/autoload.php @@ -59,7 +59,7 @@ $autoload['packages'] = array(); | $autoload['libraries'] = array('user_agent' => 'ua'); */ //$autoload['libraries'] = array(); -$autoload['libraries'] = array('session'); +$autoload['libraries'] = array('session', 'FHC_Auth'); /* | ------------------------------------------------------------------- diff --git a/application/config/config.php b/application/config/config.php index cfc8f0c6f..e07aeebbb 100755 --- a/application/config/config.php +++ b/application/config/config.php @@ -508,7 +508,7 @@ $config['proxy_ips'] = ''; | Autoload Custom Controllers |-------------------------------------------------------------------------- | -*/ +Don't work so sometime delete this*/ function __autoload($class) { if (substr($class,0,3) !== 'CI_' && substr($class,0,4) !== 'FHC_') diff --git a/application/config/rest.php b/application/config/rest.php index ef7fa55bd..5f44dc692 100644 --- a/application/config/rest.php +++ b/application/config/rest.php @@ -110,7 +110,7 @@ $config['rest_realm'] = 'FHC REST API'; | authorization key | */ -$config['rest_auth'] = ' basic'; +$config['rest_auth'] = 'basic'; /* |-------------------------------------------------------------------------- diff --git a/application/controllers/Rest_server.php b/application/controllers/Rest_server.php index bc3e1ad5b..5c5a668ce 100644 --- a/application/controllers/Rest_server.php +++ b/application/controllers/Rest_server.php @@ -29,7 +29,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); * * A more detailed class description. */ -class Rest_server extends MY_Controller { +class Rest_server extends FHC_Controller { public function index() { diff --git a/application/controllers/api/v1/AuthAPI.php b/application/controllers/api/v1/AuthAPI.php index ee9288c7b..129e383dc 100644 --- a/application/controllers/api/v1/AuthAPI.php +++ b/application/controllers/api/v1/AuthAPI.php @@ -17,12 +17,13 @@ defined('BASEPATH') OR exit('No direct script access allowed'); // This can be removed if you use __autoload() in config.php OR use Modular Extensions -require APPPATH . '/libraries/REST_Controller.php'; +//require APPPATH . '/libraries/REST_Controller.php'; /** * Handles user authentication and registration process */ -class AuthAPI extends REST_Controller { +class AuthAPI extends APIv1_Controller +{ /** * Userauth-Controller constructor. @@ -39,8 +40,9 @@ class AuthAPI extends REST_Controller { $this->methods['login_get']['limit'] = 500; // 500 requests per hour per user/key // Load helper - $this->load->helper('fhcauth'); + //$this->load->helper('fhcauth'); $this->load->library('session'); + $this->load->library('FHC_Auth'); } /** @@ -58,7 +60,7 @@ class AuthAPI extends REST_Controller { $username = urldecode($this->get('username')); $password = urldecode($this->get('password')); - $account = auth($username,$password); + $account = $this->FHCAuth->auth($username,$password); // perform login checks if (!$account) diff --git a/application/controllers/api/v1/Person.php b/application/controllers/api/v1/Person.php index df561f923..73dbda67e 100644 --- a/application/controllers/api/v1/Person.php +++ b/application/controllers/api/v1/Person.php @@ -16,7 +16,7 @@ defined('BASEPATH') || exit('No direct script access allowed'); -class Person extends REST_Controller +class Person extends APIv1_Controller { //public $session; /** @@ -42,11 +42,11 @@ class Person extends REST_Controller $result = $this->person_model->getPerson(); // var_dump($result[0]); - if (empty($result)) + if ($result['err']) { $payload = [ 'success' => false, - 'message' => 'Person not found' + 'message' => $result['msg'].': '.$result['retval'] ]; $httpstatus = REST_Controller::HTTP_OK; } diff --git a/application/core/API_Controller.php b/application/core/API_Controller.php deleted file mode 100644 index 396124dbd..000000000 --- a/application/core/API_Controller.php +++ /dev/null @@ -1,17 +0,0 @@ -load->library('session'); -> autoload - //$this->load->library('database'); -> autoload - - } - -} diff --git a/application/core/FHC_Controller.php b/application/core/FHC_Controller.php index 5810f6168..656dd4c1e 100644 --- a/application/core/FHC_Controller.php +++ b/application/core/FHC_Controller.php @@ -12,7 +12,7 @@ class FHC_Controller extends CI_Controller require_once APPPATH . '/libraries/REST_Controller.php'; -class API_Controller extends REST_Controller +class APIv1_Controller extends REST_Controller { function __construct() { diff --git a/application/core/FHC_Model.php b/application/core/FHC_Model.php index 80cfb2a0b..14377d13d 100644 --- a/application/core/FHC_Model.php +++ b/application/core/FHC_Model.php @@ -3,6 +3,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); class FHC_Model extends CI_Model { + //protected errormsg; function __construct() { parent::__construct(); @@ -31,12 +32,13 @@ class FHC_Model extends CI_Model * * @return array */ - protected function _general_error() + protected function _general_error($retval = '', $message = FHC_ERR_GENERAL) { return array( 'err' => 1, 'code' => FHC_ERR_GENERAL, - 'msg' => lang('fhc_'.FHC_ERR_GENERAL) + 'msg' => lang('fhc_'.$message), + 'retval' => $retval ); } } diff --git a/application/libraries/FHC_Auth.php b/application/libraries/FHC_Auth.php index f7fb333bb..4e715efe3 100644 --- a/application/libraries/FHC_Auth.php +++ b/application/libraries/FHC_Auth.php @@ -11,7 +11,7 @@ * @filesource */ defined('BASEPATH') OR exit('No direct script access allowed'); -require_once 'include/authentication.class.php'; +require_once FCPATH.'include/authentication.class.php'; /** * FHC-Auth Helpers @@ -39,12 +39,12 @@ class FHC_Auth $auth = new authentication(); if ($auth->checkpassword($username, $password)) { - echo 'Auth-Method-True'; + //echo 'Auth-Method-True'; return true; } else { - echo 'Auth-Method-False'; + //echo 'Auth-Method-False'; return false; } } diff --git a/application/libraries/REST_Controller.php b/application/libraries/REST_Controller.php index d13e27ec2..c9253079c 100644 --- a/application/libraries/REST_Controller.php +++ b/application/libraries/REST_Controller.php @@ -434,7 +434,7 @@ abstract class REST_Controller extends CI_Controller { $language = $this->config->item('rest_language'); if ($language === NULL) { - $language = 'english'; + $language = 'en-US'; } // Load the language file diff --git a/application/models/person/Person_model.php b/application/models/person/Person_model.php index 2ef43b376..7b5054d06 100644 --- a/application/models/person/Person_model.php +++ b/application/models/person/Person_model.php @@ -19,6 +19,11 @@ class Person_model extends DB_Model return $query->row_object(); } + /** + * Laedt Personendaten einer Person mittels Code + * @param string $code DB-Attr: tbl_benutzer.zugangscode . + * @return object + */ public function getPersonByCode($code) { if ($this->fhc_db_acl->bb->isBerechtigt('person','s')) @@ -26,6 +31,11 @@ class Person_model extends DB_Model $query = $this->db->get_where('public.tbl_person', array('zugangscode' => $code)); return $query->result_object(); } + else + { + return $this->_general_error($this->fhc_db_acl->bb->errormsg); + //return false; + } } /** diff --git a/ci_hack.php b/ci_hack.php index c68fe662e..1b0f774a6 100755 --- a/ci_hack.php +++ b/ci_hack.php @@ -289,8 +289,29 @@ switch (ENVIRONMENT) * And away we go... */ //require_once BASEPATH.'core/CodeIgniter.php'; +//require_once(dirname(__FILE__).'/include/authentication.class.php'); +require_once(dirname(__FILE__).'/vendor/codeigniter/framework/system/core/Common.php'); +require_once(dirname(__FILE__).'/vendor/codeigniter/framework/system/core/Controller.php'); +/* + * ------------------------------------------------------ + * Instantiate the config class + * ------------------------------------------------------ + * + * Note: It is important that Config is loaded first as + * most other classes depend on it either directly or by + * depending on another class that uses it. + * + */ + $CFG =& load_class('Config', 'core'); -// FH-Complete Hacks for uebergangszeit + // Do we have any manually set config items in the index.php file? + if (isset($assign_to_config) && is_array($assign_to_config)) + { + foreach ($assign_to_config as $key => $value) + { + $CFG->set_item($key, $value); + } + } function &get_instance() { return CI_Controller::get_instance(); @@ -301,10 +322,10 @@ require_once(dirname(__FILE__).'/vendor/codeigniter/framework/system/database/DB require_once(dirname(__FILE__).'/vendor/codeigniter/framework/system/core/Common.php'); require_once(dirname(__FILE__).'/vendor/codeigniter/framework/system/core/Loader.php'); $loader=new CI_Loader(); -require_once(dirname(__FILE__).'/vendor/codeigniter/framework/system/core/Controller.php'); +//require_once(dirname(__FILE__).'/application/core/FHC_Controller.php'); $controller=new CI_Controller(); require_once(dirname(__FILE__).'/vendor/codeigniter/framework/system/core/Model.php'); -require_once(dirname(__FILE__).'/application/core/MY_Model.php'); +require_once(dirname(__FILE__).'/application/core/FHC_Model.php'); $model=new CI_Model(); // Traits diff --git a/tests/codeception/api/LoginCept.php b/tests/codeception/api/LoginCept.php index 432e6095b..c0a3d74d1 100644 --- a/tests/codeception/api/LoginCept.php +++ b/tests/codeception/api/LoginCept.php @@ -3,7 +3,7 @@ $I = new ApiTester($scenario); $I->wantTo('test the Login API'); $I->haveHttpHeader('FHC-API-KEY', 'testapikey@fhcomplete.org'); -$I->sendGET('/userauth/login/username/codeception%40whisperocity.com/password/secret/device_id/abcdef123'); +$I->sendGET('AuthAPI/login?username=pam&password=1q2w3&FHC-API-KEY=testapikey@fhcomplete.org'); $I->seeResponseCodeIs(200); $I->seeResponseIsJson(); $I->seeResponseContainsJson([