From b26c39965d362f7013c19ed8c0c0f956a82723d1 Mon Sep 17 00:00:00 2001 From: sanjeev Date: Wed, 19 Jan 2022 18:42:05 +0530 Subject: [PATCH] generate USER OTP : ps --- api/application/config/routes.php | 3 + .../User_Management_Controller.php | 61 ++++++++++++++++++- .../helpers/sms_gupshup_helper.php | 3 +- .../models/User_Management_Model.php | 25 ++++++++ 4 files changed, 89 insertions(+), 3 deletions(-) diff --git a/api/application/config/routes.php b/api/application/config/routes.php index 6c6d47e6..68896b8a 100755 --- a/api/application/config/routes.php +++ b/api/application/config/routes.php @@ -349,3 +349,6 @@ $route['PDjson'] = 'PD_Controller/PDjson'; $route['regenerateSatelliteImg'] = 'Sales_PD_Controller/regenerateSatelliteImg'; $route['regenerateSaleReport'] = 'Sales_PD_Controller/regenerateSaleReport'; $route['resendSaleReportMail'] = 'Sales_PD_Controller/resendSaleReportMail'; + +$route['generateOTP'] = 'User_Management_Controller/generateOTP'; +$route['verifyOTP'] = 'User_Management_Controller/verifyOTP'; \ No newline at end of file diff --git a/api/application/controllers/User_Management_Controller.php b/api/application/controllers/User_Management_Controller.php index b34b10eb..b411bbb0 100644 --- a/api/application/controllers/User_Management_Controller.php +++ b/api/application/controllers/User_Management_Controller.php @@ -520,7 +520,7 @@ class User_Management_Controller extends REST_Controller { /** END OF INSERTING THE RCM STATE MAPPING DATA */ $response_msg = salesproduct_msg ? $salesproduct_msg : ''; - $response_msg.= $response_msg && $rcmstate_msg ? ' and '.$rcmstate_msg : $rcmstate_msg ? ' '.$rcmstate_msg : ''; + $response_msg.= ($response_msg && $rcmstate_msg ) ? ' and '.$rcmstate_msg : ($rcmstate_msg ? ' '.$rcmstate_msg : ''); $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['msg'] = $response_msg." Successully"; @@ -539,4 +539,63 @@ else { $this->response($data,REST_Controller::HTTP_NOT_FOUND); } } + + + public function generateOTP_post(){ + $records = $this->post('records'); + $result = $this->User_Management_Model->generateOTP($records); + if(count($result)>1) + { + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NO_CONTENT; + $data['msg'] = 'Double Entry Founded for given EMail'; + $data['records'] = $result; + + }else if(count($result) == 1) + { + $mobile = (string)$result[0]['mobile_no']; + $userid = $result[0]['userid']; + $string2 = str_shuffle('1234567890'); + $OTP = substr($string2,0,6); + $msg = "Your OTP for forgot password is ".$OTP."."; + SMS_GUPSHUP::sendSMS($msg,$mobile); + $this->User_Management_Model->updateRecords(array('OTP'=>$OTP),USERPROFILE,array('userid'=>$userid)); + + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['msg'] = "Success"; + + } + else + { + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NO_CONTENT; + $data['msg'] = 'No Data Available for given Email. Try Again!'; + } + $this->response($data,REST_Controller::HTTP_OK); + } + + public function verifyOTP_post(){ + // mailid + // otp + $records = $this->post('records'); + $result = $this->User_Management_Model->verifyOTP($records); + if(count($result)>0) + { + $userid = $result[0]['userid']; + // call reset password function on here. + $this->User_Management_Model->updateRecords(array('OTP'=>null),USERPROFILE,array('userid'=>$userid)); + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['msg'] = "Success"; + } + else + { + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_NO_CONTENT; + $data['msg'] = 'No Data Available for given Email and Its OTP. Try Again!'; + } + $this->response($data,REST_Controller::HTTP_OK); + } + } \ No newline at end of file diff --git a/api/application/helpers/sms_gupshup_helper.php b/api/application/helpers/sms_gupshup_helper.php index edb131db..0675eb39 100644 --- a/api/application/helpers/sms_gupshup_helper.php +++ b/api/application/helpers/sms_gupshup_helper.php @@ -17,8 +17,7 @@ class SMS_GUPSHUP $client = new \GuzzleHttp\Client(); $response = $client->post($sms_api_url); $contents = (string) $response->getBody(); - - $logger = MYLOG::logFunction(null,$additional_data['pd_id']); + $logger = isset($additional_data['pd_id']) ? MYLOG::logFunction(null,$additional_data['pd_id']) : MYLOG::logFunction(); $logger->info("Msg Send Status",array('response_data' => $contents,'mobile_no' => $no,'msg' => $msg,'sms_api_url' => $sms_api_url,'additional_data' => $additional_data)); if($return) diff --git a/api/application/models/User_Management_Model.php b/api/application/models/User_Management_Model.php index 41ebcc57..10dc70f3 100644 --- a/api/application/models/User_Management_Model.php +++ b/api/application/models/User_Management_Model.php @@ -175,4 +175,29 @@ class User_Management_Model extends SPARQ_Model { $this->db->update(RCM_STATE_MAPPING); } } + + public function generateOTP($arg) + { + $this->db->select('USERPROFILE.userid, USERPROFILE.first_name as user_first_name, USERPROFILE.last_name as user_last_name, USERPROFILE.email, USERPROFILE.mobile_no,concat(USERPROFILE.first_name," ",USERPROFILE.last_name)as full_name'); + $this->db->from(USERPROFILE.' as USERPROFILE'); + $this->db->where('USERPROFILE.email',$arg['email']); + $this->db->where('USERPROFILE.isactive',1); + // return $this->db->get()->row()->column_list; + $query = $this->db->get(); + return $query->result_array(); + } + + public function verifyOTP($arg) + { + // $this->db->select('USERPROFILE.userid, USERPROFILE.first_name as user_first_name, USERPROFILE.last_name as user_last_name, USERPROFILE.email, USERPROFILE.mobile_no,concat(USERPROFILE.first_name," ",USERPROFILE.last_name)as full_name, USERPROFILE.isactive, USERPROFILE.fk_city, USERPROFILE.fk_state,USERPROFILE.fk_entity_type_id,USERPROFILE.designation'); + $this->db->select('USERPROFILE.userid, USERPROFILE.first_name as user_first_name, USERPROFILE.last_name as user_last_name, USERPROFILE.email, USERPROFILE.mobile_no,concat(USERPROFILE.first_name," ",USERPROFILE.last_name)as full_name'); + $this->db->from(USERPROFILE.' as USERPROFILE'); + $this->db->where('USERPROFILE.email',$arg['email']); + $this->db->where('USERPROFILE.OTP',$arg['OTP']); + $this->db->where('USERPROFILE.isactive',1); + // return $this->db->get()->row()->column_list; + $query = $this->db->get(); + return $query->result_array(); + } + } \ No newline at end of file