Skip to content

Commit

Permalink
Admin authentication works
Browse files Browse the repository at this point in the history
  • Loading branch information
eyedol committed Oct 12, 2010
1 parent e83660e commit 2a418c3
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 18 deletions.
29 changes: 27 additions & 2 deletions application/controllers/api.php
Expand Up @@ -153,8 +153,33 @@ public function _get_tasks( $task )

//admin categories actions
case "addcategories":
$this->ret = $this->api_objects->admin_categories->
_add_category($this->response_type);
if(!$this->api_objects->api_actions->_verify_array_index(
$this->request,'username'))
{
$this->error = array("errror" =>
$this->api_objects->
api_actions->_get_error_msg(001,
'username'));
break;

} else if(!$this->api_objects->api_actions->
_verify_array_index($this->request,'password'))
{
$this->error = array("errror" =>
$this->api_objects->
api_actions->_get_error_msg(001,
'password'));
break;

}
else
{
$this->ret = $this->api_objects->admin_categories->
_add_category($this->response_type,
$this->request['username'],
$this->request['password']);
break;
}

break;

Expand Down
55 changes: 39 additions & 16 deletions application/libraries/api/AdminCategory.php
Expand Up @@ -26,30 +26,44 @@ class AdminCategory
private $api_actions;
private $response_type;
private $domain;
private $api_prvt_func;
private $ret_value;

public function __construct()
{
$this->api_actions = new ApiActions;
$this->api_prvt_func = new ApiPrivateFunc;
$this->data = array();
$this->items = array();
$this->ret_json_or_xml = '';
$this->response_type = '';
$this->ret_value = 0;
$this->domain = $this->api_actions->_get_domain();
}

/**
* Add new category
*
* @param string response_type - XML or JSON
* @param string username - the username to authenticate
* @param string password - the password for the user to be
* authenticated
*
* @return Array
*/
public function _add_category($response_type)
public function _add_category($response_type,$username,$password)
{
// authenticate user

$ret_value = $this->_submit_categories();
return $this->_response($ret_value, $response_type);

if($user_id = $this->api_prvt_func->_login($username,$password))
{
$this->ret_value = $this->_submit_categories();
return $this->_response($this->ret_value, $response_type);
} else {
//Authentication failed. Invalid User or App Key
$this->ret_value = 2;
return $this->_response($this->ret_value,$response_type);
}
}

/**
Expand Down Expand Up @@ -78,7 +92,6 @@ public function _edit_category($response_type)
$form_error = FALSE;
$form_saved = FALSE;
$form_action = "";
$ret_value = 0;
$parents_array = array();
// check, has the form been submitted, if so, setup validation
if ($_POST)
Expand Down Expand Up @@ -172,16 +185,16 @@ public function _edit_category($response_type)
}
}

$ret_value = 1; // validation error
$this->ret_value = 1; // validation error
}

}
else
{
$ret_value = 2;
$this->ret_value = 3;
}

return $this->_response($ret_value,$response_type);
return $this->_response($this->ret_value,$response_type);
}

/**
Expand All @@ -202,7 +215,6 @@ public function _del_category($response_type)
// copy the form as errors, so the errors will be stored
//with keys corresponding to the form field names
$errors = $form;
$ret_value = 0;
// check, has the form been submitted, if so, setup validation
if ($_POST)
{
Expand Down Expand Up @@ -230,7 +242,7 @@ public function _del_category($response_type)
{
// populate the error fields, if any
$errors = arr::overwrite($errors,
$post->errors('category'));
$post->errors('category'));
foreach($errors as $error_item => $error_description)
{
if( !is_array($error_description))
Expand All @@ -244,16 +256,16 @@ public function _del_category($response_type)
}
}

$ret_value = 1; // validation error
$this->ret_value = 1; // validation error

}
}
else
{
$ret_value = 2;
$this->ret_value = 3;
}

return $this->_response($ret_value,$response_type);
return $this->_response($this->ret_value,$response_type);
}

/**
Expand All @@ -264,7 +276,7 @@ public function _del_category($response_type)
*/
public function _response($ret_value,$response_type)
{
if($ret_value == 0 )
if($ret_value == 0)
{
$reponse = array(
"payload" => array(
Expand All @@ -275,7 +287,7 @@ public function _response($ret_value,$response_type)
);

}
else if( $ret_value == 1 )
else if($ret_value == 1)
{
$reponse = array(
"payload" => array(
Expand All @@ -286,6 +298,17 @@ public function _response($ret_value,$response_type)
_get_error_msg(003,'',$this->error_messages)
);
}
else if ($ret_value == 2)
{
// Authentication Failed. Invalid User or App Key
$reponse = array(
"payload" => array("domain" => $this->domain,"success" =>
"false"),
"error" => $this->api_actions->_get_error_msg(005)
);

}

else
{
$reponse = array(
Expand Down Expand Up @@ -472,7 +495,7 @@ private function _submit_categories()
}
else
{
return 2; // Not sent by post method.
return 3; // Not sent by post method.
}

}
Expand Down

0 comments on commit 2a418c3

Please sign in to comment.