zettapi_client
Version:
Client side CRUD operations in angular to use with zettapi_server rest api to get started quickly in any CMS project
50 lines (43 loc) • 1.24 kB
JavaScript
app.directive('zlSignup', function (zapiPath) {
return {
restrict: 'E',
scope: true,
replace: false,
templateUrl: zapiPath + '/directives/signup/signup.html',
controller: function ($scope, blockUI, $entity, $uibModalStack) {
$scope.signup = function (item) {
if ($scope.validateSignup(item)) {
return;
}
blockUI.start("A reservar conta...");
$entity.add('user', item)
.then(function (response) {
swal("Está quase!", "Consulte o seu email para ativar a conta de utilizador", "success");
$uibModalStack.dismissAll();
})
.catch(function (response) {
swal("Erro", response.data, "error");
})
.finally(function () {
blockUI.stop();
});
};
$scope.validateSignup = function (item) {
if (!item) {
return true;
}
if (!item.username) {
return true;
}
var validUsername = new RegExp('^[a-zA-Z0-9_]*$');
if (!validUsername.test(item.username)) {
return true;
}
if (!item.email) {
return true;
}
return false;
};
}
};
});