Commit b42023fe by Tobin

daily commit

parent 2e54f5ca
......@@ -41,7 +41,7 @@ class Webservices extends CI_Controller {
// $this->last_id = set_log($class, $method, $postdata, $auth);
}
// login
// customer_login
public function customer_login(){
header('Content-type: application/json');
$post = file_get_contents("php://input");
......@@ -79,5 +79,107 @@ class Webservices extends CI_Controller {
}
echo json_encode($respArr); exit;
}
// customer_forgot_password
public function customer_forgot_password(){
header('Content-type: application/json');
$post = file_get_contents("php://input");
$postData = json_decode($post, true);
$this->load->model('Customer_model');
$respArr = array('status'=>'0','message'=>'Required Fields are empty.');
if(empty($postData) || !isset($postData['email']) || empty($postData['email'])){
echo json_encode($respArr);exit;
}
$custResp = $this->Customer_model->genCustForgotPassLink($postData);
if(empty($custResp) || !isset($custResp['status']) || empty($custResp['status'])){
echo json_encode($respArr);exit;
}
if($custResp['status'] == '2'){
$respArr['status'] = '2';
$respArr['message'] = 'Invalid Email Address';
echo json_encode($respArr);exit;
}
if($custResp['status'] == '1'){
/*
MAIL SENT CONFIGARATION
*/
$respArr['status'] = '1';
$respArr['message'] = 'Password Reset Email has been sent';
}
echo json_encode($respArr); exit;
}
// customer_registration
public function customer_registration(){
header('Content-type: application/json');
$post = file_get_contents("php://input");
$postData = json_decode($post, true);
$this->load->model('Customer_model');
$respArr = array('status'=>'0','message'=>'Something went wrong.');
if(empty($postData)){
echo json_encode($respArr);exit;
}
$err = 0;
$msg = '';
if(!isset($postData['email']) || empty($postData['email'])){
$err = 1;
$msg = 'Provide a valid Email ID';
}
else if(!isset($postData['password']) || empty($postData['password'])){
$err = 1;
$msg = 'Provide a Password';
}
else if(!isset($postData['first_name']) || empty($postData['first_name'])){
$err = 1;
$msg = 'Provide valid Name';
}
else if(!isset($postData['last_name']) || empty($postData['last_name'])){
$err = 1;
$msg = 'Provide valid Name';
}
if($err == 1){
$respArr['message'] = $msg;
echo json_encode($respArr);exit;
}
if(isset($postData['phone']) && empty($postData['phone'])){
unset($postData['phone']);
}
unset($postData['promocode']);
$custResp = $this->Customer_model->customer_registration($postData);
if(empty($custResp) || !isset($custResp['status']) || empty($custResp['status'])){
echo json_encode($respArr);exit;
}
if($custResp['status'] == '2'){
$respArr['status'] = '2';
$respArr['message'] = 'Email Address already in use';
echo json_encode($respArr);exit;
}
if($custResp['status'] == '1'){
$custResp = $this->Customer_model->checkCustomerLogin($postData);
if(empty($custResp) || !isset($custResp['status']) || empty($custResp['status'])){
echo json_encode($respArr);exit;
}
if($custResp['status'] == '1'){
$respArr['data'] = $custResp['data'];
$respArr['status'] = '1';
$respArr['message'] = 'Success';
echo json_encode($respArr);exit;
}
}
echo json_encode($respArr); exit;
}
}
?>
......@@ -67,27 +67,32 @@
return $decode;
}
function getLocationLatLng($location = ''){
$settings = getSettings();
function getLocationLatLng($location = ''){
$settings = getSettings();
if(empty($location) || empty($settings) || !isset($settings['google_api_key']) ||
empty($gKey = $settings['google_api_key'])){
return 0;
}
$thisObj = & get_instance();
$locData = file_get_contents("https://maps.google.com/maps/api/geocode/json?address=".
urlencode($location)."&sensor=false&key=".$gKey);
if(empty($locData))
return 0;
$loc_data = json_decode($locData);
if(empty($loc_data) || !isset($loc_data->status) || $loc_data->status != 'OK')
return 0;
if(empty($location) || empty($settings) || !isset($settings['google_api_key']) ||
empty($gKey = $settings['google_api_key'])){
return 0;
}
$thisObj = & get_instance();
$locData = file_get_contents("https://maps.google.com/maps/api/geocode/json?address=".
urlencode($location)."&sensor=false&key=".$gKey);
if(empty($locData))
return 0;
$loc_data = json_decode($locData);
if(empty($loc_data) || !isset($loc_data->status) || $loc_data->status != 'OK')
return 0;
$locArr['lat'] = $loc_data->{'results'}[0]->{'geometry'}->{'location'}->{'lat'};
$locArr['lng'] = $loc_data->{'results'}[0]->{'geometry'}->{'location'}->{'lng'};
$locArr['lat'] = $loc_data->{'results'}[0]->{'geometry'}->{'location'}->{'lat'};
$locArr['lng'] = $loc_data->{'results'}[0]->{'geometry'}->{'location'}->{'lng'};
if(empty($locArr['lat']) || empty($locArr['lng']))
return 0;
return $locArr;
}
if(empty($locArr['lat']) || empty($locArr['lng']))
return 0;
return $locArr;
}
function generate_unique() {
$unique = md5(uniqid(time().mt_rand(), true));
return $unique;
}
?>
\ No newline at end of file
......@@ -108,5 +108,46 @@ class Customer_model extends CI_Model {
}
return $respArr;
}
function genCustForgotPassLink($userLogData = array()){
$respArr = array('status'=>0);
if(empty($userLogData)){
return $respArr;
}
$result = $this->db->get_where('customers',array('email'=>$userLogData['email'],'status'=>'1'));
if(empty($result) || $result->num_rows() < 1 || empty($custData = $result->row())){
$respArr['status'] = 2;
return $respArr;
}
$mail_id = $custData->email;
$cust_id = $custData->customer_id;
$unique_id = generate_unique();
$status = $this->db->insert('forgot_password_link',array('user_type'=>'1','user_id'=>$cust_id,
'token'=>$unique_id));
if($status){
$respArr['status'] = 1;
}
return $respArr;
}
function customer_registration($userData = array()){
$respArr = array('status'=>0);
if(empty($userData)){
return $respArr;
}
$result = $this->db->get_where('customers',array('email'=>$userData['email'],'status'=>'1'));
if(!empty($result) && $result->num_rows() >= 1){
$respArr['status'] = 2;
return $respArr;
}
$userData['password'] = md5($userData['password']);
$status = $this->db->insert('customers',$userData);
if($status){
$respArr['status'] = 1;
}
return $respArr;
}
}
?>
\ No newline at end of file
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