Commit f239a987 by Adarsh K

Merge branch 'adarsh' into 'master'

Adarsh See merge request !5
parents 04d6b223 160ac7dc
...@@ -54,7 +54,11 @@ class Handlerequest extends CI_Controller { ...@@ -54,7 +54,11 @@ class Handlerequest extends CI_Controller {
if($this->validate_headers() == true){ if($this->validate_headers() == true){
if(isset($_POST)) { if(isset($_POST)) {
$data = $_POST; $data = $_POST;
if(isset($_FILES)){ $res = $this->validation_model->check('wishPost', $data);
if($res['state'] == 1) {
$this->errorResponse($res['response']['code'], $res['response']['message']);
} else {
if(isset($_FILES['media'])){
$images = $this->handle_model->image_upload($_FILES); $images = $this->handle_model->image_upload($_FILES);
$data = $_POST; $data = $_POST;
$data = $this->handle_model->wish_post($data, $images); $data = $this->handle_model->wish_post($data, $images);
...@@ -67,6 +71,7 @@ class Handlerequest extends CI_Controller { ...@@ -67,6 +71,7 @@ class Handlerequest extends CI_Controller {
} else { } else {
$this->errorResponse('023','Wish media is missing'); $this->errorResponse('023','Wish media is missing');
} }
}
} else { } else {
$this->errorResponse('002','Invalid request'); $this->errorResponse('002','Invalid request');
} }
...@@ -76,7 +81,7 @@ class Handlerequest extends CI_Controller { ...@@ -76,7 +81,7 @@ class Handlerequest extends CI_Controller {
} }
public function validate_headers() { public function validate_headers() {
if($this->headers['x-api-key'] == $this->secret_key) { if(isset($this->headers['x-api-key']) && $this->headers['x-api-key'] == $this->secret_key) {
return true; return true;
} else { } else {
return false; return false;
......
...@@ -13,6 +13,8 @@ class Handle_model extends CI_Model { ...@@ -13,6 +13,8 @@ class Handle_model extends CI_Model {
$response = $query->row(); $response = $query->row();
if($response->user_type == 1) { if($response->user_type == 1) {
$data = $this->db->where('id',$response->user_id)->get('customer')->row(); $data = $this->db->where('id',$response->user_id)->get('customer')->row();
$data->sessionId = $this->generate_session($data->id, $data->user_type);
unset($data->id);
$res = array('status'=>1,'message'=>"Login successfully done",'data'=>$data); $res = array('status'=>1,'message'=>"Login successfully done",'data'=>$data);
} else if($response->user_type == 2) { } else if($response->user_type == 2) {
$data = $this->db->where('id',$response->user_id)->get('shopper')->row(); $data = $this->db->where('id',$response->user_id)->get('shopper')->row();
...@@ -26,6 +28,13 @@ class Handle_model extends CI_Model { ...@@ -26,6 +28,13 @@ class Handle_model extends CI_Model {
return $res; return $res;
} }
function generate_session($user_id, $type) {
$str=rand();
$session_id = md5($str);
$this->db->insert('user_auth', array('user_id'=>$user_id, 'type'=>$type, 'session_id'=>$session_id));
return $session_id;
}
function registration($data) { function registration($data) {
$dup = $this->db->query("SELECT customer.email_id, customer.phone_no FROM `users` LEFT JOIN customer ON users.user_type = customer.user_type WHERE (users.username = '".$data['email_id']."' OR customer.phone_no = '".$data['phone_no']."') GROUP BY customer.id"); $dup = $this->db->query("SELECT customer.email_id, customer.phone_no FROM `users` LEFT JOIN customer ON users.user_type = customer.user_type WHERE (users.username = '".$data['email_id']."' OR customer.phone_no = '".$data['phone_no']."') GROUP BY customer.id");
if($dup->num_rows() > 0) { if($dup->num_rows() > 0) {
...@@ -59,6 +68,8 @@ class Handle_model extends CI_Model { ...@@ -59,6 +68,8 @@ class Handle_model extends CI_Model {
$insert_id = $this->db->insert_id(); $insert_id = $this->db->insert_id();
$this->db->where('user_id',$insert_id)->where('user_type',1)->update('users',array('password'=>md5($data['pin']), 'status'=>1)); $this->db->where('user_id',$insert_id)->where('user_type',1)->update('users',array('password'=>md5($data['pin']), 'status'=>1));
$user = $this->db->where('id', $insert_id)->get('customer')->row(); $user = $this->db->where('id', $insert_id)->get('customer')->row();
$data->sessionId = $this->generate_session($data->id, $data->user_type);
unset($data->id);
$res = array('status'=>1, 'message'=>'Registration Successfully', 'data'=>$user); $res = array('status'=>1, 'message'=>'Registration Successfully', 'data'=>$user);
} else { } else {
$res = array('status'=>0,'message'=>'Something Went Wrong! Registration Failed','code'=>'012'); $res = array('status'=>0,'message'=>'Something Went Wrong! Registration Failed','code'=>'012');
...@@ -153,8 +164,12 @@ class Handle_model extends CI_Model { ...@@ -153,8 +164,12 @@ class Handle_model extends CI_Model {
} }
function wish_post($data, $images) { function wish_post($data, $images) {
$sessionId = $this->session_retrive($data['sessionId']);
if($sessionId == 0){
$res = array('status'=>0,'message'=>'Invalid session Id','code'=>'032');
} else {
$wish = array( $wish = array(
'cust_id'=>$data['cust_id'], 'cust_id'=>$sessionId,
'cat_id'=>$data['cat_id'], 'cat_id'=>$data['cat_id'],
'sub_cat_id'=>$data['sub_cat_id'], 'sub_cat_id'=>$data['sub_cat_id'],
'description'=>$data['description'], 'description'=>$data['description'],
...@@ -177,9 +192,21 @@ class Handle_model extends CI_Model { ...@@ -177,9 +192,21 @@ class Handle_model extends CI_Model {
} else { } else {
$res = array('status'=>0,'message'=>'Something Went Wrong! Wish post Failed','code'=>'012'); $res = array('status'=>0,'message'=>'Something Went Wrong! Wish post Failed','code'=>'012');
} }
}
return $res; return $res;
} }
function session_retrive($sessionId) {
$response = $this->db->where('session_id',$sessionId)->get('user_auth');
if($response->num_rows() > 0) {
$row = $response->row();
return $row->user_id;
} else {
return 0;
}
}
function wish_list($data) { function wish_list($data) {
$state = 0; $state = 0;
if(isset($data['id'])) { if(isset($data['id'])) {
...@@ -195,8 +222,8 @@ class Handle_model extends CI_Model { ...@@ -195,8 +222,8 @@ class Handle_model extends CI_Model {
$state = 1; $state = 1;
} }
if(isset($data['cat_id'])) { if(isset($data['sub_cat_id'])) {
$this->db->where('wish.cat_id',$data['cat_id']); $this->db->where('wish.sub_cat_id',$data['sub_cat_id']);
$state = 1; $state = 1;
} }
......
...@@ -39,6 +39,20 @@ class Validation_model extends CI_Model { ...@@ -39,6 +39,20 @@ class Validation_model extends CI_Model {
'sub_categories'=>array(), 'sub_categories'=>array(),
'get_country'=>array(), 'get_country'=>array(),
'wish_list'=>array(), 'wish_list'=>array(),
'wishPost'=>array(
'sessionId'=>array('required'=>array('code'=>'027', 'message'=>'session id is null or empty')
),
'cat_id'=>array('required'=>array('code'=>'028', 'message'=>'Category id is missing')
),
'sub_cat_id'=>array('required'=>array('code'=>'029', 'message'=>'Sub category id is missing')
),
'prod_name'=>array('event_id'=>array('required'=>array('code'=>'030', 'message'=>'Product name is missing')
)
),
'description'=>array('event_id'=>array('required'=>array('code'=>'031', 'message'=>'Product description is missing')
)
)
),
'forgot'=> array('email_id'=>array('required'=>array('code'=>'ER02', 'message'=>'Email id is null or empty'), 'forgot'=> array('email_id'=>array('required'=>array('code'=>'ER02', 'message'=>'Email id is null or empty'),
'email'=>array('code'=>'ER03', 'message'=>'Invalid Email id') 'email'=>array('code'=>'ER03', 'message'=>'Invalid Email id')
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment