Looking for assistance in resolving this issue. Currently, I am attempting to register a new user and need to verify if the username already exists or not. Below is the factory code used for this purpose:
.factory('accountService', function($resource, sessionService) {
var service = {};
service.register = function(account, success, failure) {
if (success (service.userExists(account))){
failure();
} else {
var Account = $resource("/Test/rest/account/student");
Account.save({}, account, success, failure);
}
};
service.userExists = function(account, success, failure) {
var Account = $resource("/Test/rest/account");
var data = Account.get({
username : account.username,
password : account.password
}, function() {
var accounts = data.username;
if (accounts && accounts.length !== 0) {
service.data = data;
success(account);
} else {
failure();
}
}, failure);
};
service.getuser = function() {
return service.data;
};
return service;
})
Encountering an error message when trying to run the code:
TypeError: success is not a function
Below is the controller that utilizes this factory:
.controller(
"RegisterController",
function($scope, sessionService, $state, accountService) {
$scope.register = function() {
accountService.register($scope.account, function(
returnedata) {
sessionService.login($scope.account).then(
function() {
$state.go("home");
});
}, function() {
$scope.registererror = function() {
}
});
};
})