Student OTP Model
This commit is contained in:
parent
3a8f75a676
commit
ad8b57b0db
@ -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
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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*
|
||||
*/
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}]);
|
||||
@ -290,47 +290,48 @@
|
||||
|
||||
<form class="form-login form-horizontal" name="Form" id="form" novalidate ng-submit="form.submit(Form)" method="post">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 col-md-offset-2">
|
||||
<div class="logo" align="center">
|
||||
<img style="margin-bottom:20px;" ng-src="{{app.layout.logo}}" alt="{{app.name}}"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group" ng-class="{'has-error':Form.mobilenumber.$dirty && Form.mobilenumber.$invalid, 'has-success':Form.mobilenumber.$valid}">
|
||||
|
||||
<span class="input-icon">
|
||||
<input type="text" id="inputEmail3" class="form-control underline" ng-model="myModel.userMobile" name="mobilenumber" placeholder="Mobile Number / Employee Id"
|
||||
ng-minlength="4" ng-maxlength="12" required>
|
||||
<i style="color: black;" class="fa fa-mobile"></i>
|
||||
</span>
|
||||
<span class="error text-small block" ng-if="Form.mobilenumber.$dirty && Form.mobilenumber.$error.required"> mobile number is required. </span>
|
||||
<span class="error text-small block" ng-if="Form.mobilenumber.$error.maxlength || Form.mobilenumber.$error.minlength || Form.mobilenumber.$error.pattern">Enter a valid mobile number / Employee Id</span>
|
||||
<div class="row">
|
||||
<div class="col-md-6 col-md-offset-2">
|
||||
<div class="logo" align="center">
|
||||
<img style="margin-bottom:20px;" ng-src="{{app.layout.logo}}" alt="{{app.name}}"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group" ng-class="{'has-error':Form.mobilenumber.$dirty && Form.mobilenumber.$invalid, 'has-success':Form.mobilenumber.$valid}">
|
||||
|
||||
<span class="input-icon">
|
||||
<input type="text" id="inputEmail3" class="form-control underline" ng-model="myModel.userMobile" name="mobilenumber" ng-blur="checkMobileNumber();" placeholder="Mobile Number / Employee Id"
|
||||
ng-minlength="4" ng-maxlength="12" required>
|
||||
<i style="color: black;" class="fa fa-mobile"></i>
|
||||
</span>
|
||||
<span class="error text-small block" ng-if="Form.mobilenumber.$dirty && Form.mobilenumber.$error.required"> mobile number is required. </span>
|
||||
<span class="error text-small block" ng-if="Form.mobilenumber.$error.maxlength || Form.mobilenumber.$error.minlength || Form.mobilenumber.$error.pattern">Enter a valid mobile number / Employee Id</span>
|
||||
</div>
|
||||
|
||||
<div class="form-group" ng-class="{'has-error':Form.password.$dirty && Form.password.$invalid, 'has-success':Form.password.$valid}">
|
||||
|
||||
<span class="input-icon">
|
||||
<input type="password" id="inputPassword3" placeholder="Password" class="form-control heighLight underline" name="password" ng-model="myModel.password"
|
||||
ng-minlength="6" required/>
|
||||
<i style="color: black;" class="fa fa-lock"></i>
|
||||
<span class="error text-small block" ng-if="Form.password.$dirty && Form.password.$invalid"> Password Required</span></span>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<a class="forgot" ui-sref="login.forgot" style="color: black;">I forgot my password </a>
|
||||
<button type="submit" class="btn btn-warning pull-right submitlogin">
|
||||
Login <i class="fa fa-arrow-circle-right"></i>
|
||||
</button>
|
||||
</div>
|
||||
<!--<div class="new-account">
|
||||
Don't have an account yet?
|
||||
<a ui-sref="login.registration">
|
||||
Create an account
|
||||
</a>
|
||||
</div>-->
|
||||
|
||||
</form>
|
||||
<div class="form-group" ng-class="{'has-error':Form.password.$dirty && Form.password.$invalid, 'has-success':Form.password.$valid}">
|
||||
|
||||
<span class="input-icon">
|
||||
<input type="{{typeInput}}" id="inputPassword3" placeholder="{{place}}" class="form-control heighLight underline" name="password" ng-model="myModel.password"
|
||||
ng-minlength="6" required/>
|
||||
<i style="color: black;" class="{{icon}}"></i>
|
||||
<span class="error text-small block" ng-if="Form.password.$dirty && Form.password.$invalid"> {{place}} Required</span></span>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<span ng-if="info == false"><a class="forgot" ui-sref="login.forgot" style="color: black;">I forgot my password </a></span>
|
||||
<span ng-if="info != false" style="color: black;">OTP Valid for 10 minutes only</span>
|
||||
<button type="submit" class="btn btn-warning pull-right submitlogin">
|
||||
Login <i class="fa fa-arrow-circle-right"></i>
|
||||
</button>
|
||||
</div>
|
||||
<!--<div class="new-account">
|
||||
Don't have an account yet?
|
||||
<a ui-sref="login.registration">
|
||||
Create an account
|
||||
</a>
|
||||
</div>-->
|
||||
|
||||
</form>
|
||||
|
||||
<!--</div>-->
|
||||
<!-- end: LOGIN BOX -->
|
||||
|
||||
Loading…
Reference in New Issue
Block a user