class Controller_Proxy extends Controller_Rest{
protected $format='json';
protected $user_controller;
protected $user_method;
protected $user_route;
public function action_proxy(){
// get the user called method
$this->get_call_method();
if(Session::get('auth') !== NULL){
if(Session::get('auth')==true){
// fire off the users requested method
$result=Request::forge($this->user_route, false)->execute()->response();
}else{
$result=Request::forge('auth/auth', false)->execute()->response();
}
}else{
$result=Request::forge('auth/auth', false)->execute()->response();
}
$this->response($result->body());
}
}
namespace Auth;
class Controller_Auth extends \Controller_Rest{
protected $format='json';
public function action_index(){
return $this->auth();
}
// function to authenticate the user and validate login
public function auth(){
switch(\Input::method()){
case 'POST':
$user=\Input::json('username');
$pass=\Input::json('password');
break;
case 'GET':
$user=\Input::get('username');
$pass=\Input::get('password');
break;
default:
break;
}
return Model_Auth::validateUser($user, $pass);
}
}
namespace Auth;
class Model_Auth extends \Model{
public static function validateUser($username, $password){
$query= \DB::query("SELECT id FROM Users WHERE Username='{$username}' AND Password=sha1('{$password}')")->execute();
$user=$query->as_array();
if(sizeof($user)>0){
if(sizeof($user)>1){
return 'There Seems To Be Multiple Users With Selected Username.';
}else{
return $user;
}
}else{
return 'No User With Selected Username.';
}
}
}
/**
* @var array An array of HTTP headers
*/
public $headers = array(
'Access-Control-Allow-Origin' => '*',
'Access-Control-Allow-Headers' => 'content-type',
'Access-Control-Allow-Methods' => 'POST, GET, OPTIONS',
'Access-Control-Max-Age' => '28800'
);
"{\"userid\":\"1\"}"
return array('user_id' => 1);
{"user_id":1}without encoded quotes.
It looks like you're new here. If you want to get involved, click one of these buttons!