zettapi_client
Version:
Admin panel and client-side CRUD operations in angular to use with zettapi_server rest api to get started quickly in any CMS project.
63 lines (57 loc) • 2.95 kB
JavaScript
app.directive('zlActivation', function () {
return {
restrict: 'E',
scope: {
zlClass: '@?',
onComplete: '&?',
},
replace: false,
templateUrl: 'directives/auth/activation/activation.html',
controller: function ($scope, $auth, $location, $routeParams, $interpolate, blockUI, zapi) {
$scope.user = null;
$scope.useInputLarge = zapi.useInputLarge;
$scope.zlClass = $scope.zlClass || "form-control input-lg";
$scope.changePassword = function (item) {
if (!item.password) return swal({
title: $interpolate("{{'api.services.auth.changepasswordWrongPasswordTitle' | translate}}")($scope),
text: $interpolate("{{'api.services.auth.changepasswordWrongPasswordContent' | translate}}")($scope),
type: "error"
});
if (item.password !== item.repeat) return swal({
title: $interpolate("{{'api.services.auth.changepasswordWrongPasswordTitle' | translate}}")($scope),
text: $interpolate("{{'api.services.auth.changepasswordWrongPasswordContent' | translate}}")($scope),
type: "error"
});
blockUI.start($interpolate("{{'api.services.auth.changepasswordLoad' | translate}}")($scope));
$auth.changePassword($scope.user, item.password, item.repeat).then(function (response) {
if ($scope.onComplete && typeof $scope.onComplete() === 'function') return $scope.onComplete()(response.data);
swal({
title: $interpolate("{{'api.services.auth.changepasswordSuccessTitle' | translate}}")($scope),
text: $interpolate("{{'api.services.auth.changepasswordSuccessContent' | translate}}")($scope),
type: "info",
confirmButtonText: $interpolate("{{'api.services.auth.changepasswordSuccessBtnOk' | translate}}")($scope)
});
$location.path('/');
}).catch(function (response) {
swal($interpolate("{{'api.services.auth.changepasswordErrorTitle' | translate}}")($scope), response.data, "error");
}).finally(function (response) {
blockUI.stop();
});
};
initialize();
function initialize() {
if (!$routeParams.code) return swal("Código de ativação inválido", "Certifique-se que seguiu o endereço exactamente como enviado no email", "warning");
var codes = $routeParams.code.split('&');
if (codes.length !== 2) return swal("Código de ativação inválido", "Certifique-se que seguiu o endereço exactamente como enviado no email", "warning");
blockUI.start($interpolate("{{'api.services.auth.activateAccountLoad' | translate}}")($scope));
$auth.activateAccount(codes).then(function (response) {
$scope.user = response.data;
}).catch(function (response) {
swal("Atenção", response.data, "warning");
}).finally(function () {
blockUI.stop();
});
}
}
};
});