Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- require APPPATH . '/libraries/REST_Controller.php';
- class Rest_json extends REST_Controller {
- function __construct($config = 'rest') {
- parent::__construct($config);
- date_default_timezone_set('Asia/Jakarta');
- $this->load->model('m_rest_json', 'model');
- $this->load->model('m_auth');
- }
- function index_get($tabel) {
- $get_no = $this->get('no_key');
- $get_param = $this->get('param');
- $output = $this->model->get_data($tabel, $get_no, $get_param);
- if(!$output)
- $this->response(array('status' => 'fail', 502));
- else
- $this->response($output->result(), 200);
- }
- function index_post($tabel) {
- $this->load->library('bcrypt');
- $user = $this->post('user');
- $pass = $this->post('passwd');
- $no_key = $this->post('no_key');
- $outsensor = $this->post('output_sensor');
- $letak = $this->post('letak');
- $get_mdl = $this->m_auth->login($user);
- if($get_mdl)
- {
- foreach ($get_mdl->result() as $row) {
- if(!$this->bcrypt->check_password($pass, $row->password)) //text , hash
- {
- $this->response(array('status' => 'gagal validasi keamanan', 502));
- }
- else if($row->status == 'suspend'){
- $this->response(array('status' => 'akun nonaktif', 502));
- } else {
- $tgl_wkt = date('Y-m-d H:i:s');
- $data = array(
- 'no_key' => $no_key,
- 'date' => $tgl_wkt,
- 'output_sensor' => $outsensor
- );
- if($letak != '')
- {
- $data['letak'] = $letak;
- }
- $insert = $this->model->insert_data($tabel, $data);
- if (!$insert) {
- $this->response(array('status' => 'fail', 502));
- } else {
- $this->response($data, 200);
- }
- }
- }
- }else{
- $this->response(array('status' => 'akun tidak terdaftar', 502));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement