addUser.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. 'use strict';
  2. var app = angular.module('app', [
  3. 'angularUtils.directives.dirPagination'
  4. ]);
  5. app.controller("addUserCtrl", ["$http", "$timeout", function ($http, $timeout) {
  6. var self = this;
  7. self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken");
  8. //console.log(self.get_AccessToken);
  9. self.get_userid = $.cookie("GlWorkPlatform-userid"); //获取userid;
  10. var postCfgJson = {
  11. headers: {
  12. 'Content-Type': 'application/json',
  13. "Authorization": "Bearer " + self.get_AccessToken
  14. }
  15. };
  16. self.info = {
  17. "UserRealName": "",
  18. "UserName": "",
  19. "Password": "",
  20. "ConfirmPassword": "",
  21. "Email": "",
  22. "PhoneNumber": "",
  23. "WorkNo": "",
  24. "Avatar": ""
  25. };
  26. self.btnSubmit = function () {
  27. //console.log(self.info);
  28. if (spngvld.submit("#form_checkData")) {
  29. //大小写字母、数字、特殊符号、8位以上
  30. var pwdReg = !!self.info.Password.match(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{8,16}$/);
  31. if (!self.info.Password) {
  32. sp.dialog("请填写新密码");
  33. } else if (pwdReg == false) {
  34. sp.dialog("密码必须同时包含:数字、大写字母、小写字母、特殊符号,并且8~16位");
  35. } else if (self.info.Password !== self.info.ConfirmPassword) {
  36. sp.dialog("两次新密码输入不一致");
  37. }else {
  38. var dialogHead = "<span class=\"sp-dialog-head\"><span class=\"sp-dialog-tip\">温馨提示</span><span class=\"sp-dialog-close sp-closeDialog\" title=\"关闭\">×</span></span>";
  39. var dialogBody = "<div class=\"sp-dialog-body\">确认要提交吗?</div>";
  40. var dialogFoot = "<div class=\"sp-dialog-foot\"><input id='dialog_btnConfirm' type='button' value='确 认' class='sp-dialog-btnTrue' /><input type='button' value='取 消' class='sp-dialog-btnCancle sp-closeDialog' /></div>";
  41. $('.sp-dialog').html(dialogHead + dialogBody + dialogFoot);
  42. sp.openCenter(".sp-dialog");
  43. ///取消按钮
  44. $('.sp-closeDialog').click(function (event) {
  45. sp.dialoghide();
  46. event.preventDefault();
  47. event.stopPropagation();
  48. });
  49. $("#dialog_btnConfirm").click(function () {
  50. var postPwdData = {
  51. "UserRealName": self.info.UserRealName,
  52. "UserName": self.info.UserName,
  53. "Password": self.info.Password,
  54. "ConfirmPassword": self.info.ConfirmPassword,
  55. "Email": self.info.Email,
  56. "PhoneNumber": self.info.PhoneNumber,
  57. "WorkNo": self.info.WorkNo,
  58. "Avatar": self.info.Avatar
  59. }
  60. //console.log(postPwdData);
  61. $http.post(apiurljs.refineapi + "api/User/Register", postPwdData, postCfgJson)
  62. .success(function (res) {
  63. //sp.dialoghide();
  64. console.log(res);
  65. if (res.success) {
  66. sp.dialog("创建成功!");
  67. self.btnCancel();
  68. } else {
  69. sp.dialog(res.message + " 用户创建失败!");
  70. }
  71. }).error(function (err) {
  72. sp.dialog(JSON.stringify(err));
  73. });
  74. });
  75. }
  76. }
  77. };
  78. self.btnCancel = function () {
  79. spngvld.clear("#form_checkData");
  80. self.info = {
  81. "UserRealName": "",
  82. "UserName": "",
  83. "Password": "",
  84. "ConfirmPassword": "",
  85. "Email": "",
  86. "PhoneNumber": "",
  87. "WorkNo": "",
  88. "Avatar": ""
  89. };
  90. };
  91. }]);