82 lines
3.2 KiB
JavaScript
82 lines
3.2 KiB
JavaScript
'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", function ($scope, $http, apiPoint, $state, $rootScope, $cookies, md5, ipCookie, SweetAlert) {
|
|
/**
|
|
* login details capture
|
|
* by : kdk
|
|
*/
|
|
$scope.myModel = {
|
|
'userMobile': '',
|
|
'password': ''
|
|
};
|
|
|
|
$scope.show = false;
|
|
|
|
$scope.responseData = '';
|
|
|
|
$scope.form = {
|
|
submit: function (form) {
|
|
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 req = {
|
|
method: 'POST',
|
|
url: apiPoint.url + 'login/',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
data: {
|
|
userMobile: $scope.myModel.userMobile,
|
|
password: md5.createHash($scope.myModel.password || '')
|
|
}
|
|
};
|
|
$http(req).then(function (response) {
|
|
if (response.data.loginStatus == true) {
|
|
$scope.responseData = response.data.details;
|
|
// {"loginStatus":true,"details":{"MobileNumber":"9876543210","ListCode":"R004","ID":"1"}}
|
|
/*
|
|
* After logined user details store to local client detail
|
|
*/
|
|
var localDateTime = new Date();
|
|
$scope.localStore = {
|
|
"localUserID": $scope.responseData.ID,
|
|
"localBranchID": $scope.responseData.BranchCode,
|
|
'localType': $scope.responseData.ListCode,
|
|
'localOn': localDateTime,
|
|
'status': 'active'
|
|
}
|
|
ipCookie('cookiechk', $scope.localStore, { expires: 21 });
|
|
localStorage.setItem('localObj', JSON.stringify($scope.localStore));
|
|
$state.go('app.dashboard');
|
|
} else {
|
|
// alert(response.data.message);
|
|
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);
|
|
}
|
|
}
|
|
}]); |