/** * Created by wisestone on 2018-10-16. */ 'use strict'; define([ 'app', 'angular' ], function (app, angular) { app.controller('userModifyPasswordController', ['$scope', '$rootScope', '$log', '$resourceProvider', 'User', '$uibModalInstance', 'parameter', 'SweetAlert', '$filter', function ($scope, $rootScope, $log, $resourceProvider, User, $uibModalInstance, parameter, SweetAlert, $filter) { $scope.fn = { cancel: cancel, // 팝업 창 닫기 formSubmit: formSubmit, // 폼 전송 formCheck: formCheck // 폼 체크 }; $scope.vm = { form: { id : parameter.id, currentPassword : "", // 현재 비밀번호 password : "", // 비밀번호 passwordConfirm : "" // 신규 비밀번호 확인 } }; // 폼 체크 function formCheck(formInvalid) { if (formInvalid) { return true; } if (!$rootScope.isDefined($scope.vm.form.currentPassword) || !$rootScope.isDefined($scope.vm.form.password) || !$rootScope.isDefined($scope.vm.form.passwordConfirm)) { return true; } if ($scope.vm.form.password.length < 4) { return true; } if ($scope.vm.form.passwordConfirm.length < 4) { return true; } if ($scope.vm.form.password !== $scope.vm.form.passwordConfirm) { return true; } return false; } // 폼 전송 function formSubmit() { $rootScope.spinner = true; var content = { id : $scope.vm.form.id, currentPassword : CryptoJS.SHA512($scope.vm.form.currentPassword).toString(), password : CryptoJS.SHA512($scope.vm.form.password).toString(), passwordConfirm : CryptoJS.SHA512($scope.vm.form.passwordConfirm).toString() }; User.modifyPassword($resourceProvider.getContent( content, $resourceProvider.getPageContent(0, 0))).then(function (result) { if (result.data.message.status === "success") { SweetAlert.swal($filter("translate")("users.completedPasswordChange"), result.data.message.message, "success"); // "비밀번호 변경 완료" $scope.fn.cancel(); } else { SweetAlert.swal($filter("translate")("users.failedPasswordChange"), result.data.message.message, "error"); // "비밀번호 변경 실패" } $rootScope.spinner = false; }); } // 팝업 창 닫기 function cancel() { $rootScope.$broadcast("closeLayer"); // 팝업이 열리고 나서 js-multi, js-single 등에서 body 이벤트가 날아가는 현상 수정 $uibModalInstance.dismiss('cancel'); $(document).unbind("keydown"); // 단축키 이벤트 제거 } }]); });