chore: initial commit
This commit is contained in:
44
api/controllers/Login.php
Normal file
44
api/controllers/Login.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?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'], ]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user