45 lines
1.6 KiB
PHP
45 lines
1.6 KiB
PHP
<?php
|
|
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
require __DIR__ . '/API_Controller.php';
|
|
|
|
class Login extends API_Controller {
|
|
public function __construct() {
|
|
parent::__construct();
|
|
}
|
|
|
|
public function login_api() {
|
|
header("Access-Control-Allow-Origin: *");
|
|
// API Configuration
|
|
$this->_apiConfig(['methods' => ['POST'], ]);
|
|
// you user authentication code will go here, you can compare the user with the database or whatever
|
|
$payload = ['id' => "Your User's ID", 'other' => "Some other data"];
|
|
// Load Authorization Library or Load in autoload config file
|
|
$this->load->library('authorization_token');
|
|
// generate a token
|
|
$token = $this->authorization_token->generateToken($payload);
|
|
// return data
|
|
$this->api_return(['status' => true, "result" => ['token' => $token, ], ], 200);
|
|
}
|
|
|
|
/**
|
|
* view method
|
|
*
|
|
* @link [api/user/view]
|
|
* @method POST
|
|
* @return Response|void
|
|
*/
|
|
public function view() {
|
|
header("Access-Control-Allow-Origin: *");
|
|
// API Configuration [Return Array: User Token Data]
|
|
$user_data = $this->_apiConfig(['methods' => ['POST'], 'requireAuthorization' => true, ]);
|
|
// return data
|
|
$this->api_return(['status' => true, "result" => ['user_data' => $user_data['token_data']], ], 200);
|
|
}
|
|
|
|
public function api_key() {
|
|
$this->_APIConfig(['methods' => ['POST'], 'key' => ['header', 'Set API Key'], ]);
|
|
}
|
|
}
|