modifyPwd.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. 'use strict';
  2. var app = angular.module('app', [
  3. 'angularUtils.directives.dirPagination', ////分页用到的插件
  4. 'ngSanitize'///$sanitize这个服务.此服务依赖于ngSanitize模块.(这个模块需要加载angular-sanitize.js插件)
  5. ////应用ng-bind-html如果不引用此模块,会报安全错误
  6. ]);
  7. app.controller("modifyPwdCtrl", ["$http", "$timeout",function ($http,$timeout) {
  8. var self = this;
  9. var s4 = new SM4Util();
  10. self.get_AccessToken=localStorage.getItem("GlWorkPlatform-AccessToken");
  11. ///console.log(self.get_AccessToken);
  12. var get_userid = $.cookie("GlWorkPlatform-userid"); //获取userid;
  13. var postCfg = {
  14. headers: {
  15. 'Content-Type': 'application/json',
  16. 'Authorization': "Bearer " + self.get_AccessToken
  17. }
  18. };
  19. self.info = {
  20. username: $.cookie("GlWorkPlatform-username"),
  21. oldPwd: '',
  22. newPwd: '',
  23. newPwdConfirm: ''
  24. };
  25. self.btnSubmit = function () {
  26. //console.log(self.info);
  27. if (spngvld.submit("#form_checkData")) {
  28. //大小写字母、数字、特殊符号,8位以上
  29. var pwdReg = !!self.info.newPwd.match(/^(?![A-Za-z0-9]+$)(?![a-z0-9\W]+$)(?![A-Za-z\W]+$)(?![A-Z0-9\W]+$)[a-zA-Z0-9\W]{8,16}$/);//验证包含大小写字母、数字、特殊符号
  30. //var pwdReg = !!self.info.newPwd.match(/^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)]|[\(\)])+$)([^(0-9a-zA-Z)]|[\(\)]|[a-z]|[A-Z]|[0-9]){8,16}$/);//验证包含大小写字母、数字、特殊符号任意两种规则
  31. if (!self.info.newPwd) {
  32. sp.dialog("请填写新密码");
  33. }else if(pwdReg==false){
  34. sp.dialog("密码必须同时包含:数字、大写字母、小写字母、特殊符号,并且8~16位");
  35. } else if (self.info.newPwd !== self.info.newPwdConfirm) {
  36. sp.dialog("两次新密码输入不一致");
  37. } else {
  38. //console.log(self.info);
  39. var dialogHead = "<span class=\"sp-dialog-head\"><span class=\"sp-dialog-tip\">温馨提示</span><span class=\"sp-dialog-close sp-closeDialog\" title=\"关闭\">×</span></span>";
  40. var dialogBody = "<div class=\"sp-dialog-body\">确认要修改密码吗?</div>";
  41. 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>";
  42. $('.sp-dialog').html(dialogHead + dialogBody + dialogFoot);
  43. sp.openCenter(".sp-dialog");
  44. ///取消按钮
  45. $('.sp-closeDialog').click(function (event) {
  46. sp.dialoghide();
  47. event.preventDefault(); event.stopPropagation();
  48. });
  49. $("#dialog_btnConfirm").click(function () {
  50. ////推送数据
  51. var postPwdData = {
  52. "oldpassword": self.info.oldPwd,
  53. "newpassword": self.info.newPwd
  54. }
  55. //console.log(postPwdData);
  56. $http.post(apiurljs.login + "g2work/user/updatePasswordByUserid", { data: s4.encryptData_CBC(JSON.stringify(postPwdData)) }, postCfg)
  57. .success(function (obj) {
  58. var res = strToJson(s4.decryptData_CBC(obj.data));
  59. //sp.dialoghide();
  60. ///console.log(res);
  61. if(res.success){
  62. sp.dialog("密码修改成功,请重新登录!");
  63. var data = {
  64. tablename: "LOGIN_STATISTICS_TAB",
  65. data: {
  66. USERID: $.cookie("GlWorkPlatform-userid"),
  67. USHOWNAME: decodeURI($.cookie("GlWorkPlatform-chineseName")),
  68. UINPUTNAME: $.cookie("GlWorkPlatform-username"),
  69. OPERATIONTIME: sp.getLocalDate(),
  70. ONLINEMARK: "out"
  71. }
  72. }
  73. $http.post(apiurljs.login + "g2app/dataabase/insertFormData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  74. .success(function (res) {})
  75. $timeout(function(){
  76. top.location.href = "../../login.html";
  77. $.cookie("GlWorkPlatform-userid", null, { path: '/', expires: -1 });
  78. $.cookie("GlWorkPlatform-chineseName", null, { path: '/', expires: -1 });
  79. $.cookie("GlWorkPlatform-username", null, { path: '/', expires: -1 });
  80. sessionStorage.removeItem("GlWorkPlatform-LoginFrom");
  81. localStorage.removeItem("GlWorkPlatform-openfileArray"); ////清空保存菜单文件的变量
  82. localStorage.removeItem("GlWorkPlatform-setLeftBarClickID");
  83. localStorage.removeItem("GlWorkPlatform-AccessToken");
  84. },1500);
  85. }else{
  86. sp.dialog(res.message);
  87. }
  88. }).error(function(err) {
  89. sp.dialog(JSON.stringify(err));
  90. });
  91. });
  92. }
  93. }
  94. };
  95. self.btnCancel = function () {
  96. var dialogHead = "<span class=\"sp-dialog-head\"><span class=\"sp-dialog-tip\">温馨提示</span><span class=\"sp-dialog-close sp-closeDialog\" title=\"关闭\">×</span></span>";
  97. var dialogBody = "<div class=\"sp-dialog-body\">此操作不影响您的密码,但会清空所填数据,确认要继续吗?</div>";
  98. var dialogFoot = "<div class=\"sp-dialog-foot\"><input id='btnYes' type='button' value='确 认' class='sp-dialog-btnTrue' /><input type='button' value='取 消' class='sp-dialog-btnCancle sp-closeDialog' /></div>";
  99. $('.sp-dialog').html(dialogHead + dialogBody + dialogFoot);
  100. sp.openCenter(".sp-dialog");
  101. ///取消按钮
  102. $('.sp-closeDialog').click(function (event) {
  103. sp.dialoghide();
  104. event.preventDefault(); event.stopPropagation();
  105. });
  106. $("#btnYes").click(function () {
  107. self.info = {
  108. username: $.cookie("GlWorkPlatform-username"),
  109. oldPwd: '',
  110. newPwd: '',
  111. newPwdConfirm: ''
  112. };
  113. spngvld.clear("#form_checkData");
  114. })
  115. };
  116. }]);