/**
|
* Created by wisestone on 2017-12-15.
|
*/
|
'use strict';
|
|
define([
|
'app',
|
'angular'
|
],
|
function (app, angular) {
|
app.controller('userAddController', ['$scope', '$rootScope', '$log', '$resourceProvider', 'User', 'SweetAlert', '$filter', 'Auth', '$state',
|
function ($scope, $rootScope, $log, $resourceProvider, User, SweetAlert, $filter, Auth, $state) {
|
|
$scope.fn = {
|
formSubmit : formSubmit, // 폼 전송
|
formCheck : formCheck, // 폼 체크
|
onFileSelect : onFileSelect // 프로필 업로드
|
};
|
|
$scope.vm = {
|
form : {
|
name : "",
|
account : "",
|
password : "",
|
passwordConfirm : "",
|
phone : "",
|
profileImage : null,
|
status : "01",
|
workspaceName : "myWorkSpace",
|
profileImageName : null,
|
agreeTerm : false,
|
licensekey : ""
|
}
|
};
|
|
function onFileSelect($files) {
|
$scope.vm.form.profileImage = $files;
|
|
if ($rootScope.isDefined($files)) {
|
$scope.vm.form.profileImageName = $files[0].name;
|
}
|
else {
|
$scope.vm.form.profileImageName = "";
|
}
|
}
|
|
// 폼 체크
|
function formCheck(formInvalid) {
|
if (formInvalid) {
|
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;
|
}
|
|
// if (!$scope.vm.form.agreeTerm) {
|
// return true;
|
// }
|
|
return false;
|
}
|
|
// 폼 전송
|
function formSubmit() {
|
$rootScope.spinner = true; // 프로그래스 바
|
|
var content = angular.copy($scope.vm.form);
|
content.name = $rootScope.preventXss(content.name);
|
content.workspaceName = $rootScope.preventXss(content.workspaceName);
|
content.password = CryptoJS.SHA512(content.password).toString();
|
content.language = $rootScope.language; // 기본 언어
|
|
User.add({
|
method : "POST",
|
file : $scope.vm.form.profileImage,
|
// data 속성으로 별도의 데이터 전송
|
fields : {
|
content : content
|
},
|
fileFormDataName : "file"
|
}).then(function (result) {
|
if (result.data.message.status === "success") {
|
Auth.login({
|
account : $rootScope.encryption($scope.vm.form.account),
|
password : CryptoJS.SHA512($scope.vm.form.password).toString()
|
}).then(function () {
|
$rootScope.spinner = false;
|
$rootScope.back();
|
}).catch(function () {
|
$rootScope.spinner = false;
|
$state.go("login");
|
});
|
}
|
else {
|
SweetAlert.swal($filter("translate")("users.failedToCreateUser"), result.data.message.message, "error"); // "사용자 생성 실패"
|
$rootScope.spinner = false;
|
}
|
});
|
}
|
|
}]);
|
});
|