예제 #1
0
 /**
  * create user
  * @param {"email":"*****@*****.**","user_name":"hello","password":"******"}
  */
 public function add()
 {
     $req_data = $this->_request;
     if (empty($req_data['email']) || empty($req_data['password']) || empty($req_data['user_name'])) {
         $this->response($this->json(array('message' => 'Email/ username / password can not be left empty')), 206);
     }
     $email_check = $this->getUserDetails($req_data['email']);
     if (!empty($email_check)) {
         $this->response($this->json(array('message' => 'Email already exists')), 200);
     }
     $qry = 'INSERT INTO user (user_name,password,email) VALUES (?,?,?)';
     $_params = array();
     $_params[] = $req_data['user_name'];
     $_params[] = $this->createHash($req_data['password']);
     $_params[] = $req_data['email'];
     $_db = new Core\Dbconfig();
     $resp = $_db->execute($qry, $_params);
     if ($resp) {
         $this->response($this->json(array('message' => 'User added successfully')), 200);
     } else {
         $this->response($this->json(array('message' => 'Error adding user data')), 200);
     }
 }
예제 #2
0
 /**
  *	edit product details, only allowed to logged in user
  *	@param {"id":"1", "name": "test", "price": "12"}
  */
 public function edit()
 {
     $email = $this->_session->get('email');
     //get email id
     if (empty($email)) {
         $this->response($this->json(array('message' => 'Please login to add products')), 403);
     }
     $req_data = $this->_request;
     $param = array();
     if (empty($req_data['id'])) {
         $this->response($this->json(array('message' => 'Please provide unique id of th product to be edited')), 200);
     }
     $sub_qry = '';
     $_params = array();
     if (!empty($req_data['name'])) {
         $sub_qry .= ' name = ?,';
         $_params[] = $req_data['name'];
     }
     if (!empty($req_data['price'])) {
         $sub_qry .= 'price = ?';
         $_params[] = $req_data['price'];
     }
     if (empty($sub_qry)) {
         $this->response($this->json(array('message' => 'Please provide data(name/price) to update the product')), 200);
     }
     $sub_qry = rtrim($sub_qry, ",");
     $qry = 'UPDATE product SET' . $sub_qry . ' WHERE id = ?';
     $_params[] = $req_data['id'];
     $_db = new Core\Dbconfig();
     $res = $_db->execute($qry, $_params);
     if ($res == 1) {
         $this->response($this->json(array('message' => 'Data updated successfully')), 200);
     } else {
         $this->response($this->json(array('message' => 'can not update the record')), 200);
     }
 }