diff --git a/application/config/routes.php b/application/config/routes.php index 9b186471..5689133f 100644 --- a/application/config/routes.php +++ b/application/config/routes.php @@ -150,11 +150,11 @@ $route['pageNotFound'] = "user/pageNotFound"; $route['checkEmailExists'] = "user/checkEmailExists"; $route['forgotPassword'] = "login/forgotPassword"; -$route['resetPasswordUser'] = "login/resetPasswordUser"; -$route['resetPasswordConfirmUser'] = "login/resetPasswordConfirmUser"; -$route['resetPasswordConfirmUser/(:any)'] = "login/resetPasswordConfirmUser/$1"; -$route['resetPasswordConfirmUser/(:any)/(:any)'] = "login/resetPasswordConfirmUser/$1/$2"; -$route['createPasswordUser'] = "login/createPasswordUser"; +$route['resetPasswordUser'] = "login/resetPasswordUser";//reset password without OTP +$route['resetPasswordConfirmUser'] = "login/resetPasswordConfirmUser";//reset password with OTP +// $route['resetPasswordConfirmUser/(:any)'] = "login/resetPasswordConfirmUser/$1"; +// $route['resetPasswordConfirmUser/(:any)/(:any)'] = "login/resetPasswordConfirmUser/$1/$2"; +// $route['createPasswordUser'] = "login/createPasswordUser"; /** --------------------------Payslip Routes---------------------- */ $route['monthlypay'] = "payslip/monthlyInputs"; diff --git a/application/controllers/login.php b/application/controllers/login.php index cc33d939..f60afb12 100644 --- a/application/controllers/login.php +++ b/application/controllers/login.php @@ -122,13 +122,126 @@ class Login extends CI_Controller $this->load->view('forgotPassword'); } + /** + * To reset password of the user (without one time code) + */ + function resetPasswordUser(){ + + $mobileno = $this->input->post('phno'); + $emailid = $this->input->post('email'); + $result = $this->login_model->getuserid($mobileno,$emailid); + + if(!empty($result)){ + + $string = "abcde".rand(10000,99999)."vwxyz"; + $string_shuffled = str_shuffle($string); + $passcode = substr($string_shuffled, 1, 6); + $password = "RESICO@".$passcode; + + $mobile = "91".$result[0]->ContactNumber; + //$msg = "Your Password is 'resico1234' sent from Resico Industries "; + $msg = "Hi " .$result[0]->FirstName. ", + \n Your password has been resetted sucessfully. + \n Please login with your new password '".$password."'"; - function resetPasswordUser() - { - $ContactNo = $this->input->post('phno'); - echo $ContactNo; + $message = urlencode($msg); + + $ch=curl_init(); + curl_setopt($ch,CURLOPT_URL,"https://smsapi.24x7sms.com/api_2.0/SendSMS.aspx?APIKEY=xegCdYUIMf3&MobileNo=".$mobile."&SenderID=VNBAIT&Message=".$message."&ServiceName=PROMOTIONAL_HIGH"); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + $output =curl_exec($ch); + curl_close($ch); + + $resetpassword = getHashedPassword($password); + + $updatepassword = $this->login_model->updatepassword($result[0]->userId,$resetpassword); + + echo ""; + redirect('/loginMe','refresh'); + } + else{ + echo ""; + redirect('/loginMe','refresh'); + } } + + /** + * To Get One time code to reset password of the user (ajax call) + */ + /** function getOTP() + * { + * $id = $this->input->post('id'); + * $result = $this->login_model->temp($id); + * if(!empty($result)){ + * $string = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; + * $string_shuffled = str_shuffle($string); + * $password = substr($string_shuffled, 1, 7); + * $otp = rand(1000, 9999); + * echo "resico@".rand(1000,9999);die; + * + * //print_r($result);die; + * //$result[0]->ContactNumber; + * + * $mobile = "91".$result[0]->ContactNumber; + * //$msg = "Your Password is 'resico1234' sent from Resico Industries "; + * $msg = "Hi " .$result[0]->FirstName. ", + * \n We have generated One Time Code For You. This code used for reset your password + * \n YOUR CODE IS'".$password."'and'".$otp."'"; + * + * $message = urlencode($msg); + * // echo $mobile , $message; + * $ch=curl_init(); + * curl_setopt($ch,CURLOPT_URL,"https://smsapi.24x7sms.com/api_2.0/SendSMS.aspx?APIKEY=xegCdYUIMf3&MobileNo=".$mobile."&SenderID=VNBAIT&Message=".$message."&ServiceName=PROMOTIONAL_HIGH"); + * curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + * $output =curl_exec($ch); + * + * //return $output; + * //print_r($output);exit(); + * curl_close($ch); + * //echo json_encode($result); + * $updateotp = $this->login_model->temp2($result[0]->userId,$otp); + * $data = $updateotp[0]->OTP; + * echo $data; + * }} + */ + + /** + * After Getting One time code + * Reset password of the user (with OTP) + */ + /** function resetPasswordConfirmUser(){ + * + * // $this->load->library('form_validation'); + * + * // $this->form_validation->set_rules('newPassword','New password','required|max_length[20]'); + * // $this->form_validation->set_rules('confirmPassword','Confirm new password','required|matches[newPassword]|max_length[20]'); + * + * $newPassword = $this->input->post('newPassword'); + * $ConfirmPassword = $this->input->post('confirmPassword'); + * + * $mobileno = $this->input->post('phno'); + * + * $da ta = $this->login_model->getuserdtl($mobileno); + * $userid = $data[0]->userId; + * $OTP = NULL; + * + * $Array = array('password'=>getHashedPassword($newPassword),'OTP'=>$OTP); + * + * $result = $this->login_model->resetpassword($Array,$userid); + * + * if($result > 0) + * { + * echo ""; redirect('login','refresh'); + * } + * else + * { + * echo ""; redirect('login','refresh'); + * } + * + * } + */ + } diff --git a/application/models/login_model.php b/application/models/login_model.php index 71b02fa9..7b560e8b 100644 --- a/application/models/login_model.php +++ b/application/models/login_model.php @@ -123,6 +123,77 @@ class Login_model extends CI_Model // print_r( $this->db->last_query()); return $query->result(); } + +/** + * get the user dtl + */ +function getuserid($mobileno,$emailid) +{ + $this->db->select('UsrTbl.userId,UsrTbl.email,EmpTbl.ContactNumber,EmpTbl.FirstName'); + $this->db->from('tbl_users as UsrTbl'); + $this->db->join('T_Employee_Details as EmpTbl','UsrTbl.EmpID = EmpTbl.EmpID'); + $this->db->where('EmpTbl.ContactNumber', $mobileno); + $this->db->where('UsrTbl.email',$emailid); + $this->db->where('UsrTbl.isDeleted', 0); + $res = $this->db->get(); + return $res->result(); + } -?> +/** + * To update opt in our database + **/ +function temp2($userId,$otp){ + $this->db->set('OTP',$otp); + $this->db->where('userId',$userId); + $this->db->update('tbl_users'); + $count = $this->db->affected_rows(); + + if($count > 0) + { + $subQuery = "select OTP from tbl_users where userId = '".$userId."'"; + $query = $this->db->query($subQuery); + return $query->result(); + } +} + +/** + * To get user id + **/ +function getuserdtl($phno){ + $this->db->select('BaseTbl.userId'); + $this->db->from('tbl_users as BaseTbl'); + $this->db->join('T_Employee_Details as Emp','BaseTbl.EmpID = Emp.EmpID'); + $this->db->where('Emp.ContactNumber', $phno); + $query = $this->db->get(); + $result = $query->result(); + return $result; +} + +/** + * To update password and otp + **/ +function resetpassword($Array,$userid){ + + $this->db->where('userId',$userid); + $this->db->update('tbl_users',$Array); + $count = $this->db->affected_rows(); + return $count; + +} + +/** + * To update password only + **/ +function updatepassword($userid,$password){ + + $this->db->set('password',$password); + $this->db->where('userId',$userid); + $this->db->update('tbl_users'); + $count = $this->db->affected_rows(); + return $count; + +} + +} +?> \ No newline at end of file diff --git a/application/views/forgotPassword.php b/application/views/forgotPassword.php index ea6f9df7..2878e522 100644 --- a/application/views/forgotPassword.php +++ b/application/views/forgotPassword.php @@ -15,26 +15,152 @@
+ +