diff --git a/Apollo/api/application/config/routes.php b/Apollo/api/application/config/routes.php index d771ddd3..05e314d7 100755 --- a/Apollo/api/application/config/routes.php +++ b/Apollo/api/application/config/routes.php @@ -60,6 +60,8 @@ $route['translate_uri_dashes'] = TRUE; */ $route['autenticadors'] = 'autenticador/index'; // Example 4 $route['login'] = 'Login_Controller/login'; +//student number check +$route['checkmobilenumber'] = 'Login_Controller/checkMobileNumber'; // Forget password $route['forgetlogin'] = 'Forget_Controller/forgetlogin'; // branch diff --git a/Apollo/api/application/controllers/Login_Controller.php b/Apollo/api/application/controllers/Login_Controller.php index d7d9655e..a1812074 100755 --- a/Apollo/api/application/controllers/Login_Controller.php +++ b/Apollo/api/application/controllers/Login_Controller.php @@ -115,6 +115,27 @@ class Login_Controller extends REST_Controller { } - + /* + *Check Mobile Number* + + */ + public function checkMobileNumber_post(){ + $studentnum = $this->post('mobilenum'); + $getstudent = $this->login_model->checkstudnetnumber($studentnum); + if ($getstudent) + { + $getstudent['status'] = REST_Controller::HTTP_OK; + // Set the response and exit + $this->response($getstudent, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code + } + else + { + // Set the response and exit + $this->response([ + 'message' => 'No records found!', + 'status' => REST_Controller::HTTP_NOT_FOUND + ], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code + } + } } \ No newline at end of file diff --git a/Apollo/api/application/models/Login_model.php b/Apollo/api/application/models/Login_model.php index ce271f08..8277d763 100755 --- a/Apollo/api/application/models/Login_model.php +++ b/Apollo/api/application/models/Login_model.php @@ -22,7 +22,7 @@ class Login_model extends CI_Model public function login($mobile = null, $password = null) { - $this->db->select('t1.MobileNumber, t1.Password,t1.ListCode'); + $this->db->select('t1.MobileNumber, t1.Password,t1.ListCode,t1.UpdatedOn,t1.OTP'); $this->db->from('' . LOGIN . ' as t1'); $this->db->where('t1.MobileNumber', $mobile); $this->db->or_where('t1.StaffID', $mobile); @@ -33,9 +33,58 @@ class Login_model extends CI_Model // print_r($loginDetails); - + if($loginDetails) { $mobileno= $loginDetails->MobileNumber; + $mobileno= $loginDetails->MobileNumber; + if($loginDetails->ListCode == STUDENT){ + $start = date_create($loginDetails->UpdatedOn); + $end = date_create(); + $diff = date_diff($end,$start); + if($diff->i <= 10){ + if($password == $loginDetails->OTP){ + + $this->db->select('LO.MobileNumber, LO.ListCode, LO.ID,ST.BranchCode, ST.LoginAccess'); + $this->db->from('' . LOGIN . ' as LO'); + $this->db->join('' . STUDENTS . ' as ST', 'LO.StaffID = ST.StudentID'); + $this->db->where('LO.MobileNumber', $mobile); + $this->db->where('ST.IsActive', 1); + $responseDetails = $this->db->get()->first_row(); + + if($responseDetails){ + + $save['OTP'] = ''; + $this->db->where('MobileNumber',$mobile); + $this->db->where('ListCode',STUDENT); + + $this->db->update('T_Login',$save); + + + if($responseDetails->LoginAccess == 1){ + $result['loginStatus'] = true; + $result['details'] = $responseDetails; + } else { + $result['loginStatus'] = false; + $result['message'] = "Your login is de-activated."; + } + } + else{ + $result['loginStatus'] = false; + $result['message'] = "Your login is de-activated."; + } + }else{ + $result['loginStatus'] = false; + $result['message'] = "Please Enter Valid OTP !!"; + } + }else{ + $result['loginStatus'] = false; + $result['message'] = "OTP is Expired !!"; + $save['OTP'] = ''; + $this->db->where('MobileNumber',$mobile); + $this->db->update('T_Login',$save); + } + + }else{ if ($mobile == $loginDetails->MobileNumber || $mobile == $loginDetails->StaffID) { if ($password == $loginDetails->Password) { @@ -129,6 +178,7 @@ class Login_model extends CI_Model $result['loginStatus'] = false; $result['message'] = "Please Enter Register Mobile Number !!"; } + } } else { $result['loginStatus'] = false; $result['message'] = "Your login is de-activated or don't have login."; @@ -169,4 +219,80 @@ class Login_model extends CI_Model } return $result; } + /** + * Studnet Check function* + * created_by : sriram + */ + public function checkstudnetnumber($mobile){ + $this->db->select('t1.MobileNumber, t1.Password,t1.ListCode'); + $this->db->from('' . LOGIN . ' as t1'); + $this->db->where('t1.MobileNumber', $mobile); + + + $this->db->where('t1.IsActive', 1); + + $loginDetails = $this->db->get(LOGIN)->first_row(); + //print_r($loginDetails);die; + if($loginDetails){ + if($loginDetails->ListCode == STUDENT){ + $result['loginstudent'] = true; + $this->db->select('LO.MobileNumber, LO.ListCode, LO.ID,ST.BranchCode, ST.LoginAccess'); + $this->db->from('' . LOGIN . ' as LO'); + $this->db->join('' . STUDENTS . ' as ST', 'LO.StaffID = ST.StudentID'); + $this->db->where('LO.MobileNumber', $mobile); + $this->db->where('ST.IsActive', 1); + $responseDetails = $this->db->get()->first_row(); + if($responseDetails->LoginAccess ==1){ + $string2 = str_shuffle('1234567890'); + $otp = substr($string2,0,6); + //echo $otp;die; + $save['OTP'] = $otp; + $save['UpdatedOn'] = date('Y-m-d H:i:s'); + // print_r($save);die; + $this->db->where('MobileNumber',$mobile); + $this->db->where('ListCode',STUDENT); + $query = $this->db->update('T_Login',$save); + + + if($query == 1){ + $sms = $this->smssend($mobile,$otp); + + $result['checkstudent'] = true; + }else{ + $result['checkstudent'] = false; + } + + + }else { + $result['loginStatus'] = false; + $result['message'] = "Your login is de-activated."; + } + }else{ + $result['loginstudent'] = false; + } + }else{ + $result['checkstudent'] = false; + $result['message'] = "Your login is de-activated or don't have login."; + } + //print_r($result);die; + return $result; + } + public function smssend($mobile,$OTP) { + + + + $message ="Your One Time Password to Login to apollodec.com is $OTP. This is valid for 10 minutes."; + $mobile = "91$mobile"; + $message = urlencode($message); + // echo $message;die; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, "https://smsapi.24x7sms.com/api_2.0/SendSMS.aspx?APIKEY=xegCdYUIMf3&MobileNo=" . $mobile . "&SenderID=APOLLO&Message=" . $message . "&ServiceName=PROMOTIONAL_HIGH"); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + $output = curl_exec($ch); + curl_close($ch); + return $output; + } + /** + * End the function* + */ } \ No newline at end of file diff --git a/Apollo/assets/js/controllers/loginCtrl.js b/Apollo/assets/js/controllers/loginCtrl.js index 6c251642..63813711 100755 --- a/Apollo/assets/js/controllers/loginCtrl.js +++ b/Apollo/assets/js/controllers/loginCtrl.js @@ -14,7 +14,12 @@ app.controller('loginCtrl', ["$scope", "$http", "API_POINTS", "$state", '$rootSc 'password': '' }; + $scope.typeInput = 'password'; + $scope.place = 'password'; + $scope.icon = 'fa fa-lock'; $scope.show = false; + $scope.info = false; + $scope.responseData = ''; @@ -36,6 +41,12 @@ app.controller('loginCtrl', ["$scope", "$http", "API_POINTS", "$state", '$rootSc angular.element('.ng-invalid[name=' + firstError + ']').focus(); } else { $scope.spin = ''; + var password = ''; + if($scope.typeInput =='text'){ + var password = $scope.myModel.password; + }else{ + var password = md5.createHash($scope.myModel.password || ''); + } var req = { method: 'POST', url: apiPoint.url + 'login/', @@ -44,7 +55,7 @@ app.controller('loginCtrl', ["$scope", "$http", "API_POINTS", "$state", '$rootSc }, data: { userMobile: $scope.myModel.userMobile, - password: md5.createHash($scope.myModel.password || '') + password: password } }; $http(req).then(function (response) { @@ -113,4 +124,47 @@ app.controller('loginCtrl', ["$scope", "$http", "API_POINTS", "$state", '$rootSc } }); } + /** + * Checkstudent change function * + * created_by : sriram + */ + $scope.checkMobileNumber = function (MobileNumber) { + //alert($scope.myModel.userMobile); + // var studentNumber = $scope.myModel.userMobile; + if($scope.myModel.userMobile !=''){ + swal({ + title:"Please Wait..", + imageUrl: 'https://cdn.dribbble.com/users/15774/screenshots/1759511/spinner.gif', + showConfirmButton: false + }); + var req = { + method:'POST', + url:apiPoint.url + 'checkmobilenumber', + + header:{'Content-Type':'application/json'}, + data:{mobilenum:$scope.myModel.userMobile} + }; + $http(req).then(function(response){ + //console.log(response); + swal.close(); + if(response.data.loginstudent ==true){ + if(response.data.checkstudent == true){ + $scope.typeInput = 'text'; + $scope.place = 'OTP'; + $scope.icon = 'fa fa-key'; + $scope.info = true; + }else{ + swal("Warning!", response.data.message, "warning"); + $scope.show = true; + $(".alert").delay(200).addClass("in").fadeOut(3500); + } + }else{ + $scope.typeInput = 'password'; + $scope.place = 'password'; + $scope.icon = 'fa fa-lock'; + $scope.info = false; + } + }); + } + } }]); \ No newline at end of file diff --git a/Apollo/assets/views/login_login.html b/Apollo/assets/views/login_login.html index a533beaa..2738434e 100755 --- a/Apollo/assets/views/login_login.html +++ b/Apollo/assets/views/login_login.html @@ -290,47 +290,48 @@
-
-
- -
-
-
- - - - - - mobile number is required. - Enter a valid mobile number / Employee Id +
+
+ +
+
+ + + + + + mobile number is required. + Enter a valid mobile number / Employee Id +
-
- - - - - Password Required -
- -
- I forgot my password - -
- - - +
+ + + + + {{place}} Required +
+ +
+ I forgot my password + OTP Valid for 10 minutes only + +
+ + +