forgot password changes
This commit is contained in:
parent
7a40036cdd
commit
d66dbb670a
@ -153,9 +153,13 @@ $route['changePassword'] = "user/changePassword";
|
||||
$route['pageNotFound'] = "user/pageNotFound";
|
||||
|
||||
//<-----------Application Email & ForgetPassword Routes------------>
|
||||
$route['checkEmailExists'] = "user/checkEmailExists";
|
||||
$route['forgotPassword'] = "login/forgotPassword";
|
||||
$route['resetPasswordUser'] = "login/resetPasswordUser";//reset password without OTP
|
||||
$route['resetPasswordConfirmUser'] = "login/resetPasswordConfirmUser";//reset password with OTP
|
||||
|
||||
|
||||
$route['checkEmailExists'] = "user/checkEmailExists";
|
||||
|
||||
$route['forgotPassword'] = "login/forgotPassword";
|
||||
$route['monthlypay'] = "payslip/monthlyInputs";
|
||||
$route['ExcelUpload2'] = "payslip/viewUpload2";
|
||||
|
||||
@ -124,151 +124,132 @@ class Login extends CI_Controller
|
||||
{
|
||||
$this->load->view('forgotPassword');
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This function used to generate reset password request link
|
||||
* To reset password of the user (without one time code)
|
||||
*/
|
||||
function resetPasswordUser()
|
||||
{
|
||||
$status = '';
|
||||
|
||||
$this->load->library('form_validation');
|
||||
|
||||
$this->form_validation->set_rules('login_email','Email','trim|required|valid_email|xss_clean');
|
||||
|
||||
if($this->form_validation->run() == FALSE)
|
||||
{
|
||||
$this->forgetPasswordUser();
|
||||
}
|
||||
else
|
||||
{
|
||||
$email = $this->input->post('login_email');
|
||||
|
||||
if($this->user_model->checkEmailExist($email))
|
||||
{
|
||||
$encoded_email = urlencode($email);
|
||||
|
||||
$this->load->helper('string');
|
||||
$data['email'] = $email;
|
||||
$data['activation_id'] = random_string('alnum',15);
|
||||
$data['created_dtm'] = date('Y-m-d H:i:s');
|
||||
$data['agent'] = $this->getBrowserAgent();
|
||||
$data['client_ip'] = $this->input->ip_address();
|
||||
|
||||
$save = $this->user_model->resetPasswordUser($data);
|
||||
|
||||
if($save)
|
||||
{
|
||||
$config['protocol'] = 'sendmail';
|
||||
$config['mailpath'] = '/usr/sbin/sendmail';
|
||||
$config['charset'] = 'UTF-8';
|
||||
$config['wordwrap'] = TRUE;
|
||||
$config['mailtype'] = 'html';
|
||||
|
||||
$this->load->library('email', $config);
|
||||
|
||||
$data1['reset_link'] = base_url() . "resetPasswordConfirmUser/" . $data['activation_id'] . "/" . $encoded_email;
|
||||
$data1['info'] = $this->user_model->getCustomerInfoByEmail($email);
|
||||
|
||||
$this->email->from(ADMIN_EMAIL_ID, WEBSITE);
|
||||
$this->email->to($email);
|
||||
$this->email->subject(RESET_PASSWORD_EMAIL_SUBJECT);
|
||||
$this->email->message($this->load->view('email', $data1, TRUE));
|
||||
|
||||
if ($this->email->send())
|
||||
{
|
||||
$status = 'send';
|
||||
}
|
||||
else
|
||||
{
|
||||
$status = 'notsend';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$status = 'unable';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$status = 'invalid';
|
||||
}
|
||||
|
||||
echo json_encode(array('status'=>$status));
|
||||
}
|
||||
}
|
||||
|
||||
// This function used to reset the password
|
||||
function resetPasswordConfirmUser()
|
||||
{
|
||||
|
||||
// Get email and activation code from URL values at index 3-4
|
||||
$email = urldecode($this->uri->segment(3));
|
||||
$activation_id = $this->uri->segment(2);
|
||||
|
||||
// Check activation id in database
|
||||
$is_correct = $this->user_model->checkActivationDetails($email, $activation_id);
|
||||
|
||||
$data['email'] = $email;
|
||||
$data['activation_code'] = $activation_id;
|
||||
|
||||
if ($is_correct == 1)
|
||||
{
|
||||
$this->load->view('includes/header');
|
||||
$this->load->view('new_password', $data);
|
||||
$this->load->view('includes/footer');
|
||||
}
|
||||
else
|
||||
{
|
||||
redirect('user');
|
||||
}
|
||||
}
|
||||
function resetPasswordUser(){
|
||||
// echo 'hi';
|
||||
// die();
|
||||
|
||||
// This function used to create new password
|
||||
function createPasswordUser()
|
||||
{
|
||||
$status = '';
|
||||
$message = '';
|
||||
|
||||
$this->load->library('form_validation');
|
||||
|
||||
$this->form_validation->set_rules('password','New Password','required|max_length[20]');
|
||||
$this->form_validation->set_rules('cpassword','New Re-Password','trim|required|matches[password]|max_length[20]');
|
||||
|
||||
if($this->form_validation->run() == FALSE)
|
||||
{
|
||||
echo json_encode(array('status' => 'validation', 'message' => 'Please validate the fields'));
|
||||
$mobileno = $this->input->post('phno');
|
||||
$emailid = $this->input->post('email');
|
||||
$result = $this->login_model->getuserid($mobileno,$emailid);
|
||||
|
||||
if(!empty($result)){
|
||||
|
||||
$string = "abcd".rand(100000,999999)."lmnxyz";
|
||||
$string_shuffled = str_shuffle($string);
|
||||
$passcode = substr($string_shuffled, 1, 6);
|
||||
$password = "SIDH@".$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."'";
|
||||
|
||||
$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 "<script>alert('Password Send successfully, Please check your mobile.');</script>";
|
||||
redirect('/loginMe','refresh');
|
||||
}
|
||||
else
|
||||
{
|
||||
$password = $this->input->post('password');
|
||||
$cpassword = $this->input->post('cpassword');
|
||||
$email = $this->input->post('email');
|
||||
$activation_id = $this->input->post('activation_id');
|
||||
|
||||
// Check activation id in database
|
||||
$is_correct = $this->user_model->checkActivationDetails($email, $activation_id);
|
||||
|
||||
if(($is_correct == 1) && ($password == $cpassword))
|
||||
{
|
||||
$data = array('email_id'=>$email, 'password'=>$password);
|
||||
|
||||
$this->user_model->createPasswordUser($data);
|
||||
|
||||
$status = 'success';
|
||||
$message = 'Password changed successfully';
|
||||
}
|
||||
else
|
||||
{
|
||||
$status = 'error';
|
||||
$message = 'Password changed failed';
|
||||
}
|
||||
|
||||
echo json_encode(array('status'=>$status, 'message'=>$message));
|
||||
else{
|
||||
echo "<script>alert('".$mobileno." This Mobile Number is not registered with us.');</script>";
|
||||
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 "<script>alert('You Password Resetted!');</script>"; redirect('login','refresh');
|
||||
* }
|
||||
* else
|
||||
* {
|
||||
* echo "<script>alert('Have Not Update Error Msg!');</script>"; redirect('login','refresh');
|
||||
* }
|
||||
*
|
||||
* }
|
||||
*/
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@ -46,6 +46,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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>CodeInsect | Admin System Log in</title>
|
||||
<title>Siddharth | Admin System Log in</title>
|
||||
<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
|
||||
<link href="<?php echo base_url(); ?>assets/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
|
||||
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
|
||||
@ -14,50 +14,161 @@
|
||||
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
|
||||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
</head>
|
||||
</head>
|
||||
<body class="login-page">
|
||||
<div class="login-box">
|
||||
<div class="login-logo">
|
||||
<a href="#"><b>Siddharth Industries</b><br>Admin System</a>
|
||||
<a href="#"><b>Resico industries</b><br></a>
|
||||
</div><!-- /.login-logo -->
|
||||
<div class="login-box-body">
|
||||
<p class="login-box-msg">Forgot Password</p>
|
||||
<?php $this->load->helper('form'); ?>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<?php echo validation_errors('<div class="alert alert-danger alert-dismissable">', ' <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button></div>'); ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
$this->load->helper('form');
|
||||
$error = $this->session->flashdata('error');
|
||||
if($error)
|
||||
{
|
||||
?>
|
||||
<div class="alert alert-danger alert-dismissable">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
||||
<?php echo $this->session->flashdata('error'); ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<form action="<?php echo base_url(); ?>loginMe" method="post">
|
||||
<!-- <form action="<?php echo base_url(); ?>resetPasswordConfirmUser" method="post"> // this form action for OTP -->
|
||||
<form action="<?php echo base_url(); ?>resetPasswordUser" method="post">
|
||||
<div class="form-group has-feedback">
|
||||
<input type="email" class="form-control" placeholder="Email" name="email" required />
|
||||
<input type="text" class="form-control" placeholder="Mobile Number" name ="phno" id= "phno" maxlength="10" onkeypress="return isNumber(event)">
|
||||
<span class="glyphicon glyphicon glyphicon-phone form-control-feedback"></span>
|
||||
</div>
|
||||
<div class="form-group has-feedback">
|
||||
<input type="text" class="form-control" placeholder="Email" name="email" required />
|
||||
<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
|
||||
</div>
|
||||
|
||||
<!--
|
||||
<div class="form-group has-feedback" id="pin">
|
||||
<input type="text" class="form-control" placeholder="One time Code" name ="otp" id= "otp" maxlength="4">
|
||||
<span class="glyphicon glyphicon-paperclip form-control-feedback"></span>
|
||||
</div>
|
||||
<div id="passwordfields">
|
||||
<hr>
|
||||
<div>
|
||||
<label for="inputPassword1">New Password</label>
|
||||
<input type="password" class="form-control required" id="NewPassword" placeholder="New password" name="newPassword" maxlength="10" required>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="inputPassword2">Confirm New Password</label>
|
||||
<input type="password" class="form-control required equalTo" required id="ConfirmPassword" placeholder="Confirm new password" name="confirmPassword" maxlength="10" required>
|
||||
<span id='message'></span>
|
||||
</div>
|
||||
<input type="text" id="hideuserid" name="hideuserid" readonly>
|
||||
</div> -->
|
||||
<br/>
|
||||
<div class="row">
|
||||
<div class="col-xs-8">
|
||||
</div><!-- /.col -->
|
||||
<div class="col-xs-4">
|
||||
<input type="submit" class="btn btn-primary btn-block btn-flat" value="Sign In" />
|
||||
<input type="submit" id="submit" class="btn btn-primary btn-block btn-flat" value="Submit"/>
|
||||
</div><!-- /.col -->
|
||||
</div>
|
||||
</form>
|
||||
<!-- </form> -->
|
||||
<a href="<?php echo base_url() ?>">Login</a><br>
|
||||
</div><!-- /.login-box-body -->
|
||||
</div><!-- /.login-box -->
|
||||
|
||||
<script src="<?php echo base_url(); ?>assets/js/jQuery-2.1.4.min.js"></script>
|
||||
<script src="<?php echo base_url(); ?>assets/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
|
||||
<script>
|
||||
/** This for Used as OTP
|
||||
* var dbOTP = '' ;
|
||||
*
|
||||
* $(function() {
|
||||
* $('#passwordfields').hide();
|
||||
* $('#pin').hide();
|
||||
* $('#NewPassword, #ConfirmPassword').on('keyup', function () {
|
||||
* if ($('#NewPassword').val() == $('#ConfirmPassword').val()) {
|
||||
* $('#message').html('Matching').css('color', 'green');
|
||||
* //$("input[type=submit]").attr("disabled", "disabled");
|
||||
* } else
|
||||
* $('#message').html('Password MisMatch').css('color', 'red');
|
||||
* //$("input[type=submit]").attr("disabled", "disabled");
|
||||
* });
|
||||
* });
|
||||
|
||||
* $('#phno').change(function() {
|
||||
* var id = $(this).val();
|
||||
* //alert(id);
|
||||
* $.ajax({
|
||||
* data:{id:id},
|
||||
* type:"POST",
|
||||
* url:"<?php echo base_url();?>login/temp",
|
||||
* success:function(data) {
|
||||
* if(data.length == 4){
|
||||
* $('#pin').show();
|
||||
* dbOTP = data; }
|
||||
* else{ alert(data); }
|
||||
* }
|
||||
* // var data = JSON.parse(data);
|
||||
* // $.each(data,function(index,value){ var i = value.ContactNumber
|
||||
* // if( i == id ){
|
||||
* // alert('OTP send successfully, please check your mobile.');
|
||||
* // }
|
||||
* // else{
|
||||
* // alert(id+'This Mobile Number is not registered with us.');
|
||||
* // }
|
||||
* // });
|
||||
|
||||
* // }
|
||||
* });
|
||||
* });
|
||||
|
||||
|
||||
* $('#otp').change(function() {
|
||||
* var enteredOTP = $(this).val();
|
||||
* //alert('dbOTP'+dbOTP);
|
||||
* if(enteredOTP == dbOTP){
|
||||
* //alert("cont. true");
|
||||
* $('#passwordfields').show();
|
||||
* }
|
||||
* else{
|
||||
* alert("One Time Code Does not Matched. Try Next Times");
|
||||
* $('#passwordfields').hide();
|
||||
* }
|
||||
* });//change function closed
|
||||
*/
|
||||
</script>
|
||||
<script>
|
||||
function isNumber(evt) {
|
||||
evt = (evt) ? evt : window.event;
|
||||
var charCode = (evt.which) ? evt.which : evt.keyCode;
|
||||
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// $('#phno').change(function() {
|
||||
// var id = $(this).val();
|
||||
// //alert(id);
|
||||
// $.ajax({
|
||||
// data:{id:id},
|
||||
// type:"POST",
|
||||
// url:"<?php echo base_url();?>login/sendthepassword",
|
||||
// success:function(data) {
|
||||
// alert(data);
|
||||
// // if(data){
|
||||
// // alert('Password Send successfully, Please check your mobile.');
|
||||
// // }
|
||||
// // else{
|
||||
// // alert(id+'This Mobile Number is not registered with us.');
|
||||
// // alert(data);
|
||||
// // }
|
||||
// }
|
||||
// // var data = JSON.parse(data);
|
||||
// // $.each(data,function(index,value){ var i = value.ContactNumber
|
||||
// // if( i == id ){
|
||||
// // alert('OTP send successfully, please check your mobile.');
|
||||
// // }
|
||||
// // else{
|
||||
// // alert(id+'This Mobile Number is not registered with us.');
|
||||
// // }
|
||||
// // });
|
||||
// });
|
||||
// });
|
||||
|
||||
// $('#submit').click(function() {
|
||||
// alert("adlkhadskjfjhadf");
|
||||
// window.location.href = "loginMe";
|
||||
|
||||
// });
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
@ -63,7 +63,7 @@
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<!-- <a href="<?php echo base_url() ?>forgotPassword">Forgot Password</a><br> -->
|
||||
<a href="<?php echo base_url() ?>forgotPassword">Forgot Password</a><br>
|
||||
|
||||
</div><!-- /.login-box-body -->
|
||||
</div><!-- /.login-box -->
|
||||
|
||||
Loading…
Reference in New Issue
Block a user