'use strict'; /** * controllers for ng-table//commentgit * Simple table with sorting and filtering on AngularJS */ app.controller('loginCtrl', ["$scope", "$http", "API_POINTS", "$state", '$rootScope', '$cookies', 'md5', 'ipCookie', "SweetAlert", "$window", function ($scope, $http, apiPoint, $state, $rootScope, $cookies, md5, ipCookie, SweetAlert, $window) { /** * login details capture * by : kdk */ $scope.myModel = { 'userMobile': '', 'password': '', 'passwordemp':'' }; $scope.myPwdModel= { curr: "", newpassword: "", empid:"" }; $scope.typeInput = 'password'; $scope.place = 'password'; $scope.icon = 'fa fa-lock'; $scope.show = false; $scope.info = false; $scope.change_empid=''; $scope.loginbutton = true; $scope.responseData = ''; // $scope.form = { $scope.Login=function(myModel) { //console.log(myModel);return false; // alert($scope.Empcheck); //alert('in');return false; var firstError = null; if (form.$invalid) { var field = null, firstError = null; for (field in form) { if (field[0] != '$') { if (firstError === null && !form[field].$valid) { firstError = form[field].$name; } if (form[field].$pristine) { form[field].$dirty = true; } } } 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/', headers: { 'Content-Type': 'application/json' }, data: { userMobile: $scope.myModel.userMobile, password: password, accessFrom: 'Web' } }; $http(req).then(function (response) { // console.log(response.data);return false; if (response.data.loginStatus == true) { $scope.responseData = response.data.details; //console.log($scope.responseData) if($scope.responseData == 'role check') { $scope.Empcheck = true; $scope.loginbutton = false; swal("Your OTP is sent !", response.data.message); } /* * After logined user details store to local client detail */ else { var localDateTime = new Date(); $scope.localStore = { "localUserID": $scope.responseData.ID, "localBranchID": $scope.responseData.BranchCode, 'localType': $scope.responseData.ListCode, 'is_DayBookApproval_Access': $scope.responseData.FinanceModuleAccess, 'is_CalltrackApproval_Access': $scope.responseData.CallModuleAccess, 'localOn': localDateTime, 'status': 'active' } ipCookie('cookiechk', $scope.localStore, { expires: 21 }); sessionStorage.setItem('localObj', JSON.stringify($scope.localStore)); sessionStorage.setItem('localsessionObj', JSON.stringify($scope.localStore)); // console.log('HTRG'); // console.log(localsessionObj); // return false; if($scope.responseData.ListCode=='R001'){ $state.go('app.studentView'); } else if($scope.responseData.ListCode !='R004') { console.log('in') } else{ // $window.location.reload(); console.log('das') $state.go('app.dashboard'); //$state.go('login.Login_pwdchange'); // $window.location.reload(); } } } else if((response.data.loginStatus == false) &&(response.data.passwordStatus==false)) { //console.log('else if') $scope.change_empid=myModel.userMobile; $scope.myPwdModel.empid=$scope.change_empid; $rootScope.Emp = $scope.change_empid; $state.go('login.Login_pwdchange'); } else { // alert(response.data.message); if($scope.Empcheck == false) { swal("Warning!", response.data.message, "warning"); } if(response.data.checkemp == true) { swal("Warning!", response.data.message, "warning"); } $scope.show = true; $(".alert").delay(200).addClass("in").fadeOut(3500); } }); } } // reset: function (form) { // $scope.myModel = angular.copy($scope.master); // form.$setPristine(true); // } //} $scope.myInterval = 2000; // load when html page load $scope.init = function () { $scope.getAnnouncementDetails(); } $scope.getAnnouncementDetails = function () { var req = { method: 'POST', url: apiPoint.url + 'getLoginAnnouncementDetails/', headers: { 'Content-Type': 'application/json' }, data: {} }; $http(req).then(function (response) { if (response.data.AnnouncementStatus) { $scope.slides = response.data.details; // alert(JSON.stringify($scope.slides)); } else { $scope.slides = [{ "Heading" : " ", "description" : " " }] } }); } $scope.EmpLogin=function(myModel) { //console.log(myModel) var empid= myModel.userMobile; var password = myModel.password; var otp = myModel.passwordemp; var md5password = md5.createHash(password); var verify = { method: 'POST', url: apiPoint.url + 'VerifyEmpOTP/', headers: { 'Content-Type': 'application/json' }, data: {EmpID:empid,Password:md5password,OTP:otp} }; $http(verify).then(function (response) { // console.log(response.data.loginStatus) if (response.data.loginStatus == true) { if (response.data.loginStatus == true) { $scope.responseData = response.data.details; var localDateTime = new Date(); $scope.localStore = { "localUserID": $scope.responseData.ID, "localBranchID": $scope.responseData.BranchCode, 'localType': $scope.responseData.ListCode, 'is_DayBookApproval_Access': $scope.responseData.FinanceModuleAccess, 'is_CalltrackApproval_Access': $scope.responseData.CallModuleAccess, 'localOn': localDateTime, 'status': 'active' } ipCookie('cookiechk', $scope.localStore, { expires: 21 }); sessionStorage.setItem('localObj', JSON.stringify($scope.localStore)); sessionStorage.setItem('localsessionObj', JSON.stringify($scope.localStore)); // console.log('HTRG'); // console.log(localsessionObj); // return false; $state.go('app.dashboard'); } } else { swal("Error!", response.data.message, "error"); } }); // } } /** * Checkstudent change function * * created_by : sriram */ $scope.Empcheck = false; $scope.OTP_or_PWD = 0; $scope.checkMobileNumber = function (MobileNumber) { $scope.OTP_or_PWD = MobileNumber; var otpcheck= MobileNumber; 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,otpcheck:otpcheck,pwd:$scope.myModel.passwordemp} }; $http(req).then(function(response){ //alert(otpcheck); //console.log(response) if(otpcheck == undefined) { swal.close(); } if((response.data.loginstudent ==true)||(response.data.loginemployee ==true)){ //console.log('if'); if(response.data.checkstudent == true) { $scope.typeInput = 'text'; $scope.place = 'OTP'; $scope.icon = 'fa fa-key'; $scope.info = true; //swal("Your OTP is sent !", response.data.message); } else if(response.data.pwdcheck== true) { //console.log('in'); $scope.loginbutton = true; // $scope.Empcheck = true; //$scope.typeInput = 'text'; //$scope.place = 'OTP'; //$scope.icon = 'fa fa-key'; //$scope.info = false; } else { if(otpcheck != undefined) { // 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; //swal("Warning!", response.data.message, "warning"); // $scope.show = true; //$(".alert").delay(200).addClass("in").fadeOut(3500); //alert(response.data.message); } }); } } // $scope.myPwdModel= { // curr: "", // newpassword: "", // empid:"" // }; $scope.initlogchange = function (){ //console.log($rootScope.Emp); // console.log($scope.myPwdModel.empid) $scope.myPwdModel.empid=$rootScope.Emp } $scope.ChangePassword = function (Form,myPwdModel) { var userId = myPwdModel.empid; var oldPassword = myPwdModel.curr; var newPassword = myPwdModel.newpassword //var passwordLength = newPassword.length; //console.log(passwordLength) if((userId == undefined)||(oldPassword =="")||(oldPassword == undefined)||(newPassword == undefined)) { swal("Please Enter all the Fields, New Password Should Consist 8 letters!", "", "warning"); } else { var req = { method: 'POST', url: apiPoint.url + 'changePasswordLogin/', headers: { 'Content-Type': 'application/json' }, data: { oldPassword: md5.createHash(oldPassword || ''), newPassword: md5.createHash(newPassword || '') , UserId: userId, } }; $http(req).then(function (response) { console.log(response.data) if(response.data.updateStatus == true) { swal("Success",response.data.message, "success"); } // swal(" Success", message, "success"); form.$setPristine(true); $scope.myModel = { curr: "", newpassword: "", empid: "" }; swal("Success",response.data.message, "success"); //} }, function (error) { //error function }); } } }]);