74 lines
2.7 KiB
PHP
74 lines
2.7 KiB
PHP
<?php
|
|
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
|
|
/** @noinspection PhpIncludeInspection */
|
|
require_once APPPATH . '/libraries/REST_Controller.php';
|
|
|
|
/**
|
|
* This is an example of a few basic user interaction methods you could use
|
|
* all done with a hardcoded array
|
|
*
|
|
* @package CodeIgniter
|
|
* @subpackage Rest Server
|
|
* @category Controller
|
|
* @author
|
|
* @license MIT
|
|
* @link
|
|
*/
|
|
class Login_Controller extends REST_Controller {
|
|
function __construct()
|
|
{
|
|
// Construct the parent class
|
|
parent::__construct();
|
|
|
|
// Configure limits on our controller methods
|
|
// Ensure you have created the 'limits' table and enabled 'limits' within application/config/rest.php
|
|
$this->methods['login_post']['limit'] = 100; // 100 requests per hour per user/key
|
|
$this->load->model('Login_model', 'login_model');
|
|
}
|
|
|
|
//This method used to get Login
|
|
|
|
public function login_post()
|
|
{
|
|
//echo "function in";
|
|
$userMobile = $this->post('userMobile');
|
|
//echo json_encode($userMobile);die;
|
|
//echo $userMobile;die;
|
|
$password = $this->post('password');
|
|
|
|
$loginDetails = $this->login_model->login( $userMobile, $password);// Check if the users data store contains users (in case the database result returns NULL)
|
|
//print_r($loginDetails);die;
|
|
if ($loginDetails['loginStatus'])
|
|
{
|
|
// generate token
|
|
$tokenData = array();
|
|
// $tokenData['ID'] = $loginDetails['details']->ID;
|
|
// $tokenData['UserType'] = $loginDetails['details']->ListCode;
|
|
$tokenData['MobileNumber'] = $loginDetails['details']->MobileNumber;
|
|
//$tokenData['BranchCode'] = $loginDetails['details']->BranchCode;
|
|
//$tokenData['Admin'] = $loginDetails['details']->BranchCode;
|
|
$tokenData['iat'] = strtotime("now");
|
|
$tokenData['exp'] = strtotime("+30 days");
|
|
//$tokenData['timestamp'] = strtotime("+2 hours");
|
|
$output['token'] = AUTHORIZATION::generateToken($tokenData);
|
|
// $generate=AUTHORIZATION::validateTimestamp($output['token']);
|
|
// end generate token
|
|
$output['loginStatus'] = true;
|
|
// Set the response and exit
|
|
$this->response($output);
|
|
}
|
|
else
|
|
{
|
|
// Set the response and exit
|
|
$this->response([
|
|
'message' => 'No users were found',
|
|
'loginStatus' => false
|
|
]);
|
|
}
|
|
}
|
|
|
|
}
|
|
|