I have two functions in login controller both functions are implementing login purpose , In this controller !scope.isLoggedIn condition satistified need to check if inside condition. i need to permanate login in application so i store userid and password credienticals in local sessionStorage whenever values are available in localStorage i need to execute automaticLogin function, i checked localStorage data is available or not in if condition if both userid and password is available in localStorage i need to execute automaticLoginUser function if not no need to execute automaticLogin function whenever i am try to execute that automaticLoginUser function getting error TypeError: scope.automaticLoginUser is not a function error. Thank you in advanced..!
app.controller('LoginCtrl', ['$scope',
'userService', '$state', '$rootScope','BackendService', 'CartService',
function(scope, userService, $state, rootScope, BackendService, CartService) {
scope.user = {};
scope.isLoggedIn = false;
scope.userId = CartService.getuserId();
scope.userPassword = CartService.getuserPassword();
if (!scope.isLoggedIn) {
console.log('in side isLoggedIn');
if (scope.userId !== undefined && scope.userPassword !== undefined) {
var loginId = scope.userId;
var password = scope.userPassword;
scope.user.loginId = loginId;
scope.user.password = password;
console.log('after user' + scope.user);
var user = scope.user;
scope.automaticLoginuser(user);
}
scope.automaticLoginuser = function(user) {
alert("Inside automaticLoginuser");
CartService.saveuserId(scope.user.loginId);
CartService.saveuserPassword(scope.user.password);
userService.loginuser(user)
.then(function(response) {
scope.userUuid = response.data.userUuid;
userService.setuserUuid(scope.userUuid);
if (response.data.status === 'success') {
CartService.saveFuuid(scope.fuuid);
$state.go("app.userHome");
} else {
$state.go("app.login");
}
});
};
scope.loginuser = function(user) {
CartService.saveuserId(scope.user.loginId);
CartService.saveuserPassword(scope.user.password);
userService.loginuser(user)
.then(function(response) {
scope.userUuid = response.data.userUuid;
userService.setuserUuid(scope.userUuid);
if (response.data.status === 'success') {
$state.go("app.userHome");
} else {
$state.go("app.login");
}
});
};
}
]);