'use strict';
var app = angular.module('app', [
'angularUtils.directives.dirPagination'
]);
app.controller("addUserCtrl", ["$http", "$timeout", function ($http, $timeout) {
var self = this;
self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken");
//console.log(self.get_AccessToken);
self.get_userid = $.cookie("GlWorkPlatform-userid"); //获取userid;
var postCfgJson = {
headers: {
'Content-Type': 'application/json',
"Authorization": "Bearer " + self.get_AccessToken
}
};
self.info = {
"UserRealName": "",
"UserName": "",
"Password": "",
"ConfirmPassword": "",
"Email": "",
"PhoneNumber": "",
"WorkNo": "",
"Avatar": ""
};
self.btnSubmit = function () {
//console.log(self.info);
if (spngvld.submit("#form_checkData")) {
//大小写字母、数字、特殊符号、8位以上
var pwdReg = !!self.info.Password.match(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{8,16}$/);
if (!self.info.Password) {
sp.dialog("请填写新密码");
} else if (pwdReg == false) {
sp.dialog("密码必须同时包含:数字、大写字母、小写字母、特殊符号,并且8~16位");
} else if (self.info.Password !== self.info.ConfirmPassword) {
sp.dialog("两次新密码输入不一致");
}else {
var dialogHead = "温馨提示×";
var dialogBody = "
确认要提交吗?
";
var dialogFoot = "";
$('.sp-dialog').html(dialogHead + dialogBody + dialogFoot);
sp.openCenter(".sp-dialog");
///取消按钮
$('.sp-closeDialog').click(function (event) {
sp.dialoghide();
event.preventDefault();
event.stopPropagation();
});
$("#dialog_btnConfirm").click(function () {
var postPwdData = {
"UserRealName": self.info.UserRealName,
"UserName": self.info.UserName,
"Password": self.info.Password,
"ConfirmPassword": self.info.ConfirmPassword,
"Email": self.info.Email,
"PhoneNumber": self.info.PhoneNumber,
"WorkNo": self.info.WorkNo,
"Avatar": self.info.Avatar
}
//console.log(postPwdData);
$http.post(apiurljs.refineapi + "api/User/Register", postPwdData, postCfgJson)
.success(function (res) {
//sp.dialoghide();
console.log(res);
if (res.success) {
sp.dialog("创建成功!");
self.btnCancel();
} else {
sp.dialog(res.message + " 用户创建失败!");
}
}).error(function (err) {
sp.dialog(JSON.stringify(err));
});
});
}
}
};
self.btnCancel = function () {
spngvld.clear("#form_checkData");
self.info = {
"UserRealName": "",
"UserName": "",
"Password": "",
"ConfirmPassword": "",
"Email": "",
"PhoneNumber": "",
"WorkNo": "",
"Avatar": ""
};
};
}]);