Authentication.js 108 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317
  1. MWF.xDesktop = MWF.xDesktop || {};
  2. MWF.xApplication = MWF.xApplication || {};
  3. MWF.xDesktop.requireApp("Template", "MPopupForm", null, false);
  4. MWF.require("MWF.xDesktop.UserData", null, false);
  5. MWF.xDesktop.Authentication = new Class({
  6. Extends: MWF.widget.Common,
  7. Implements: [Options, Events],
  8. options: {
  9. "style": "default",
  10. // "width": "650",
  11. // "height": "480"
  12. "width": "420",
  13. "height": "640",
  14. "popupStyle_password": "o2platformSignupFlat",
  15. "popupStyle_signup": "o2platformSignup"
  16. },
  17. initialize: function (options, app, node) {
  18. this.setOptions(options);
  19. this.node = node;
  20. this.path = MWF.defaultPath + "/xDesktop/$Authentication/";
  21. var css = null;
  22. MWF.UD.getPublicData("loginStyleList", function (json) {
  23. if (json && json.enabledId) {
  24. MWF.UD.getPublicData(json.enabledId, function (json) {
  25. if (json && json.data) {
  26. css = json.data;
  27. }
  28. }.bind(this), false);
  29. }
  30. }.bind(this), false);
  31. if (!css) {
  32. this.cssPath = MWF.defaultPath + "/xDesktop/$Authentication/" + this.options.style + "/css.wcss";
  33. this._loadCss();
  34. } else {
  35. this.css = css;
  36. }
  37. this.lp = MWF.LP.authentication;
  38. this.app = app || {};
  39. },
  40. isAuthenticated: function (success, failure) {
  41. MWF.Actions.get("x_organization_assemble_authentication").getAuthentication(success, failure);
  42. },
  43. loadLogin: function (node) {
  44. if(node)this.loginNode = node;
  45. if( !node && this.loginNode )node = this.loginNode;
  46. if (layout.config.loginPage && layout.config.loginPage.enable && layout.config.loginPage.portal) {
  47. MWF.xDesktop.loadPortal(layout.config.loginPage.portal, this.options.loginParameter);
  48. this.fireEvent("openLogin");
  49. } else {
  50. this.popupOptions = {
  51. "draggable": false,
  52. "closeAction": false,
  53. "hasMask": false,
  54. "relativeToApp": false
  55. };
  56. this.popupPara = {
  57. container: node
  58. };
  59. this.postLogin = function (json) {
  60. layout.desktop.session.user = json.data;
  61. layout.session.user = json.data;
  62. layout.session.token = layout.session.user.token;
  63. var user = layout.desktop.session.user;
  64. if (!user.identityList) user.identityList = [];
  65. if (user.roleList) {
  66. var userRoleName = [];
  67. user.roleList.each(function (role) {
  68. userRoleName.push(role.substring(0, role.indexOf("@")));
  69. });
  70. user.roleList = user.roleList.concat(userRoleName);
  71. }
  72. window.location.reload();
  73. }.bind(this);
  74. this.openLoginForm(this.popupOptions);
  75. this.fireEvent("openLogin");
  76. }
  77. },
  78. logout: function ( callback ) {
  79. MWF.Actions.get("x_organization_assemble_authentication").logout(function () {
  80. if (this.socket) {
  81. this.socket.close();
  82. this.socket = null;
  83. }
  84. Cookie.dispose("x-token");
  85. if (layout.session && layout.session.user) layout.session.user.token = "";
  86. if( callback ){
  87. callback()
  88. }else{
  89. window.location.reload();
  90. }
  91. }.bind(this));
  92. },
  93. openLoginForm: function (options, callback) {
  94. var opt = Object.merge(this.popupOptions || {}, options || {}, {
  95. onPostOk: function (json) {
  96. if (callback) callback(json);
  97. if (this.postLogin) this.postLogin(json);
  98. this.fireEvent("postOk", json)
  99. }.bind(this)
  100. });
  101. opt.width = this.options.width;
  102. opt.height = this.options.height;
  103. var form = new MWF.xDesktop.Authentication.LoginForm(this, {}, opt, this.popupPara);
  104. form.create();
  105. },
  106. openSignUpForm: function (options, callback) {
  107. var opt = Object.merge(this.popupOptions || {}, options || {}, {
  108. onPostOk: function (json) {
  109. if (callback) callback(json);
  110. this.fireEvent("postOk", json)
  111. }.bind(this)
  112. });
  113. delete opt.width;
  114. delete opt.height;
  115. if (this.options.popupStyle_signup) opt.popupStyle = this.options.popupStyle_signup;
  116. var form = new MWF.xDesktop.Authentication.SignUpForm(this, {}, opt, this.popupPara);
  117. form.create();
  118. },
  119. openResetPasswordForm: function (options, callback) {
  120. var opt = Object.merge(this.popupOptions || {}, options || {}, {
  121. onPostOk: function (json) {
  122. if (callback) callback(json);
  123. this.fireEvent("postOk", json)
  124. }.bind(this)
  125. });
  126. if (this.options.popupStyle_password) opt.popupStyle = this.options.popupStyle_password;
  127. // delete opt.width;
  128. // delete opt.height;
  129. var form = new MWF.xDesktop.Authentication.ResetPasswordForm(this, {}, opt, this.popupPara);
  130. form.create();
  131. },
  132. openChangePasswordForm: function (options, callback) {
  133. //options 里应该包括 userName
  134. var opt = Object.merge(this.popupOptions || {}, options || {}, {
  135. onPostOk: function (json) {
  136. if (callback) callback(json);
  137. this.fireEvent("postOk", json)
  138. }.bind(this)
  139. });
  140. // if (this.options.popupStyle_password) opt.popupStyle = this.options.popupStyle_password;
  141. var form = new MWF.xDesktop.Authentication.ChangePasswordForm(this, {}, opt, this.popupPara);
  142. form.create();
  143. }
  144. });
  145. MWF.xDesktop.Authentication.LoginForm = new Class({
  146. Extends: MPopupForm,
  147. Implements: [Options, Events],
  148. options: {
  149. "style": "default",
  150. "popupStyle": "o2platform",
  151. "width": "650",
  152. "height": "480",
  153. "hasTop": true,
  154. "hasIcon": false,
  155. "hasTopIcon": true,
  156. "hasTopContent": true,
  157. "hasBottom": false,
  158. "hasScroll": false,
  159. "hasMark": false,
  160. "title": (layout.config && (layout.config.systemTitle || layout.config.title)) ? (layout.config.title || layout.config.systemTitle) : MWF.LP.authentication.LoginFormTitle,
  161. "draggable": true,
  162. "closeAction": true
  163. },
  164. //Camera Login
  165. _createTopContent: function () {
  166. this.actions = MWF.Actions.get("x_organization_assemble_authentication");
  167. this.faceLogin = false;
  168. this.actions.getLoginMode(function (json) {
  169. this.faceLogin = json.data.faceLogin;
  170. }.bind(this), null, false);
  171. if (this.faceLogin) {
  172. if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
  173. COMMON.AjaxModule.loadDom("../o2_lib/adapter/adapter.js", function () {
  174. if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
  175. //暂时隐藏此功能
  176. this.cameraLoginIcon = new Element("div", { "styles": this.explorer.css.cameraLoginIcon }).inject(this.formTopContentNode);
  177. this.cameraLoginIcon.addEvent("click", function () {
  178. if (!this.isCameraLogin) {
  179. this.cameraLogin();
  180. this.isCameraLogin = true;
  181. } else {
  182. this.closeCamera();
  183. this.isCameraLogin = false;
  184. }
  185. }.bind(this));
  186. }
  187. }.bind(this));
  188. }
  189. }
  190. },
  191. closeCamera: function () {
  192. if (this.cameraLoginVideoNode) {
  193. if (this.video) this.video.destroy();
  194. if (this.canvas) this.canvas.destroy();
  195. if (this.cameraLoginVideoNode) this.cameraLoginVideoNode.destroy();
  196. this.video = null;
  197. this.canvas = null;
  198. this.cameraLoginVideoNode = null;
  199. }
  200. this.cameraLoginIcon.setStyles(this.explorer.css.cameraLoginIcon);
  201. },
  202. cameraLoginInit: function () {
  203. this.cameraLoginConfig = {
  204. "maxStep": 2,
  205. "step": 0,
  206. "count": 0,
  207. "max": 2,
  208. "errorCount": 0,
  209. "errorMax": 3,
  210. "user": "",
  211. "tokens": []
  212. };
  213. },
  214. cameraLoginReset: function (resetError) {
  215. this.cameraLoginConfig.count = 0;
  216. this.cameraLoginConfig.user = "";
  217. if (resetError) this.cameraLoginConfig.errorCount = 0;
  218. },
  219. cameraLogin: function () {
  220. this.cameraLoginInit();
  221. this.cameraLoginIcon.setStyles(this.explorer.css.closeCameraLoginIcon);
  222. this.createCameraLoginNode();
  223. this.startCameraLogin();
  224. },
  225. createCameraLoginNode: function () {
  226. this.cameraLoginVideoNode = new Element("div", { "styles": this.explorer.css.cameraLoginVideoNode }).inject(this.container);
  227. var size = this.formNode.getSize();
  228. var topSize = this.formTopNode.getSize();
  229. var h = size.y - topSize.y;
  230. this.cameraLoginVideoNode.setStyles({
  231. "width": "" + size.x + "px",
  232. "height": "" + h + "px"
  233. });
  234. this.cameraLoginVideoNode.position({
  235. "relativeTo": this.formContentNode,
  236. "position": "upperLeft",
  237. "edge": "upperLeft"
  238. });
  239. },
  240. startCameraLogin: function () {
  241. this.cameraLoginVideoAreaNode = new Element("div").inject(this.cameraLoginVideoNode);
  242. this.cameraLoginVideoInfoNode = new Element("div", { "styles": this.explorer.css.cameraLoginVideoInfoNode }).inject(this.cameraLoginVideoNode);
  243. this.cameraLoginVideoInfoNode.set("text", MWF.LP.desktop.login.camera_logining);
  244. var size = this.cameraLoginVideoNode.getSize();
  245. var infoSize = this.cameraLoginVideoInfoNode.getSize();
  246. var h = size.y - infoSize.y;
  247. this.cameraLoginVideoAreaNode.setStyle("height", "" + h + "px");
  248. this.cameraLoginVideoAreaNode.set("html", "<video autoplay></video>");
  249. this.video = this.cameraLoginVideoAreaNode.getFirst().setStyles({
  250. "background-color": "#000000",
  251. "width": "" + size.x + "px",
  252. "height": "" + h + "px"
  253. });
  254. this.videoStart();
  255. },
  256. videoStart: function () {
  257. this.video.addEventListener("canplay", function () {
  258. window.setTimeout(function () {
  259. this.startCameraAuthentication();
  260. }.bind(this), 500);
  261. }.bind(this));
  262. navigator.mediaDevices.getUserMedia({
  263. audio: false,
  264. video: true
  265. }).then(function (stream) {
  266. this.video.srcObject = stream;
  267. }.bind(this))["catch"](function (error) {
  268. console.log('navigator.getUserMedia error: ', error);
  269. this.closeCamera();
  270. }.bind(this));
  271. },
  272. getFormData: function () {
  273. if (!this.canvas) {
  274. this.canvas = new Element("canvas", { "styles": { "display": "none" } }).inject(this.cameraLoginVideoNode);
  275. this.canvas.width = this.video.videoWidth;
  276. this.canvas.height = this.video.videoHeight;
  277. }
  278. this.canvas.getContext('2d').drawImage(this.video, 0, 0, this.canvas.width, this.canvas.height);
  279. var blob = this.toBlob(this.canvas.toDataURL());
  280. var formData = new FormData();
  281. formData.append('file', blob);
  282. this.canvas.destroy();
  283. return { "data": formData, "size": blob.size };
  284. },
  285. //检测出身份
  286. checkUserFace: function (formData) {
  287. var faceset = window.location.host;
  288. faceset = faceset.replace(/\./g, "_");
  289. this.faceAction.search(faceset, formData.data, { "name": "pic", "size": formData.size }, function (json) {
  290. if (json.data.results && json.data.results.length) {
  291. var hold = json.data.thresholds["1e-5"];
  292. if (json.data.results[0].confidence > hold) {
  293. var token = json.data.faces[0].face_token;
  294. var user = json.data.results[0].user_id;
  295. if ((!this.cameraLoginConfig.user) || (this.cameraLoginConfig.user === user)) {
  296. this.cameraLoginConfig.count++;
  297. this.cameraLoginConfig.user = user;
  298. this.cameraLoginConfig.tokens.push(token);
  299. this.cameraLoginConfig.step++;
  300. this.cameraLoginConfig.errorCount = 0;
  301. this.cameraLoginVideoInfoNode.set("text", MWF.LP.desktop.login["camera_logining_" + this.cameraLoginConfig.step]);
  302. } else {
  303. this.cameraLoginReset();
  304. this.cameraLoginConfig.errorCount++;
  305. }
  306. } else {
  307. this.cameraLoginReset();
  308. this.cameraLoginConfig.errorCount++;
  309. }
  310. } else {
  311. this.cameraLoginReset();
  312. this.cameraLoginConfig.errorCount++;
  313. }
  314. this.checkCameraLogin();
  315. }.bind(this), function () {
  316. window.setTimeout(function () { this.startCameraAuthentication(); }.bind(this), 500);
  317. }.bind(this));
  318. },
  319. checkUserAlive: function (formData, attr, method) {
  320. this.faceAction.detectattr(attr, formData.data, { "name": "pic", "size": formData.size }, function (json) {
  321. if (json.data.faces && json.data.faces.length) {
  322. if (this[method](json.data.faces[0].attributes)) {
  323. this.cameraLoginConfig.step++;
  324. this.cameraLoginConfig.errorCount = 0;
  325. this.cameraLoginVideoInfoNode.set("text", MWF.LP.desktop.login["camera_logining_" + this.cameraLoginConfig.step]);
  326. } else {
  327. //可能是照片
  328. this.cameraLoginConfig.errorCount++;
  329. }
  330. } else {
  331. this.cameraLoginConfig.errorCount++;
  332. }
  333. this.checkCameraLogin();
  334. }.bind(this), function () {
  335. this.cameraLoginConfig.errorCount++;
  336. this.checkCameraLogin();
  337. }.bind(this));
  338. },
  339. //检测微笑
  340. checkUserSmile: function (attr) {
  341. return attr.smile.value > attr.smile.threshold;
  342. },
  343. //检测抬头
  344. checkUserPitch: function (attr) {
  345. return attr.headpose.pitch_angle < -10;
  346. },
  347. startCameraAuthentication: function () {
  348. if (this.video) {
  349. var formData = this.getFormData();
  350. if (!this.faceAction) this.faceAction = MWF.Actions.get("x_faceset_control");
  351. if (this.cameraLoginConfig.step === 0) {
  352. this.checkUserFace(formData);
  353. }
  354. if (this.cameraLoginConfig.step === 1) {
  355. this.checkUserAlive(formData, "smiling", "checkUserSmile");
  356. }
  357. if (this.cameraLoginConfig.step === 2) {
  358. this.checkUserAlive(formData, "headpose", "checkUserPitch");
  359. }
  360. }
  361. },
  362. toBlob: function (base64) {
  363. var bytes;
  364. if (base64.substr(0, 10) === 'data:image') {
  365. bytes = window.atob(base64.split(',')[1]);
  366. } else {
  367. bytes = window.atob(base64);
  368. }
  369. var ab = new ArrayBuffer(bytes.length);
  370. var ia = new Uint8Array(ab);
  371. for (var i = 0; i < bytes.length; i++) {
  372. ia[i] = bytes.charCodeAt(i);
  373. }
  374. return new Blob([ab], { type: "image/png" });
  375. },
  376. getDIF: function (arr) {
  377. var max = Math.max.apply(this, arr);
  378. var min = Math.min.apply(this, arr);
  379. return max - min;
  380. },
  381. checkCameraLogin: function () {
  382. debugger;
  383. if (this.cameraLoginConfig.errorCount > this.cameraLoginConfig.errorMax) {
  384. this.cameraLoginVideoInfoNode.set("text", MWF.LP.desktop.login.camera_loginError);
  385. } else {
  386. if (this.cameraLoginConfig.step >= this.cameraLoginConfig.maxStep) {
  387. var text = MWF.LP.desktop.login.camera_loginSuccess.replace("{name}", this.cameraLoginConfig.user);
  388. this.cameraLoginVideoInfoNode.set("text", text);
  389. this.cameraLoginSuccess();
  390. } else {
  391. window.setTimeout(function () { this.startCameraAuthentication(); }.bind(this), 100);
  392. }
  393. }
  394. },
  395. cameraLoginSuccess: function () {
  396. COMMON.AjaxModule.loadDom(["../o2_lib/CryptoJS/tripledes.js", "../o2_lib/CryptoJS/mode-ecb.js"], function () {
  397. //COMMON.AjaxModule.loadDom(, function(){
  398. var addressObj = layout.serviceAddressList["x_organization_assemble_authentication"];
  399. var url = layout.config.app_protocol + "//" + (addressObj.host || window.location.hostname)+ (addressObj.port === 80 ? "" : ":" + addressObj.port) + addressObj.context;
  400. var code = this.crypDES();
  401. var json = { "client": "face", "token": code };
  402. var res = new Request.JSON({
  403. "method": "POST",
  404. "url": url + "/jaxrs/sso",
  405. "data": JSON.stringify(json),
  406. secure: false,
  407. emulation: false,
  408. noCache: true,
  409. withCredentials: true,
  410. "headers": {
  411. "Content-Type": "application/json; charset=utf-8"
  412. },
  413. onSuccess: function (responseJSON) {
  414. this._close();
  415. this.closeCamera();
  416. if (this.formMaskNode) this.formMaskNode.destroy();
  417. this.formAreaNode.destroy();
  418. if (this.explorer && this.explorer.view) this.explorer.view.reload();
  419. if (this.app) this.app.notice(this.lp.loginSuccess, "success");
  420. this.fireEvent("postOk", responseJSON);
  421. }.bind(this),
  422. onError: function () {
  423. this.cameraLoginVideoInfoNode.set("text", MWF.LP.desktop.login.camera_loginError2);
  424. }.bind(this)
  425. });
  426. res.send();
  427. //}.bind(this));
  428. }.bind(this));
  429. },
  430. crypDES: function () {
  431. var key = "xplatform";
  432. var userId = this.cameraLoginConfig.user;
  433. var d = (new Date()).getTime();
  434. var keyHex = CryptoJS.enc.Utf8.parse(key);
  435. var xtoken = CryptoJS.DES.encrypt(userId + "#" + d, keyHex, {
  436. mode: CryptoJS.mode.ECB,
  437. padding: CryptoJS.pad.Pkcs7
  438. });
  439. var str = xtoken.ciphertext.toString(CryptoJS.enc.Base64);
  440. str = str.replace(/=/g, "");
  441. str = str.replace(/\+/g, "-");
  442. str = str.replace(/\//g, "_");
  443. return str;
  444. },
  445. _createTableContent: function () {
  446. this.loginType = "captcha";
  447. this.codeLogin = false;
  448. this.bindLogin = false;
  449. this.captchaLogin = true;
  450. this.actions.getLoginMode(function (json) {
  451. this.codeLogin = json.data.codeLogin;
  452. this.bindLogin = json.data.bindLogin;
  453. this.captchaLogin = json.data.captchaLogin;
  454. }.bind(this), null, false);
  455. MWF.Actions.get("x_organization_assemble_personal").getRegisterMode(function (json) {
  456. this.signUpMode = json.data.value;
  457. }.bind(this), null, false);
  458. if (this.bindLogin) {
  459. this.bindLoginTipPic = new Element("div.bindLoginTipPic", { styles: this.css.bindLoginTipPic }).inject(this.formContentNode, "top");
  460. this.bindLoginAction = new Element("div.bindLoginAction", { styles: this.css.bindLoginAction }).inject(this.formContentNode, "top");
  461. this.bindLoginAction.addEvent("click", function () {
  462. this.showBindCodeLogin();
  463. }.bind(this));
  464. this.backtoPasswordLoginTipPic = new Element("div.backtoPasswordLoginTipPic", { styles: this.css.backtoPasswordLoginTipPic }).inject(this.formContentNode, "top");
  465. this.backtoPasswordLoginAction = new Element("div.backtoPasswordLoginAction", { styles: this.css.backtoPasswordLoginAction }).inject(this.formContentNode, "top");
  466. this.backtoPasswordLoginAction.addEvent("click", function () {
  467. this.backtoPasswordLogin();
  468. }.bind(this));
  469. }
  470. var html =
  471. "<table width='100%' bordr='0' cellpadding='0' cellspacing='0' styles='formTable'>" +
  472. "<tr><div><div item='passwordAction'>";
  473. if (this.codeLogin) {
  474. html += "</div><div styles='titleSep'></div><div item='codeAction'></div></tr>";
  475. }
  476. html += "</table>";
  477. html += "<table width='100%' bordr='0' cellpadding='0' cellspacing='0' styles='formTable'>" +
  478. "<tr item='credentialTr'><td styles='formTableValueTop20' item='credential'></td></tr>" +
  479. "<tr item='passwordTr'><td styles='formTableValueTop20' item='password'></td></tr>";
  480. if (this.captchaLogin) {
  481. html += "<tr item='captchaTr'><td styles='formTableValueTop20'>" +
  482. "<div item='captchaAnswer' style='float:left;'></div><div item='captchaPic' style='float:left;'></div><div item='changeCaptchaAction' style='float:left;'></div>" +
  483. "</td></tr>";
  484. }
  485. if (this.codeLogin) {
  486. html += "<tr item='codeTr' style='display: none'><td styles='formTableValueTop20'>" +
  487. " <div item='codeAnswer' style='float:left;'></div>" +
  488. " <div item='verificationAction' style='float:left;'></div>" +
  489. " <div item='resendVerificationAction' style='float:left;display:none;'></div>" +
  490. "</td></tr>";
  491. }
  492. html += "<tr><td styles='formTableValueTop20' item='loginAction'></td></tr>" +
  493. "</table>" +
  494. "<table width='100%' bordr='0' cellpadding='0' cellspacing='0' styles='formTable'>";
  495. if (this.signUpMode && this.signUpMode !== "disable") {
  496. html += "<tr><td><div item='signUpAction'></div><div item='forgetPassword'></div></td></tr>";
  497. } else {
  498. html += "<tr><td><div styles='signUpAction'></div><div item='forgetPassword'></div></td></tr>";
  499. }
  500. html += "<tr><td styles='formTableValue' item='errorArea'></td></tr>" +
  501. "<tr><td styles='formTableValue' item='oauthArea'></td></tr>" +
  502. "</table>";
  503. this.formTableArea.set("html", html);
  504. new Element("div", {
  505. "styles": this.css.formFooter,
  506. // "styles": {
  507. // "text-align": "center",
  508. // "height": "40px",
  509. // "line-height": "40px"
  510. // },
  511. "text": layout.config.footer || layout.config.systemName
  512. }).inject(this.formTableArea, "after");
  513. if (this.captchaLogin) this.setCaptchaPic();
  514. this.errorArea = this.formTableArea.getElement("[item=errorArea]");
  515. this.oauthArea = this.formTableArea.getElement("[item=oauthArea]");
  516. MWF.xDesktop.requireApp("Template", "MForm", function () {
  517. this.form = new MForm(this.formTableArea, this.data, {
  518. style: this.options.popupStyle,
  519. verifyType: "single", //batch一起校验,或alert弹出
  520. isEdited: this.isEdited || this.isNew,
  521. itemTemplate: {
  522. credential: {
  523. text: this.lp.userName,
  524. defaultValue: this.lp.userName,
  525. className: "inputUser",
  526. notEmpty: true,
  527. defaultValueAsEmpty: true,
  528. emptyTip: this.lp.inputYourUserName,
  529. event: {
  530. focus: function (it) {
  531. if (this.lp.userName === it.getValue()) it.setValue("");
  532. if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputActive);
  533. }.bind(this),
  534. blur: function (it) {
  535. if ("" === it.getValue()) it.setValue(this.lp.userName);
  536. if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputUser);
  537. }.bind(this),
  538. keyup: function (it, ev) {
  539. if (ev.event.keyCode === 13) this.ok();
  540. }.bind(this)
  541. },
  542. onEmpty: function (it) {
  543. it.getElements()[0].setStyles(this.css.inputEmpty);
  544. }.bind(this),
  545. onUnempty: function (it) {
  546. it.getElements()[0].setStyles(this.css.inputUser);
  547. }.bind(this)
  548. },
  549. password: {
  550. text: this.lp.password,
  551. type: "password",
  552. defaultValue: "password",
  553. className: "inputPassword",
  554. notEmpty: true,
  555. defaultValueAsEmpty: true,
  556. emptyTip: this.lp.inputYourPassword,
  557. event: {
  558. focus: function (it) {
  559. if ("password" === it.getValue()) it.setValue("");
  560. if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputActive);
  561. }.bind(this),
  562. blur: function (it) {
  563. if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputPassword);
  564. }.bind(this),
  565. keyup: function (it, ev) {
  566. if (ev.event.keyCode === 13) this.ok();
  567. }.bind(this)
  568. },
  569. onEmpty: function (it) {
  570. it.getElements()[0].setStyles(this.css.inputEmpty);
  571. }.bind(this),
  572. onUnempty: function (it) {
  573. it.getElements()[0].setStyles(this.css.inputPassword);
  574. }.bind(this)
  575. },
  576. captchaAnswer: {
  577. tType: "number",
  578. text: this.lp.verificationCode,
  579. defaultValue: this.lp.verificationCode,
  580. className: "inputVerificationCode",
  581. notEmpty: true,
  582. defaultValueAsEmpty: true,
  583. emptyTip: this.lp.inputPicVerificationCode,
  584. event: {
  585. focus: function (it) {
  586. if (this.lp.verificationCode === it.getValue()) it.setValue("");
  587. if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputActive);
  588. }.bind(this),
  589. blur: function (it) {
  590. if ("" === it.getValue()) it.setValue(this.lp.verificationCode);
  591. if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputVerificationCode);
  592. }.bind(this),
  593. keyup: function (it, ev) {
  594. if (ev.event.keyCode === 13) this.ok();
  595. }.bind(this)
  596. },
  597. onEmpty: function (it) {
  598. it.getElements()[0].setStyles(this.css.inputEmpty);
  599. }.bind(this),
  600. onUnempty: function (it) {
  601. it.getElements()[0].setStyles(this.css.inputVerificationCode);
  602. }.bind(this)
  603. },
  604. changeCaptchaAction: {
  605. value: this.lp.changeVerification,
  606. type: "innerText",
  607. className: "verificationChange",
  608. event: {
  609. click: function () {
  610. this.setCaptchaPic();
  611. }.bind(this)
  612. }
  613. },
  614. codeAnswer: {
  615. text: this.lp.verificationCode,
  616. defaultValue: this.lp.inputVerificationCode,
  617. className: "inputVerificationCode2",
  618. notEmpty: true,
  619. defaultValueAsEmpty: true,
  620. emptyTip: this.lp.inputVerificationCode,
  621. event: {
  622. focus: function (it) {
  623. if (this.lp.inputVerificationCode === it.getValue()) it.setValue("");
  624. if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputActive);
  625. }.bind(this),
  626. blur: function (it) {
  627. if ("" === it.getValue()) it.setValue(this.lp.inputVerificationCode);
  628. if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputVerificationCode2);
  629. }.bind(this),
  630. keyup: function (it, ev) {
  631. if (ev.event.keyCode === 13) this.ok();
  632. }.bind(this)
  633. },
  634. onEmpty: function (it) {
  635. it.getElements()[0].setStyles(this.css.inputEmpty);
  636. }.bind(this),
  637. onUnempty: function (it) {
  638. it.getElements()[0].setStyles(this.css.inputVerificationCode2);
  639. }.bind(this)
  640. },
  641. verificationAction: {
  642. value: this.lp.sendVerification,
  643. type: "button",
  644. className: "inputSendVerification",
  645. event: {
  646. click: function () {
  647. this.sendVerificationAction();
  648. }.bind(this)
  649. }
  650. },
  651. resendVerificationAction: {
  652. value: this.lp.resendVerification,
  653. type: "button",
  654. className: "inputResendVerification"
  655. },
  656. loginAction: {
  657. value: this.lp.loginAction,
  658. type: "button",
  659. className: "inputLogin",
  660. event: {
  661. click: function () {
  662. this.ok();
  663. }.bind(this)
  664. }
  665. },
  666. passwordAction: {
  667. value: this.lp.passwordLogin,
  668. type: "innerText",
  669. className: "titleNode_active",
  670. event: {
  671. click: function () {
  672. if (this.codeLogin) this.showPasswordLogin();
  673. }.bind(this)
  674. }
  675. },
  676. codeAction: {
  677. value: this.lp.codeLogin,
  678. type: "innerText",
  679. className: "titleNode_normal",
  680. event: {
  681. click: function () {
  682. this.showCodeLogin();
  683. }.bind(this)
  684. }
  685. },
  686. signUpAction: {
  687. value: this.lp.signUp,
  688. type: "innerText",
  689. className: "signUpAction",
  690. event: {
  691. click: function () {
  692. this.gotoSignup();
  693. }.bind(this)
  694. }
  695. },
  696. forgetPassword: {
  697. value: this.lp.forgetPassword,
  698. type: "innerText",
  699. className: "forgetPassword",
  700. event: {
  701. click: function () {
  702. this.gotoResetPassword();
  703. }.bind(this)
  704. }
  705. }
  706. }
  707. }, this.app, this.css);
  708. this.form.load();
  709. }.bind(this), true);
  710. if (this.bindLogin) {
  711. this.bindLoginContainer = new Element("div", {
  712. styles: this.css.bindLoginContainer
  713. }).inject(this.formContentNode);
  714. var html2 = "<div item='bindLoginTitle' styles='bindTitleNode'></div>" +
  715. "<div styles='bindBodyArea'>" +
  716. "<div item='bindPicArea' styles='bindPicArea'></div>" +
  717. "<div styles='bindSepArea'></div>" +
  718. "<div styles='bindExampleArea'></div>" +
  719. "</div>" +
  720. "<div styles='bindTipArea'>" +
  721. " <div styles='bindTipIconArea'></div>" +
  722. " <div styles='bindTipTextArea'>" +
  723. " <div>打开<div styles='bindTipLinkArea'>APP</div>扫一扫</div>" +
  724. " <div>登录网页版</div>" +
  725. "</div>";
  726. this.bindLoginContainer.set("html", html2);
  727. this.isShowEnable = true;
  728. this.bindBodyArea = this.bindLoginContainer.getElement("[styles='bindBodyArea']");
  729. this.bindLoginContainer.addEvent("mousemove", function (ev) {
  730. if (this.bindBodyArea.isOutside(ev)) {
  731. this.hideExampleArea(ev);
  732. } else {
  733. this.showExampleArea(ev);
  734. }
  735. }.bind(this));
  736. this.bindPicArea = this.bindLoginContainer.getElement("[item='bindPicArea']");
  737. this.setBindPic();
  738. this.bindExampleArea = this.bindLoginContainer.getElement("[styles='bindExampleArea']");
  739. this.bindSepArea = this.bindLoginContainer.getElement("[styles='bindSepArea']");
  740. var link = this.bindLoginContainer.getElement("[styles='bindTipLinkArea']");
  741. link.addEvent("click", function () {
  742. if( layout.config.appUrl ){
  743. window.open(layout.config.appUrl, "_blank");
  744. }else{
  745. window.open(this.lp.o2downloadLink, "_blank");
  746. }
  747. }.bind(this));
  748. MWF.xDesktop.requireApp("Template", "MForm", function () {
  749. this.bindform = new MForm(this.bindLoginContainer, {}, {
  750. style: "o2platform",
  751. verifyType: "single", //batch一起校验,或alert弹出
  752. isEdited: this.isEdited || this.isNew,
  753. itemTemplate: {
  754. bindLoginTitle: { value: this.lp.bingLoginTitle, type: "innerText" }
  755. }
  756. }, this.app, this.css);
  757. this.bindform.load();
  758. }.bind(this), true);
  759. }
  760. this.loadOauthContent()
  761. },
  762. _beforeFormNodeSize: function () {
  763. if (!this.isPlusOauthSize && this.oauthListNode) {
  764. this.options.height = parseInt(this.options.height) + this.oauthArea.getSize().y;
  765. this.isPlusOauthSize = true;
  766. }
  767. if (this.oauthListNode || (!this.captchaLogin && !this.bindLogin)) { //留高度给二维码
  768. this.options.height = this.options.height - 60;
  769. }
  770. if (this.oauthListNode && this.captchaLogin) {
  771. this.options.height = this.options.height + 60;
  772. }
  773. },
  774. loadOauthContent: function () {
  775. this.actions.listOauthServer(function (json) {
  776. this.oauthList = json.data || [];
  777. if (this.oauthList.length > 0) {
  778. if (!this.oauthArea.getChildren().length) {
  779. this.oauthListNode = new Element("div", { styles: this.css.oauthListNode }).inject(this.oauthArea);
  780. }
  781. this.oauthList.each(function (d) {
  782. if (d.displayName === "@O2企业微信") {
  783. d.qywx = true;
  784. } else if (d.displayName === "@O2钉钉") {
  785. d.dingding = true;
  786. }
  787. this.loadOauthItem(d);
  788. }.bind(this));
  789. }
  790. }.bind(this), null, false);
  791. },
  792. loadOauthItem: function (data) {
  793. var url = data.icon.indexOf("http") == 0 ? data.icon : ("data:image/png;base64," + data.icon);
  794. var itemNode = new Element("div", {
  795. styles: this.css.oauthItemNode,
  796. events: {
  797. click: function () {
  798. var url = "../x_desktop/oauth.html?oauth=" + encodeURIComponent(this.name);
  799. if (this.qywx) {
  800. url += "&qywx=" + this.qywx;
  801. }
  802. if (this.dingding) {
  803. url += "&dingding=" + this.dingding;
  804. }
  805. window.location = url;
  806. }.bind(data)
  807. }
  808. }).inject(this.oauthListNode);
  809. var iconNode = new Element("img", {
  810. styles: this.css.oauthItemIconNode,
  811. src: url
  812. }).inject(itemNode);
  813. var textNode = new Element("div", {
  814. styles: this.css.oauthItemTextNode,
  815. text: data.name
  816. }).inject(itemNode);
  817. },
  818. showExampleArea: function () {
  819. if (this.isHiddingExample || this.isShowingExample) return;
  820. if (!this.isShowEnable) return;
  821. this.isShowingExample = true;
  822. var left = this.bindBodyArea.getPosition(this.bindBodyArea.getParent()).x;
  823. var hideLeft = ((this.bindBodyArea.getParent().getSize().x) - 400) / 2;
  824. this.intervalId = setInterval(function () {
  825. if (left > hideLeft) {
  826. this.bindBodyArea.setStyle("margin-left", (left - 5) + "px");
  827. left = left - 5;
  828. } else {
  829. clearInterval(this.intervalId);
  830. this.bindBodyArea.setStyle("width", "400px");
  831. this.bindSepArea.setStyle("display", "");
  832. this.bindExampleArea.setStyle("display", "");
  833. this.isHidEnable = true;
  834. this.isShowEnable = false;
  835. this.isShowingExample = false;
  836. }
  837. }.bind(this), 10)
  838. },
  839. hideExampleArea: function () {
  840. if (this.isShowingExample || this.isHiddingExample) return;
  841. if (!this.isHidEnable) return;
  842. this.isHiddingExample = true;
  843. var left = this.bindBodyArea.getPosition(this.bindBodyArea.getParent()).x;
  844. this.bindSepArea.setStyle("display", "none");
  845. this.bindExampleArea.setStyle("display", "none");
  846. var hideLeft = ((this.bindBodyArea.getParent().getSize().x) - 200) / 2;
  847. this.intervalId2 = setInterval(function () {
  848. if (left < hideLeft) {
  849. this.bindBodyArea.setStyle("margin-left", (left + 5) + "px");
  850. left = left + 5;
  851. } else {
  852. clearInterval(this.intervalId2);
  853. this.bindBodyArea.setStyle("width", "204px");
  854. this.isHidEnable = false;
  855. this.isShowEnable = true;
  856. this.isHiddingExample = false;
  857. }
  858. }.bind(this), 10)
  859. },
  860. showPasswordLogin: function () {
  861. this.errorArea.empty();
  862. this.loginType = "captcha";
  863. this.form.getItem("passwordAction").setStyles(this.css.titleNode_active);
  864. this.form.getItem("codeAction").setStyles(this.css.titleNode_normal);
  865. this.formTableArea.getElement("[item='passwordTr']").setStyle("display", "");
  866. var captchaTr = this.formTableArea.getElement("[item='captchaTr']");
  867. if (captchaTr) captchaTr.setStyle("display", "");
  868. this.formTableArea.getElement("[item='codeTr']").setStyle("display", "none");
  869. },
  870. showCodeLogin: function () {
  871. this.errorArea.empty();
  872. this.loginType = "code";
  873. this.form.getItem("passwordAction").setStyles(this.css.titleNode_normal);
  874. this.form.getItem("codeAction").setStyles(this.css.titleNode_active);
  875. this.formTableArea.getElement("[item='passwordTr']").setStyle("display", "none");
  876. var captchaTr = this.formTableArea.getElement("[item='captchaTr']");
  877. if (captchaTr) captchaTr.setStyle("display", "none");
  878. this.formTableArea.getElement("[item='codeTr']").setStyle("display", "");
  879. },
  880. showBindCodeLogin: function () {
  881. this.errorArea.empty();
  882. this.formTableContainer.setStyle("display", "none");
  883. this.bindLoginContainer.setStyle("display", "");
  884. this.bindLoginTipPic.setStyle("display", "none");
  885. this.bindLoginAction.setStyle("display", "none");
  886. this.backtoPasswordLoginTipPic.setStyle("display", "");
  887. this.backtoPasswordLoginAction.setStyle("display", "");
  888. this.checkBindStatus();
  889. },
  890. backtoPasswordLogin: function () {
  891. this.errorArea.empty();
  892. if (this.bindStatusInterval) clearInterval(this.bindStatusInterval);
  893. this.formTableContainer.setStyle("display", "");
  894. this.bindLoginContainer.setStyle("display", "none");
  895. this.bindLoginTipPic.setStyle("display", "");
  896. this.bindLoginAction.setStyle("display", "");
  897. this.backtoPasswordLoginTipPic.setStyle("display", "none");
  898. this.backtoPasswordLoginAction.setStyle("display", "none");
  899. },
  900. setBindPic: function () {
  901. this.bindPicArea.empty();
  902. this.actions.getLoginBind(function (json) {
  903. this.bindMeta = json.data.meta;
  904. new Element("img", {
  905. src: "data:image/png;base64," + json.data.image
  906. }).inject(this.bindPicArea);
  907. }.bind(this))
  908. },
  909. setCaptchaPic: function () {
  910. if (!this.captchaLogin) return;
  911. var captchaPic = this.formTableArea.getElement("[item='captchaPic']");
  912. captchaPic.empty();
  913. this.actions.getLoginCaptcha(120, 50, function (json) {
  914. this.captcha = json.data.id;
  915. new Element("img", {
  916. src: "data:image/png;base64," + json.data.image,
  917. styles: this.css.verificationImage
  918. }).inject(captchaPic);
  919. }.bind(this))
  920. },
  921. sendVerificationAction: function () {
  922. var flag = true;
  923. var credentialItem = this.form.getItem("credential");
  924. var credential = credentialItem.getValue();
  925. if (!credential || credential.trim() === "") {
  926. credentialItem.setWarning(this.lp.inputYourUserName, "empty");
  927. return;
  928. } else {
  929. this.actions.checkCredential(credential, function (json) {
  930. if (!json.data.value) {
  931. flag = false;
  932. credentialItem.setWarning(this.lp.userNotExist, "invalid");
  933. }
  934. }.bind(this), function (errorObj) {
  935. flag = false;
  936. var error = JSON.parse(errorObj.responseText);
  937. credentialItem.setWarning(error.message, "invalid");
  938. }.bind(this), false)
  939. }
  940. if (!flag) {
  941. return;
  942. } else {
  943. credentialItem.clearWarning("invalid");
  944. }
  945. this.actions.createCredentialCode(credential, function (json) {
  946. }, function (errorObj) {
  947. var error = JSON.parse(errorObj.responseText);
  948. this.setWarning(error.message);
  949. flag = false
  950. }.bind(this));
  951. if (!flag) {
  952. return;
  953. } else {
  954. this.errorArea.empty();
  955. }
  956. this.form.getItem("verificationAction").container.setStyle("display", "none");
  957. this.setResendVerification();
  958. },
  959. setResendVerification: function () {
  960. var resendItem = this.form.getItem("resendVerificationAction");
  961. resendItem.container.setStyle("display", "");
  962. this.resendElement = resendItem.getElements()[0];
  963. this.resendElement.set("text", this.lp.resendVerification + "(60)");
  964. var i = 60;
  965. this.timer = setInterval(function () {
  966. if (i > 0) {
  967. this.resendElement.set("text", this.lp.resendVerification + "(" + --i + ")")
  968. } else {
  969. this.form.getItem("verificationAction").container.setStyle("display", "");
  970. resendItem.container.setStyle("display", "none");
  971. clearInterval(this.timer)
  972. }
  973. }.bind(this), 1000)
  974. },
  975. gotoSignup: function () {
  976. this.explorer.openSignUpForm();
  977. //this.explorer.openResetPasswordForm();
  978. this.close();
  979. },
  980. gotoResetPassword: function () {
  981. this.explorer.openResetPasswordForm();
  982. this.close();
  983. },
  984. gotoChangePassword : function( options ){ //密码过期
  985. this.explorer.openChangePasswordForm( options, function(){
  986. this.explorer.loadLogin();
  987. }.bind(this));
  988. this.close();
  989. },
  990. checkBindStatus: function () {
  991. this.bindStatusInterval = setInterval(function () {
  992. this.actions.checkBindStatus(this.bindMeta, function (json) {
  993. if (json.data) {
  994. if (json.data.name && json.data.name !== "anonymous") {
  995. this.fireEvent("queryOk");
  996. this._close();
  997. if (this.formMaskNode) this.formMaskNode.destroy();
  998. this.formAreaNode.destroy();
  999. if (this.explorer && this.explorer.view) this.explorer.view.reload();
  1000. if (this.app) this.app.notice(this.lp.loginSuccess, "success");
  1001. this.fireEvent("postOk", json);
  1002. }
  1003. }
  1004. }.bind(this), function (errorObj) {
  1005. //var error = JSON.parse( errorObj.responseText );
  1006. //this.setWarning( error.message );
  1007. }.bind(this))
  1008. }.bind(this), 3000);
  1009. },
  1010. _close: function () {
  1011. if (this.bindStatusInterval) clearInterval(this.bindStatusInterval);
  1012. if (this.timer) clearInterval(this.timer);
  1013. },
  1014. ok: function () {
  1015. this.fireEvent("queryOk");
  1016. this.errorArea.empty();
  1017. var captchaItem = null;
  1018. var codeItem = null;
  1019. if (this.loginType === "captcha") {
  1020. this.form.getItem("password").options.notEmpty = true;
  1021. if (this.captchaLogin) {
  1022. captchaItem = this.form.getItem("captchaAnswer");
  1023. if (captchaItem) captchaItem.options.notEmpty = true;
  1024. }
  1025. codeItem = this.form.getItem("codeAnswer");
  1026. if (codeItem) codeItem.options.notEmpty = false;
  1027. } else if (this.loginType === "code") {
  1028. this.form.getItem("password").options.notEmpty = false;
  1029. if (this.captchaLogin) {
  1030. captchaItem = this.form.getItem("captchaAnswer");
  1031. if (captchaItem) captchaItem.options.notEmpty = false;
  1032. }
  1033. codeItem = this.form.getItem("codeAnswer");
  1034. if (codeItem) codeItem.options.notEmpty = true;
  1035. }
  1036. var data = this.form.getResult(true, ",", true, false, true);
  1037. if (data) {
  1038. this._ok(data, function (json) {
  1039. if (json.type === "error") {
  1040. if (this.app) this.app.notice(json.message, "error");
  1041. } else if( json.data.passwordExpired ){ //密码过期
  1042. var userName = json.data.distinguishedName;
  1043. this.explorer.logout( function(){ //注销再到密码修改页
  1044. this.gotoChangePassword({
  1045. userName : userName
  1046. });
  1047. }.bind(this))
  1048. } else {
  1049. this._close();
  1050. if (this.formMaskNode) this.formMaskNode.destroy();
  1051. this.formAreaNode.destroy();
  1052. if (this.explorer && this.explorer.view) this.explorer.view.reload();
  1053. if (this.app) this.app.notice(this.lp.loginSuccess, "success");
  1054. this.fireEvent("postOk", json);
  1055. }
  1056. }.bind(this));
  1057. }
  1058. },
  1059. setWarning: function (text) {
  1060. this.errorArea.empty();
  1061. new Element("div", {
  1062. "text": text,
  1063. "styles": this.css.warningMessageNode
  1064. }).inject(this.errorArea);
  1065. },
  1066. _ok: function (data, callback) {
  1067. var d = null;
  1068. if (this.loginType === "captcha") {
  1069. d = {
  1070. credential: data.credential,
  1071. password: data.password
  1072. };
  1073. if (this.captchaLogin) {
  1074. d.captchaAnswer = data.captchaAnswer;
  1075. d.captcha = this.captcha;
  1076. }
  1077. this.actions.loginByCaptcha(d, function (json) {
  1078. if (callback) callback(json);
  1079. //this.fireEvent("postOk")
  1080. }.bind(this), function (errorObj) {
  1081. var error = JSON.parse(errorObj.responseText);
  1082. this.setWarning(error.message);
  1083. this.setCaptchaPic();
  1084. if (this.form.getItem("captchaAnswer")) this.form.getItem("captchaAnswer").setValue("");
  1085. }.bind(this));
  1086. } else if (this.loginType === "code") {
  1087. d = {
  1088. credential: data.credential,
  1089. codeAnswer: data.codeAnswer
  1090. };
  1091. this.actions.loginByCode(d, function (json) {
  1092. if (callback) callback(json);
  1093. //this.fireEvent("postOk")
  1094. }.bind(this), function (errorObj) {
  1095. var error = JSON.parse(errorObj.responseText);
  1096. this.setWarning(error.message);
  1097. }.bind(this));
  1098. }
  1099. }
  1100. });
  1101. MWF.xDesktop.Authentication.SignUpForm = new Class({
  1102. Extends: MPopupForm,
  1103. Implements: [Options, Events],
  1104. options: {
  1105. "style": "default",
  1106. "popupStyle": "o2platformSignup",
  1107. "width": "910",
  1108. "height": "740",
  1109. "hasTop": true,
  1110. "hasIcon": false,
  1111. "hasTopIcon": true,
  1112. "hasTopContent": true,
  1113. "hasBottom": false,
  1114. "title": MWF.LP.authentication.SignUpFormTitle,
  1115. "draggable": true,
  1116. "closeAction": true
  1117. },
  1118. _createTableContent: function () {
  1119. var self = this;
  1120. this.actions = MWF.Actions.get("x_organization_assemble_personal");
  1121. var signUpMode = "code";
  1122. this.actions.getRegisterMode(function (json) {
  1123. signUpMode = json.data.value;
  1124. }.bind(this), null, false);
  1125. this.formTableContainer.setStyles({
  1126. "width": "890px",
  1127. "margin-top": "50px"
  1128. });
  1129. var html = "<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>" +
  1130. "<tr><td styles='formTableTitle' lable='name' width='200'></td>" +
  1131. " <td styles='formTableValue' item='name' width='350'></td>" +
  1132. " <td styles='formTableValue' item='nameTip'></td></tr>" +
  1133. "<tr><td styles='formTableTitle' lable='password'></td>" +
  1134. " <td styles='formTableValue' item='password'></td>" +
  1135. " <td styles='formTableValue'><div item='passwordStrengthArea'></div></div><div item='passwordTip'></div></td></tr>" +
  1136. "<tr><td styles='formTableTitle' lable='confirmPassword'></td>" +
  1137. " <td styles='formTableValue' item='confirmPassword'></td>" +
  1138. " <td styles='formTableValue' item='confirmPasswordTip'></td></tr>" +
  1139. "<tr><td styles='formTableTitle' lable='genderType'></td>" +
  1140. " <td styles='formTableValue' item='genderType'></td>" +
  1141. " <td styles='formTableValue' item='genderTypeTip'></td></tr>" +
  1142. //"<tr><td styles='formTableTitle' lable='mail'></td>" +
  1143. //" <td styles='formTableValue' item='mail'></td>" +
  1144. //" <td styles='formTableValue' item='mailTip'></td></tr>" +
  1145. "<tr><td styles='formTableTitle' lable='mobile'></td>" +
  1146. " <td styles='formTableValue' item='mobile'></td>" +
  1147. " <td styles='formTableValue' item='mobileTip'></td></tr>";
  1148. if (signUpMode === "code") {
  1149. html += "<tr><td styles='formTableTitle' lable='codeAnswer'></td>" +
  1150. " <td styles='formTableValue'><div item='codeAnswer' style='float:left;'></div><div item='verificationAction' style='float:left;'></div><div item='resendVerificationAction' style='float:left;display:none;'></div></td>" +
  1151. " <td styles='formTableValue' item='verificationCodeTip'></td></tr>";
  1152. } else {
  1153. html += "<tr><td styles='formTableTitle' lable='captchaAnswer'></td>" +
  1154. " <td styles='formTableValue'><div item='captchaAnswer' style='float:left;'></div><div item='captchaPic' style='float:left;'></div><div item='changeCaptchaAction' style='float:left;'></div></td>" +
  1155. " <td styles='formTableValue' item='captchaAnswerTip'></td></tr>";
  1156. }
  1157. html += "<tr><td styles='formTableTitle'></td>" +
  1158. " <td styles='formTableValue' item='signUpAction'></td>" +
  1159. " <td styles='formTableValue' item='signUpTip'></td></tr>" +
  1160. "<tr><td></td>" +
  1161. " <td><div item='hasAccountArea'></div><div item='gotoLoginAction'></div></td>" +
  1162. " <td></td></tr>" +
  1163. "</table>";
  1164. this.formTableArea.set("html", html);
  1165. if (signUpMode === "captcha") {
  1166. this.setCaptchaPic();
  1167. }
  1168. //this.createPasswordStrengthNode();
  1169. MWF.xDesktop.requireApp("Template", "MForm", function () {
  1170. this.form = new MForm(this.formTableArea, this.data, {
  1171. style: this.options.popupStyle,
  1172. verifyType: "batchSingle", //batch一起校验,或alert弹出
  1173. isEdited: this.isEdited || this.isNew,
  1174. onPostLoad: function () {
  1175. var form = this.form;
  1176. var table = this.formTableArea;
  1177. form.getItem("name").tipNode = table.getElement("[item='nameTip']");
  1178. form.getItem("password").tipNode = table.getElement("[item='passwordTip']");
  1179. form.getItem("confirmPassword").tipNode = table.getElement("[item='confirmPasswordTip']");
  1180. //form.getItem("mail").tipNode = table.getElement("[item='mailTip']")[0];
  1181. form.getItem("genderType").tipNode = table.getElement("[item='genderTypeTip']");
  1182. form.getItem("mobile").tipNode = table.getElement("[item='mobileTip']");
  1183. this.tipNode = table.getElement("[item='signUpTip']");
  1184. var captchaAnswer = form.getItem("captchaAnswer");
  1185. if (captchaAnswer) {
  1186. form.getItem("captchaAnswer").tipNode = table.getElement("[item='captchaAnswerTip']");
  1187. }
  1188. var codeAnswer = form.getItem("codeAnswer");
  1189. if (codeAnswer) {
  1190. form.getItem("codeAnswer").tipNode = table.getElement("[item='verificationCodeTip']");
  1191. }
  1192. }.bind(this),
  1193. itemTemplate: {
  1194. name: {
  1195. text: this.lp.userName, defaultValue: this.lp.userName, className: "inputUser",
  1196. notEmpty: true, defaultValueAsEmpty: true, emptyTip: this.lp.inputYourUserName,
  1197. validRule: { isInvalid: function (value, it) { return this.checkUserName(value, it); }.bind(this) },
  1198. validMessage: { isInvalid: this.lp.userExist },
  1199. event: {
  1200. focus: function (it) { if (this.lp.userName === it.getValue()) it.setValue(""); if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputActive); }.bind(this),
  1201. keyup: function (it, ev) { if (ev.event.keyCode === 13) { this.ok() } }.bind(this),
  1202. blur: function (it) {
  1203. if (it.verify(true)) {
  1204. if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputUser);
  1205. }
  1206. }.bind(this)
  1207. }, onEmpty: function (it) {
  1208. it.getElements()[0].setStyles(this.css.inputEmpty);
  1209. }.bind(this), onUnempty: function (it) {
  1210. it.getElements()[0].setStyles(this.css.inputUser);
  1211. }.bind(this)
  1212. },
  1213. password: {
  1214. text: this.lp.password, type: "password", className: "inputPassword",
  1215. notEmpty: true, defaultValueAsEmpty: true, emptyTip: this.lp.inputYourPassword,
  1216. validRule: {
  1217. passwordIsWeak: function (value, it) {
  1218. return !this.getPasswordRule(it.getValue());
  1219. }.bind(this)
  1220. },
  1221. validMessage: {
  1222. passwordIsWeak: function () {
  1223. return self.getPasswordRule(this.getValue());
  1224. }
  1225. }, //this.lp.passwordIsSimple
  1226. event: {
  1227. focus: function (it) { if ("password" === it.getValue()) it.setValue(""); if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputActive); }.bind(this),
  1228. //keyup : function(it){ this.pwStrength(it.getValue()) }.bind(this),
  1229. blur: function (it) { it.verify(true) }.bind(this)
  1230. }, onEmpty: function (it) {
  1231. it.getElements()[0].setStyles(this.css.inputEmpty);
  1232. }.bind(this), onUnempty: function (it) {
  1233. it.getElements()[0].setStyles(this.css.inputPassword);
  1234. }.bind(this)
  1235. },
  1236. confirmPassword: {
  1237. text: this.lp.confirmPassword, type: "password", className: "inputComfirmPassword",
  1238. notEmpty: true, defaultValueAsEmpty: true, emptyTip: this.lp.inputComfirmPassword,
  1239. validRule: {
  1240. passwordNotEqual: function (value, it) {
  1241. if (it.getValue() === this.form.getItem("password").getValue()) return true;
  1242. }.bind(this)
  1243. },
  1244. validMessage: { passwordNotEqual: this.lp.passwordNotEqual },
  1245. event: {
  1246. focus: function (it) { if ("password" === it.getValue()) it.setValue(""); if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputActive); }.bind(this),
  1247. keyup: function (it, ev) { if (ev.event.keyCode === 13) { this.ok() } }.bind(this),
  1248. blur: function (it) {
  1249. if (it.verify(true)) {
  1250. if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputComfirmPassword);
  1251. }
  1252. }.bind(this)
  1253. }, onEmpty: function (it) {
  1254. it.getElements()[0].setStyles(this.css.inputEmpty);
  1255. }.bind(this), onUnempty: function (it) {
  1256. it.getElements()[0].setStyles(this.css.inputComfirmPassword);
  1257. }.bind(this)
  1258. },
  1259. mail: {
  1260. text: this.lp.mail, defaultValue: this.lp.inputYourMail, className: "inputMail",
  1261. notEmpty: true, defaultValueAsEmpty: true, emptyTip: this.lp.inputYourMail, validRule: { email: true }, event: {
  1262. focus: function (it) { if (this.lp.inputYourMail === it.getValue()) it.setValue(""); if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputActive); }.bind(this),
  1263. blur: function (it) { it.verify(true); if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputMail); }.bind(this),
  1264. keyup: function (it, ev) { if (ev.event.keyCode === 13) { this.ok() } }.bind(this)
  1265. }, onEmpty: function (it) {
  1266. it.getElements()[0].setStyles(this.css.inputEmpty);
  1267. }.bind(this), onUnempty: function (it) {
  1268. it.getElements()[0].setStyles(this.css.inputMail);
  1269. }.bind(this)
  1270. },
  1271. genderType: {
  1272. text: this.lp.genderType, className: "inputGenderType", type: "select", selectValue: this.lp.genderTypeValue.split(","), selectText: this.lp.genderTypeText.split(","),
  1273. notEmpty: true, emptyTip: this.lp.selectGenderType, event: {
  1274. focus: function (it) { if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputActive); }.bind(this),
  1275. blur: function (it) { it.verify(true); if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputGenderType); }.bind(this),
  1276. keyup: function (it, ev) { if (ev.event.keyCode === 13) { this.ok() } }.bind(this)
  1277. }, onEmpty: function (it) {
  1278. it.getElements()[0].setStyles(this.css.inputEmpty);
  1279. }.bind(this), onUnempty: function (it) {
  1280. it.getElements()[0].setStyles(this.css.inputGenderType);
  1281. }.bind(this)
  1282. },
  1283. mobile: {
  1284. text: this.lp.mobile, defaultValue: this.lp.inputYourMobile, className: "inputMobile", tType: "number",
  1285. notEmpty: true, defaultValueAsEmpty: true, emptyTip: this.lp.inputYourMobile,
  1286. validRule: { isInvalid: function (value, it) { return this.checkMobile(value, it); }.bind(this) },
  1287. validMessage: { isInvalid: this.lp.mobileIsRegisted },
  1288. event: {
  1289. focus: function (it) { if (this.lp.inputYourMobile === it.getValue()) it.setValue(""); if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputActive); }.bind(this),
  1290. keyup: function (it, ev) { if (ev.event.keyCode === 13) { this.ok() } }.bind(this),
  1291. blur: function (it) {
  1292. if (it.verify(true)) {
  1293. if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputMobile);
  1294. }
  1295. }.bind(this)
  1296. }, onEmpty: function (it) {
  1297. it.getElements()[0].setStyles(this.css.inputEmpty);
  1298. }.bind(this), onUnempty: function (it) {
  1299. it.getElements()[0].setStyles(this.css.inputMobile);
  1300. }.bind(this)
  1301. },
  1302. captchaAnswer: {
  1303. tType: "number", text: this.lp.verificationCode, defaultValue: this.lp.verificationCode, className: "inputVerificationCode",
  1304. notEmpty: true, defaultValueAsEmpty: true, emptyTip: this.lp.inputPicVerificationCode, event: {
  1305. focus: function (it) { if (this.lp.verificationCode === it.getValue()) it.setValue(""); if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputActive); }.bind(this),
  1306. blur: function (it) { it.verify(true); if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputVerificationCode); }.bind(this),
  1307. keyup: function (it, ev) { if (ev.event.keyCode === 13) { this.ok() } }.bind(this)
  1308. }, onEmpty: function (it) {
  1309. it.getElements()[0].setStyles(this.css.inputEmpty);
  1310. }.bind(this), onUnempty: function (it) {
  1311. it.getElements()[0].setStyles(this.css.inputVerificationCode);
  1312. }.bind(this)
  1313. },
  1314. changeCaptchaAction: {
  1315. value: this.lp.changeVerification, type: "innerText", className: "verificationChange", event: {
  1316. click: function () {
  1317. this.setCaptchaPic();
  1318. }.bind(this)
  1319. }
  1320. },
  1321. codeAnswer: {
  1322. text: this.lp.verificationCode, defaultValue: this.lp.inputVerificationCode, className: "inputVerificationCode2",
  1323. notEmpty: true, defaultValueAsEmpty: true, emptyTip: this.lp.inputVerificationCode, event: {
  1324. focus: function (it) { if (this.lp.inputVerificationCode === it.getValue()) it.setValue(""); if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputActive); }.bind(this),
  1325. blur: function (it) { it.verify(true); if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputVerificationCode2); }.bind(this),
  1326. keyup: function (it, ev) { if (ev.event.keyCode === 13) { this.ok() } }.bind(this)
  1327. }, onEmpty: function (it) {
  1328. it.getElements()[0].setStyles(this.css.inputEmpty);
  1329. }.bind(this), onUnempty: function (it) {
  1330. it.getElements()[0].setStyles(this.css.inputVerificationCode2);
  1331. }.bind(this)
  1332. },
  1333. verificationAction: {
  1334. value: this.lp.sendVerification, type: "button", className: "inputSendVerification", event: {
  1335. click: function () { this.sendVerificationAction() }.bind(this)
  1336. }
  1337. },
  1338. resendVerificationAction: { value: this.lp.resendVerification, type: "button", className: "inputResendVerification" },
  1339. signUpAction: {
  1340. value: this.lp.signUp, type: "button", className: "inputSignUp", event: {
  1341. click: function () { this.ok() }.bind(this)
  1342. }
  1343. },
  1344. hasAccountArea: { value: this.lp.hasAccount, type: "innerText", className: "hasCountArea" },
  1345. gotoLoginAction: {
  1346. value: this.lp.gotoLogin, type: "innerText", className: "gotoLoginAction", event: {
  1347. click: function () { this.gotoLogin() }.bind(this)
  1348. }
  1349. }
  1350. }
  1351. }, this.app, this.css);
  1352. this.form.load();
  1353. }.bind(this), true);
  1354. },
  1355. checkMobile: function (mobile, it) {
  1356. var flag = true;
  1357. this.actions.checkRegisterMobile(mobile, function () {
  1358. flag = true
  1359. }.bind(this), function (errorObj) {
  1360. if (errorObj.status === 404) {
  1361. it.options.validMessage.isInvalid = this.lp.pageNotFound;
  1362. flag = false;
  1363. } else {
  1364. var error = JSON.parse(errorObj.responseText);
  1365. it.options.validMessage.isInvalid = error.message;
  1366. flag = false;
  1367. }
  1368. }.bind(this), false);
  1369. return flag;
  1370. },
  1371. checkUserName: function (userName, it) {
  1372. var flag = true;
  1373. this.actions.checkRegisterName(userName, function () {
  1374. flag = true
  1375. }.bind(this), function (errorObj) {
  1376. if (errorObj.status === 404) {
  1377. it.options.validMessage.isInvalid = this.lp.pageNotFound;
  1378. flag = false
  1379. } else {
  1380. var error = JSON.parse(errorObj.responseText);
  1381. it.options.validMessage.isInvalid = error.message;
  1382. flag = false
  1383. }
  1384. }.bind(this), false);
  1385. return flag;
  1386. },
  1387. setCaptchaPic: function () {
  1388. var captchaPic = this.formTableArea.getElement("[item='captchaPic']");
  1389. captchaPic.empty();
  1390. this.actions.getRegisterCaptcha(120, 50, function (json) {
  1391. this.captcha = json.data.id;
  1392. new Element("img", {
  1393. src: "data:image/png;base64," + json.data.image,
  1394. styles: this.css.verificationImage
  1395. }).inject(captchaPic);
  1396. }.bind(this))
  1397. },
  1398. sendVerificationAction: function () {
  1399. var flag = true;
  1400. var it = this.form.getItem("mobile");
  1401. if (it.verify(true)) {
  1402. it.clearWarning();
  1403. it.getElements()[0].setStyles(this.css.inputMobile);
  1404. } else {
  1405. return;
  1406. }
  1407. this.actions.createRegisterCode(it.getValue(), function (json) {
  1408. }, function (errorObj) {
  1409. var codeIt = this.form.getItem("codeAnswer");
  1410. var error = JSON.parse(errorObj.responseText);
  1411. if (errorObj.status === 404) {
  1412. codeIt.setWarning(error.message, this.lp.pageNotFound);
  1413. flag = false;
  1414. } else {
  1415. codeIt.setWarning(error.message, "invalid");
  1416. flag = false;
  1417. }
  1418. }.bind(this), false);
  1419. if (!flag) return false;
  1420. this.form.getItem("verificationAction").container.setStyle("display", "none");
  1421. this.setResendVerification();
  1422. },
  1423. setResendVerification: function () {
  1424. var resendItem = this.form.getItem("resendVerificationAction");
  1425. resendItem.container.setStyle("display", "");
  1426. this.resendElement = resendItem.getElements()[0];
  1427. this.resendElement.set("text", this.lp.resendVerification + "(60)");
  1428. var i = 60;
  1429. this.timer = setInterval(function () {
  1430. if (i > 0) {
  1431. this.resendElement.set("text", this.lp.resendVerification + "(" + --i + ")")
  1432. } else {
  1433. this.form.getItem("verificationAction").container.setStyle("display", "");
  1434. resendItem.container.setStyle("display", "none");
  1435. clearInterval(this.timer)
  1436. }
  1437. }.bind(this), 1000)
  1438. },
  1439. getPasswordRule: function (password) {
  1440. var str = "";
  1441. this.actions.checkRegisterPassword(password, function (json) {
  1442. str = json.data.value || "";
  1443. }.bind(this), null, false);
  1444. return str;
  1445. },
  1446. //createPasswordStrengthNode : function(){
  1447. // var passwordStrengthArea = this.formTableArea.getElement("[item='passwordStrengthArea']");
  1448. //
  1449. // var lowNode = new Element( "div", {styles : this.css.passwordStrengthNode }).inject( passwordStrengthArea );
  1450. // this.lowColorNode = new Element( "div", {styles : this.css.passwordStrengthColor }).inject( lowNode );
  1451. // this.lowTextNode = new Element( "div", {styles : this.css.passwordStrengthText, text : this.lp.weak }).inject( lowNode );
  1452. //
  1453. // var middleNode = new Element( "div" , {styles : this.css.passwordStrengthNode }).inject( passwordStrengthArea );
  1454. // this.middleColorNode = new Element( "div", {styles : this.css.passwordStrengthColor }).inject( middleNode );
  1455. // this.middleTextNode = new Element( "div", {styles : this.css.passwordStrengthText, text : this.lp.middle }).inject( middleNode );
  1456. //
  1457. // var highNode = new Element("div", {styles : this.css.passwordStrengthNode }).inject( passwordStrengthArea );
  1458. // this.highColorNode = new Element( "div", {styles : this.css.passwordStrengthColor }).inject( highNode );
  1459. // this.highTextNode = new Element( "div", {styles : this.css.passwordStrengthText, text : this.lp.high }).inject( highNode );
  1460. //},
  1461. //getPasswordLevel: function( password ){
  1462. // // Level(级别)
  1463. // // •0-3 : [easy]
  1464. // // •4-6 : [midium]
  1465. // // •7-9 : [strong]
  1466. // // •10-12 : [very strong]
  1467. // // •>12 : [extremely strong]
  1468. // var level = 0;
  1469. // this.actions.checkRegisterPassword( password, function( json ){
  1470. // level = json.data.value;
  1471. // }.bind(this), null, false );
  1472. // return level;
  1473. //},
  1474. //pwStrength: function(pwd){
  1475. // this.lowColorNode.setStyles( this.css.passwordStrengthColor );
  1476. // this.lowTextNode.setStyles( this.css.passwordStrengthText );
  1477. // this.middleColorNode.setStyles( this.css.passwordStrengthColor );
  1478. // this.middleTextNode.setStyles( this.css.passwordStrengthText );
  1479. // this.highColorNode.setStyles( this.css.passwordStrengthColor );
  1480. // this.highTextNode.setStyles( this.css.passwordStrengthText );
  1481. // if (!pwd){
  1482. // }else{
  1483. // //var level = this.checkStrong(pwd);
  1484. // var level = this.getPasswordLevel(pwd);
  1485. // switch(level) {
  1486. // case 0:
  1487. // case 1:
  1488. // case 2:
  1489. // case 3:
  1490. // this.lowColorNode.setStyles( this.css.passwordStrengthColor_low );
  1491. // this.lowTextNode.setStyles( this.css.passwordStrengthText_current );
  1492. // break;
  1493. // case 4:
  1494. // case 5:
  1495. // case 6:
  1496. // this.middleColorNode.setStyles( this.css.passwordStrengthColor_middle );
  1497. // this.middleTextNode.setStyles( this.css.passwordStrengthText_current );
  1498. // break;
  1499. // default:
  1500. // this.highColorNode.setStyles( this.css.passwordStrengthColor_high );
  1501. // this.highTextNode.setStyles( this.css.passwordStrengthText_current );
  1502. // }
  1503. // }
  1504. //},
  1505. gotoLogin: function () {
  1506. this.explorer.openLoginForm({}, function () { window.location.reload(); });
  1507. this.close();
  1508. },
  1509. setWarning: function (text) {
  1510. this.tipNode.empty();
  1511. new Element("div", {
  1512. "text": text,
  1513. "styles": this.css.warningMessageNode
  1514. }).inject(this.tipNode);
  1515. },
  1516. setNotice: function (text) {
  1517. this.tipNode.empty();
  1518. new Element("div", {
  1519. "text": text,
  1520. "styles": this.css.noticeMessageNode
  1521. }).inject(this.tipNode);
  1522. },
  1523. ok: function () {
  1524. this.tipNode.empty();
  1525. this.fireEvent("queryOk");
  1526. var data = this.form.getResult(true, ",", true, false, true);
  1527. if (data) {
  1528. this._ok(data, function (json) {
  1529. if (json.type === "error") {
  1530. if (this.app) this.app.notice(json.message, "error");
  1531. } else {
  1532. if (this.formMaskNode) this.formMaskNode.destroy();
  1533. this.formAreaNode.destroy();
  1534. this.setNotice(this.lp.registeSuccess);
  1535. if (this.app) this.app.notice(this.lp.registeSuccess, "success");
  1536. this.fireEvent("postOk", json);
  1537. this.gotoLogin();
  1538. }
  1539. }.bind(this))
  1540. }
  1541. },
  1542. _ok: function (data, callback) {
  1543. data.captcha = this.captcha;
  1544. this.actions.register(data, function (json) {
  1545. if (callback) callback(json);
  1546. }.bind(this), function (errorObj) {
  1547. if (errorObj.status === 404) {
  1548. this.setWarning(this.lp.pageNotFound);
  1549. } else {
  1550. var error = JSON.parse(errorObj.responseText);
  1551. this.setWarning(error.message);
  1552. }
  1553. }.bind(this));
  1554. }
  1555. });
  1556. //忘记密码
  1557. MWF.xDesktop.Authentication.ResetPasswordForm = new Class({
  1558. Extends: MPopupForm,
  1559. Implements: [Options, Events],
  1560. options: {
  1561. "style": "default",
  1562. "popupStyle": "o2platformSignup",
  1563. "width": "710",
  1564. "height": "450",
  1565. "hasTop": true,
  1566. "hasIcon": false,
  1567. "hasTopIcon": true,
  1568. "hasTopContent": true,
  1569. "hasBottom": false,
  1570. "title": MWF.LP.authentication.ResetPasswordFormTitle,
  1571. "draggable": true,
  1572. "closeAction": true
  1573. },
  1574. _createTopContent: function () {
  1575. this.actions = MWF.Actions.get("x_organization_assemble_personal");
  1576. this.actions.getRegisterMode(function (json) {
  1577. this.signUpMode = json.data.value;
  1578. }.bind(this), null, false);
  1579. if (this.signUpMode && this.signUpMode !== "disable") {
  1580. this.gotoSignupNode = new Element("div", {
  1581. styles: this.css.formTopContentCustomNode,
  1582. text: this.lp.signUp
  1583. }).inject(this.formTopContentNode);
  1584. this.gotoSignupNode.addEvent("click", function () { this.gotoSignup() }.bind(this));
  1585. new Element("div", { styles: this.css.formTopContentSepNode }).inject(this.formTopContentNode);
  1586. }
  1587. this.gotoLoginNode = new Element("div", {
  1588. styles: this.css.formTopContentCustomNode,
  1589. text: this.lp.loginAction
  1590. }).inject(this.formTopContentNode);
  1591. this.gotoLoginNode.addEvent("click", function () { this.gotoLogin() }.bind(this));
  1592. },
  1593. _createTableContent: function () {
  1594. this.formTableContainer.setStyles(this.css.formTableContainer2);
  1595. this.loadSteps();
  1596. this.loadStepForm_1();
  1597. this.loadStepForm_2();
  1598. this.loadStepForm_3();
  1599. },
  1600. reset: function () {
  1601. this.formTableArea.empty();
  1602. this._createTableContent();
  1603. },
  1604. loadSteps: function () {
  1605. var stepsContainer = new Element("div", { styles: this.css.stepsContainer }).inject(this.formTableArea);
  1606. this.step_1 = new Element("div", {
  1607. styles: this.css.step_1_active,
  1608. text: this.lp.shotMessageCheck
  1609. }).inject(stepsContainer);
  1610. this.stepLink_1 = new Element("div", { styles: this.css.stepLink_1 }).inject(this.step_1);
  1611. this.step_2 = new Element("div", {
  1612. styles: this.css.step_2,
  1613. text: this.lp.setMewPassword
  1614. }).inject(stepsContainer);
  1615. this.stepLink_2 = new Element("div", { styles: this.css.stepLink_2 }).inject(this.step_2);
  1616. this.step_3 = new Element("div", {
  1617. styles: this.css.step_3,
  1618. text: this.lp.completed
  1619. }).inject(stepsContainer);
  1620. },
  1621. loadStepForm_1: function () {
  1622. var html = "<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>" +
  1623. "<tr><td styles='formTableTitle' lable='name' width='80'></td>" +
  1624. " <td styles='formTableValue' item='name' width='350'></td></tr>" +
  1625. "<tr><td styles='formTableTitle' lable='codeAnswer'></td>" +
  1626. " <td styles='formTableValue'>" +
  1627. " <div item='codeAnswer' style='float:left;'></div>" +
  1628. " <div item='verificationAction' style='float:left;'></div>" +
  1629. " <div item='resendVerificationAction' style='float:left;display:none;'></div></td>" +
  1630. " </tr>" +
  1631. "<tr><td styles='formTableTitle'></td>" +
  1632. " <td styles='formTableValue' item='nextStep'></td></tr>" +
  1633. "</table>";
  1634. this.stepNode_1 = new Element("div", { html: html, styles: { display: "" } }).inject(this.formTableArea);
  1635. MWF.xDesktop.requireApp("Template", "MForm", function () {
  1636. this.stepForm_1 = new MForm(this.stepNode_1, {}, {
  1637. style: this.options.popupStyle,
  1638. verifyType: "single", //batch一起校验,或alert弹出
  1639. isEdited: this.isEdited || this.isNew,
  1640. itemTemplate: {
  1641. name: {
  1642. text: this.lp.userName, defaultValue: this.lp.userName, className: "inputUser",
  1643. notEmpty: true, defaultValueAsEmpty: true, emptyTip: this.lp.inputYourUserName,
  1644. validRule: { isInvalid: function (value, it) { return this.checkUserName(value, it); }.bind(this) },
  1645. validMessage: { isInvalid: this.lp.userNotExist },
  1646. event: {
  1647. focus: function (it) { if (this.lp.userName === it.getValue()) it.setValue(""); if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputActive); }.bind(this),
  1648. blur: function (it) { if (it.getValue() === "") it.setValue(this.lp.userName); if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputUser); }.bind(this),
  1649. keyup: function (it, ev) { if (ev.event.keyCode === 13) { this.gotoStep(2) } }.bind(this)
  1650. }, onEmpty: function (it) {
  1651. it.getElements()[0].setStyles(this.css.inputEmpty);
  1652. }.bind(this), onUnempty: function (it) {
  1653. it.getElements()[0].setStyles(this.css.inputUser);
  1654. }.bind(this)
  1655. },
  1656. codeAnswer: {
  1657. text: this.lp.verificationCode, defaultValue: this.lp.inputVerificationCode, className: "inputVerificationCode2",
  1658. notEmpty: true, defaultValueAsEmpty: true, emptyTip: this.lp.inputVerificationCode, event: {
  1659. focus: function (it) { if (this.lp.inputVerificationCode === it.getValue()) it.setValue(""); if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputActive); }.bind(this),
  1660. blur: function (it) {
  1661. if (it.getValue() === "") it.setValue(this.lp.inputVerificationCode);
  1662. if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputVerificationCode2);
  1663. }.bind(this),
  1664. keyup: function (it, ev) { if (ev.event.keyCode === 13) { this.gotoStep(2) } }.bind(this)
  1665. }, onEmpty: function (it) {
  1666. it.getElements()[0].setStyles(this.css.inputEmpty);
  1667. }.bind(this), onUnempty: function (it) {
  1668. it.getElements()[0].setStyles(this.css.inputVerificationCode2);
  1669. }.bind(this)
  1670. },
  1671. verificationAction: {
  1672. value: this.lp.sendVerification, type: "button", className: "inputSendVerification", event: {
  1673. click: function () { this.sendVerificationAction() }.bind(this)
  1674. }
  1675. },
  1676. resendVerificationAction: { value: this.lp.resendVerification, type: "button", className: "inputResendVerification" },
  1677. nextStep: {
  1678. value: this.lp.nextStep, type: "button", className: "inputSignUp", event: {
  1679. click: function () { this.gotoStep(2) }.bind(this)
  1680. }
  1681. }
  1682. }
  1683. }, this.app, this.css);
  1684. this.stepForm_1.load();
  1685. }.bind(this), true);
  1686. },
  1687. loadStepForm_2: function () {
  1688. var self = this;
  1689. html = "<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>" +
  1690. "<tr><td styles='formTableTitle' lable='password' width='80'></td>" +
  1691. " <td styles='formTableValue' item='password' width='350'></td>" +
  1692. " <td styles='formTableValue'><div item='passwordStrengthArea'></div></td></tr>" +
  1693. "<tr><td styles='formTableTitle' lable='confirmPassword'></td>" +
  1694. " <td styles='formTableValue' item='confirmPassword'></td>" +
  1695. " <td styles='formTableValue'></td></tr>" +
  1696. "<tr><td styles='formTableTitle'></td>" +
  1697. " <td styles='formTableValue' item='nextStep'></td>" +
  1698. " <td styles='formTableValue'></td></tr>" +
  1699. "</table>";
  1700. this.stepNode_2 = new Element("div", {
  1701. html: html,
  1702. styles: { "display": "none" }
  1703. }).inject(this.formTableArea);
  1704. MWF.xDesktop.requireApp("Template", "MForm", function () {
  1705. this.stepForm_2 = new MForm(this.stepNode_2, {}, {
  1706. style: this.options.popupStyle,
  1707. verifyType: "single", //batch一起校验,或alert弹出
  1708. isEdited: this.isEdited || this.isNew,
  1709. itemTemplate: {
  1710. password: {
  1711. text: this.lp.setNewPassword, type: "password", className: "inputPassword",
  1712. notEmpty: true, defaultValueAsEmpty: true, emptyTip: this.lp.inputYourPassword,
  1713. attr: { "placeholder": this.lp.inputYourPassword },
  1714. validRule: {
  1715. passwordIsWeak: function (value, it) {
  1716. return !this.getPasswordRule(it.getValue());
  1717. }.bind(this)
  1718. },
  1719. validMessage: {
  1720. passwordIsWeak: function () {
  1721. return self.getPasswordRule(this.getValue());
  1722. }
  1723. },
  1724. event: {
  1725. focus: function (it) { if ("password" === it.getValue()) it.setValue(""); if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputActive); }.bind(this),
  1726. blur: function (it) { it.verify(true); }.bind(this)
  1727. //if( !it.warningStatus )it.getElements()[0].setStyles( this.css.inputPassword );
  1728. //keyup : function(it){ this.pwStrength(it.getValue()) }.bind(this)
  1729. }, onEmpty: function (it) {
  1730. it.getElements()[0].setStyles(this.css.inputEmpty);
  1731. }.bind(this), onUnempty: function (it) {
  1732. it.getElements()[0].setStyles(this.css.inputPassword);
  1733. }.bind(this)
  1734. },
  1735. confirmPassword: {
  1736. text: this.lp.confirmNewPassword, type: "password", className: "inputComfirmPassword",
  1737. notEmpty: true, defaultValueAsEmpty: true, emptyTip: this.lp.inputComfirmPassword,
  1738. attr: { "placeholder": this.lp.inputComfirmPassword },
  1739. validRule: {
  1740. passwordNotEqual: function (value, it) {
  1741. if (it.getValue() === this.stepForm_2.getItem("password").getValue()) return true;
  1742. }.bind(this)
  1743. },
  1744. validMessage: { passwordNotEqual: this.lp.passwordNotEqual },
  1745. event: {
  1746. focus: function (it) { if ("password" === it.getValue()) it.setValue(""); if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputActive); }.bind(this),
  1747. blur: function (it) { if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputComfirmPassword); }.bind(this),
  1748. keyup: function (it, ev) { if (ev.event.keyCode === 13) { this.gotoStep(3) } }.bind(this)
  1749. }, onEmpty: function (it) {
  1750. it.getElements()[0].setStyles(this.css.inputEmpty);
  1751. }.bind(this), onUnempty: function (it) {
  1752. it.getElements()[0].setStyles(this.css.inputComfirmPassword);
  1753. }.bind(this)
  1754. },
  1755. nextStep: {
  1756. value: this.lp.nextStep, type: "button", className: "inputSignUp", event: {
  1757. click: function () { this.gotoStep(3) }.bind(this)
  1758. }
  1759. }
  1760. }
  1761. }, this.app, this.css);
  1762. this.stepForm_2.load();
  1763. }.bind(this), true);
  1764. //this.createPasswordStrengthNode();
  1765. },
  1766. loadStepForm_3: function () {
  1767. this.stepNode_3 = new Element("div", {
  1768. styles: this.css.stepFormResult
  1769. }).inject(this.formTableArea);
  1770. },
  1771. createSetForm_3: function (isSuccess, text) {
  1772. var area = null;
  1773. var action = null;
  1774. if (isSuccess) {
  1775. this.stepNode_3.setStyles(this.css.stepFormResult);
  1776. this.stepNode_3.setStyle("display", "");
  1777. new Element("div", {
  1778. styles: this.css.resetPasswordSuccess,
  1779. text: this.lp.resetPasswordSuccess
  1780. }).inject(this.stepNode_3);
  1781. area = new Element("div", {
  1782. styles: this.css.resetPasswordResultArea
  1783. }).inject(this.stepNode_3);
  1784. new Element("div", {
  1785. styles: this.css.resetPasswordResultWord,
  1786. text: this.lp.resetPasswordSuccessWord
  1787. }).inject(area);
  1788. action = new Element("div", {
  1789. styles: this.css.resetPasswordResultAction,
  1790. text: this.lp.gotoLogin
  1791. }).inject(area);
  1792. action.addEvent("click", function () { this.gotoLogin() }.bind(this));
  1793. } else {
  1794. this.stepNode_3.setStyles(this.css.stepFormResult_fail);
  1795. this.stepNode_3.setStyle("display", "");
  1796. new Element("div", {
  1797. styles: this.css.resetPasswordFail,
  1798. text: text + this.lp.resetPasswordFail
  1799. }).inject(this.stepNode_3);
  1800. area = new Element("div", {
  1801. styles: this.css.resetPasswordResultArea
  1802. }).inject(this.stepNode_3);
  1803. new Element("div", {
  1804. styles: this.css.resetPasswordResultWord,
  1805. text: this.lp.resetPasswordFailWord
  1806. }).inject(area);
  1807. action = new Element("div", {
  1808. styles: this.css.resetPasswordResultAction,
  1809. text: this.lp.backtoModify
  1810. }).inject(area);
  1811. action.addEvent("click", function () { this.reset() }.bind(this));
  1812. }
  1813. },
  1814. gotoStep: function (step) {
  1815. var form = this["stepForm_" + (step - 1)];
  1816. form.clearWarning();
  1817. var data = form.getResult(true, ",", true, false, true);
  1818. if (!data) {
  1819. return;
  1820. }
  1821. var i;
  1822. for (i = 1; i <= step; i++) {
  1823. this["step_" + i].setStyles(this.css["step_" + i + "_active"]);
  1824. if (i !== step && this["stepLink_" + i]) {
  1825. this["stepLink_" + i].setStyles(this.css["stepLink_" + i + "_active"]);
  1826. }
  1827. }
  1828. for (i = step + 1; i <= 3; i++) {
  1829. this["step_" + i].setStyles(this.css["step_" + i]);
  1830. if (i !== 3) {
  1831. this["stepLink_" + i].setStyles(this.css["stepLink_" + i]);
  1832. }
  1833. }
  1834. for (i = 1; i <= 3; i++) {
  1835. if (i === step) {
  1836. this["stepNode_" + i].setStyle("display", "");
  1837. } else {
  1838. this["stepNode_" + i].setStyle("display", "none");
  1839. }
  1840. }
  1841. if (step === 3) {
  1842. var d = {
  1843. credential: this.stepForm_1.getItem("name").getValue(),
  1844. codeAnswer: this.stepForm_1.getItem("codeAnswer").getValue(),
  1845. password: this.stepForm_2.getItem("password").getValue()
  1846. };
  1847. this.actions.resetPassword(d, function () {
  1848. this.createSetForm_3(true)
  1849. }.bind(this), function (errorObj) {
  1850. var error = JSON.parse(errorObj.responseText);
  1851. //this.app.notice( error.message );
  1852. this.createSetForm_3(false, error.message)
  1853. }.bind(this), false);
  1854. }
  1855. },
  1856. checkMobile: function (mobile) {
  1857. var flag = true;
  1858. this.actions.checkRegisterMobile(mobile, function () {
  1859. flag = true
  1860. }.bind(this), function () {
  1861. flag = false;
  1862. }.bind(this), false);
  1863. return flag;
  1864. },
  1865. checkUserName: function (userName, it) {
  1866. var flag = false;
  1867. this.actions.checkCredentialOnResetPassword(userName, function (json) {
  1868. if (json.data) {
  1869. flag = json.data.value;
  1870. }
  1871. }.bind(this), function (errorObj) {
  1872. if (errorObj.status === 404) {
  1873. it.options.validMessage.isInvalid = this.lp.pageNotFound;
  1874. flag = false
  1875. } else {
  1876. var error = JSON.parse(errorObj.responseText);
  1877. it.options.validMessage.isInvalid = error.message;
  1878. flag = false
  1879. }
  1880. }.bind(this), false);
  1881. return flag;
  1882. },
  1883. sendVerificationAction: function () {
  1884. var flag = true;
  1885. var it = this.stepForm_1.getItem("name");
  1886. this.stepForm_1.clearWarning();
  1887. if (it.verify(true)) {
  1888. } else {
  1889. return;
  1890. }
  1891. this.actions.createCodeOnResetPassword(it.getValue(), function (json) {
  1892. }, function (errorObj) {
  1893. var error = JSON.parse(errorObj.responseText);
  1894. it.setWarning(error.message, "invalid");
  1895. flag = false
  1896. }.bind(this), false);
  1897. if (!flag) return false;
  1898. this.stepForm_1.getItem("verificationAction").container.setStyle("display", "none");
  1899. this.setResendVerification();
  1900. },
  1901. setResendVerification: function () {
  1902. var resendItem = this.stepForm_1.getItem("resendVerificationAction");
  1903. resendItem.container.setStyle("display", "");
  1904. this.resendElement = resendItem.getElements()[0];
  1905. this.resendElement.set("text", this.lp.resendVerification + "(60)");
  1906. var i = 60;
  1907. this.timer = setInterval(function () {
  1908. if (i > 0) {
  1909. this.resendElement.set("text", this.lp.resendVerification + "(" + --i + ")")
  1910. } else {
  1911. this.stepForm_1.getItem("verificationAction").container.setStyle("display", "");
  1912. resendItem.container.setStyle("display", "none");
  1913. clearInterval(this.timer)
  1914. }
  1915. }.bind(this), 1000)
  1916. },
  1917. getPasswordRule: function (password) {
  1918. var str = "";
  1919. this.actions.checkRegisterPassword(password, function (json) {
  1920. str = json.data.value || "";
  1921. }.bind(this), null, false);
  1922. return str;
  1923. },
  1924. //createPasswordStrengthNode : function(){
  1925. // var passwordStrengthArea = this.formTableArea.getElement("[item='passwordStrengthArea']");
  1926. //
  1927. // var lowNode = new Element( "div", {styles : this.css.passwordStrengthNode }).inject( passwordStrengthArea );
  1928. // this.lowColorNode = new Element( "div", {styles : this.css.passwordStrengthColor }).inject( lowNode );
  1929. // this.lowTextNode = new Element( "div", {styles : this.css.passwordStrengthText, text : this.lp.weak }).inject( lowNode );
  1930. //
  1931. // var middleNode = new Element( "div" , {styles : this.css.passwordStrengthNode }).inject( passwordStrengthArea );
  1932. // this.middleColorNode = new Element( "div", {styles : this.css.passwordStrengthColor }).inject( middleNode );
  1933. // this.middleTextNode = new Element( "div", {styles : this.css.passwordStrengthText, text : this.lp.middle }).inject( middleNode );
  1934. //
  1935. // var highNode = new Element("div", {styles : this.css.passwordStrengthNode }).inject( passwordStrengthArea );
  1936. // this.highColorNode = new Element( "div", {styles : this.css.passwordStrengthColor }).inject( highNode );
  1937. // this.highTextNode = new Element( "div", {styles : this.css.passwordStrengthText, text : this.lp.high }).inject( highNode );
  1938. //},
  1939. //getPasswordLevel: function( password ){
  1940. // /*Level(级别)
  1941. // •0-3 : [easy]
  1942. // •4-6 : [midium]
  1943. // •7-9 : [strong]
  1944. // •10-12 : [very strong]
  1945. // •>12 : [extremely strong]
  1946. // */
  1947. // var level = 0;
  1948. // this.actions.checkRegisterPassword( password, function( json ){
  1949. // level = json.data.value;
  1950. // }.bind(this), null, false );
  1951. // return level;
  1952. //},
  1953. //pwStrength: function(pwd){
  1954. // this.lowColorNode.setStyles( this.css.passwordStrengthColor );
  1955. // this.lowTextNode.setStyles( this.css.passwordStrengthText );
  1956. // this.middleColorNode.setStyles( this.css.passwordStrengthColor );
  1957. // this.middleTextNode.setStyles( this.css.passwordStrengthText );
  1958. // this.highColorNode.setStyles( this.css.passwordStrengthColor );
  1959. // this.highTextNode.setStyles( this.css.passwordStrengthText );
  1960. // if (!pwd){
  1961. // }else{
  1962. // //var level = this.checkStrong(pwd);
  1963. // var level = this.getPasswordLevel(pwd);
  1964. // switch(level) {
  1965. // case 0:
  1966. // case 1:
  1967. // case 2:
  1968. // case 3:
  1969. // this.lowColorNode.setStyles( this.css.passwordStrengthColor_low );
  1970. // this.lowTextNode.setStyles( this.css.passwordStrengthText_current );
  1971. // break;
  1972. // case 4:
  1973. // case 5:
  1974. // case 6:
  1975. // this.middleColorNode.setStyles( this.css.passwordStrengthColor_middle );
  1976. // this.middleTextNode.setStyles( this.css.passwordStrengthText_current );
  1977. // break;
  1978. // default:
  1979. // this.highColorNode.setStyles( this.css.passwordStrengthColor_high );
  1980. // this.highTextNode.setStyles( this.css.passwordStrengthText_current );
  1981. // }
  1982. // }
  1983. //},
  1984. gotoLogin: function () {
  1985. this.explorer.openLoginForm({}, function () { window.location.reload(); });
  1986. this.close();
  1987. },
  1988. gotoSignup: function () {
  1989. this.explorer.openSignUpForm();
  1990. this.close();
  1991. }
  1992. });
  1993. //密码过期
  1994. MWF.xDesktop.Authentication.ChangePasswordForm = new Class({
  1995. Extends: MPopupForm,
  1996. Implements: [Options, Events],
  1997. options: {
  1998. "style": "default",
  1999. "popupStyle": "o2platform",
  2000. "width": "650",
  2001. "height": "480",
  2002. "hasTop": true,
  2003. "hasIcon": false,
  2004. "hasTopIcon": true,
  2005. "hasTopContent": true,
  2006. "hasBottom": false,
  2007. "hasScroll": false,
  2008. "hasMark": false,
  2009. "title": MWF.LP.authentication.ChangePasswordFormTitle,
  2010. "draggable": true,
  2011. "closeAction": true,
  2012. "userName" : ""
  2013. },
  2014. _createTableContent: function () {
  2015. var self = this;
  2016. this.actions = MWF.Actions.get("x_organization_assemble_personal");
  2017. var html = "<table width='100%' bordr='0' cellpadding='0' cellspacing='0' styles='formTable'>" +
  2018. "<tr><td styles='formTableValueTop20' item='password'></td></tr>" +
  2019. "<tr><td styles='formTableValueTop20' item='newPassword'></td>" +
  2020. "<tr><td styles='formTableValue'><div item='passwordTip'></div></td></tr>" +
  2021. "<tr><td styles='formTableValueTop20' item='confirmPassword'></td>" +
  2022. "<tr><td styles='formTableValueTop20' item='submitAction'></td></tr>" +
  2023. "<tr><td><div item='forgetPassword'></div><div item='gotoLoginAction'></div></td></tr>"+
  2024. "<tr><td styles='formTableValue' item='errorArea'></td></tr>" +
  2025. "</table>";
  2026. this.formTableArea.set("html", html);
  2027. this.errorArea = this.formTableArea.getElement("[item=errorArea]");
  2028. MWF.xDesktop.requireApp("Template", "MForm", function () {
  2029. this.form = new MForm(this.formTableArea, this.data, {
  2030. style: this.options.popupStyle,
  2031. verifyType: "single", //batch一起校验,或alert弹出
  2032. isEdited: this.isEdited || this.isNew,
  2033. onPostLoad: function () {
  2034. var form = this.form;
  2035. form.getItem("password").tipNode = this.errorArea;
  2036. form.getItem("newPassword").tipNode = this.errorArea;
  2037. form.getItem("confirmPassword").tipNode = this.errorArea;
  2038. }.bind(this),
  2039. itemTemplate: {
  2040. password: {
  2041. text: this.lp.oldPassword,
  2042. type: "password",
  2043. className: "inputPassword",
  2044. notEmpty: true,
  2045. defaultValueAsEmpty: true,
  2046. emptyTip: this.lp.inputYourOldPassword,
  2047. attr: {"placeholder": this.lp.oldPassword},
  2048. event: {
  2049. focus: function (it) {
  2050. if ("password" === it.getValue()) it.setValue("");
  2051. if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputActive);
  2052. }.bind(this),
  2053. blur: function (it) {
  2054. // it.verify(true);
  2055. if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputPassword);
  2056. }.bind(this),
  2057. keyup: function (it, ev) {
  2058. if (ev.event.keyCode === 13) this.ok();
  2059. }.bind(this)
  2060. },
  2061. onEmpty: function (it) {
  2062. it.getElements()[0].setStyles(this.css.inputEmpty);
  2063. }.bind(this),
  2064. onUnempty: function (it) {
  2065. it.getElements()[0].setStyles(this.css.inputPassword);
  2066. }.bind(this)
  2067. },
  2068. newPassword: {
  2069. text: this.lp.newPassword,
  2070. type: "password",
  2071. className: "inputPassword",
  2072. notEmpty: true,
  2073. defaultValueAsEmpty: true,
  2074. emptyTip: this.lp.inputYourNewPassword,
  2075. attr: {"placeholder": this.lp.newPassword},
  2076. validRule: {
  2077. passwordIsWeak: function (value, it) {
  2078. return !this.getPasswordRule(it.getValue());
  2079. }.bind(this)
  2080. },
  2081. validMessage: {
  2082. passwordIsWeak: function () {
  2083. return self.getPasswordRule(this.getValue());
  2084. }
  2085. },
  2086. event: {
  2087. focus: function (it) {
  2088. if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputActive);
  2089. }.bind(this),
  2090. blur: function (it) {
  2091. // it.verify(true);
  2092. }.bind(this),
  2093. keyup: function (it, ev) {
  2094. if (ev.event.keyCode === 13)this.ok();
  2095. }.bind(this)
  2096. },
  2097. onEmpty: function (it) {
  2098. it.getElements()[0].setStyles(this.css.inputEmpty);
  2099. }.bind(this),
  2100. onUnempty: function (it) {
  2101. it.getElements()[0].setStyles(this.css.inputPassword);
  2102. }.bind(this)
  2103. },
  2104. confirmPassword: {
  2105. text: this.lp.confirmNewPassword,
  2106. type: "password",
  2107. className: "inputComfirmPassword",
  2108. notEmpty: true,
  2109. defaultValueAsEmpty: true,
  2110. emptyTip: this.lp.inputComfirmPassword,
  2111. attr: {"placeholder": this.lp.confirmPassword},
  2112. validRule: {
  2113. passwordNotEqual: function (value, it) {
  2114. if (it.getValue() === this.form.getItem("newPassword").getValue()) return true;
  2115. }.bind(this)
  2116. },
  2117. validMessage: {passwordNotEqual: this.lp.passwordNotEqual},
  2118. event: {
  2119. focus: function (it) {
  2120. if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputActive);
  2121. }.bind(this),
  2122. blur: function (it) {
  2123. // it.verify(true);
  2124. if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputComfirmPassword);
  2125. }.bind(this),
  2126. keyup: function (it, ev) {
  2127. if (ev.event.keyCode === 13)this.ok();
  2128. }.bind(this)
  2129. },
  2130. onEmpty: function (it) {
  2131. it.getElements()[0].setStyles(this.css.inputEmpty);
  2132. }.bind(this),
  2133. onUnempty: function (it) {
  2134. it.getElements()[0].setStyles(this.css.inputComfirmPassword);
  2135. }.bind(this)
  2136. },
  2137. forgetPassword: {
  2138. value: this.lp.forgetPassword,
  2139. type: "innerText",
  2140. className: "forgetPassword",
  2141. event: {
  2142. click: function () {
  2143. this.gotoResetPassword();
  2144. }.bind(this)
  2145. }
  2146. },
  2147. gotoLoginAction: {
  2148. value: this.lp.loginAction,
  2149. type: "innerText",
  2150. className: "signUpAction",
  2151. event: {
  2152. click: function () { this.gotoLogin() }.bind(this)
  2153. }
  2154. },
  2155. passwordTip: {
  2156. type: "innerText",
  2157. className: "forgetPassword",
  2158. defaultValue: layout.config.passwordRegexHint || ""
  2159. },
  2160. submitAction: {
  2161. value: this.lp.submitAction,
  2162. type: "button",
  2163. className: "inputLogin",
  2164. event: {
  2165. click: function () {
  2166. this.ok();
  2167. }.bind(this)
  2168. }
  2169. }
  2170. }
  2171. }, this.app, this.css);
  2172. this.form.load();
  2173. }.bind(this), true);
  2174. },
  2175. gotoLogin: function () {
  2176. this.explorer.openLoginForm({}, function () { window.location.reload(); });
  2177. this.close();
  2178. },
  2179. getPasswordRule: function (password) {
  2180. var str = "";
  2181. this.actions.checkRegisterPassword(password, function (json) {
  2182. str = json.data.value || "";
  2183. }.bind(this), null, false);
  2184. return str;
  2185. },
  2186. gotoResetPassword: function () {
  2187. this.explorer.openResetPasswordForm();
  2188. this.close();
  2189. },
  2190. ok: function () {
  2191. this.fireEvent("queryOk");
  2192. this.errorArea.empty();
  2193. var data = this.form.getResult(true, ",", true, false, true);
  2194. if (data) {
  2195. this._ok(data, function (json) {
  2196. if (json.type === "error") {
  2197. if (this.app) this.app.notice(json.message, "error");
  2198. } else {
  2199. this._close();
  2200. if (this.formMaskNode) this.formMaskNode.destroy();
  2201. this.formAreaNode.destroy();
  2202. if (this.explorer && this.explorer.view) this.explorer.view.reload();
  2203. if (this.app) this.app.notice(this.lp.changePasswordSuccess, "success");
  2204. this.fireEvent("postOk", json);
  2205. }
  2206. }.bind(this));
  2207. }
  2208. },
  2209. setWarning: function (text) {
  2210. this.errorArea.empty();
  2211. new Element("div", {
  2212. "text": text,
  2213. "styles": this.css.warningMessageNode
  2214. }).inject(this.errorArea);
  2215. },
  2216. _ok: function (data, callback) {
  2217. var d = {
  2218. userName : this.options.userName,
  2219. oldPassword : data.password,
  2220. newPassword : data.newPassword,
  2221. confirmPassword : data.confirmPassword,
  2222. isEncrypted : "n" //是否启用加密,默认不加密,启用(y)。注意:使用加密先要在服务器运行 create encrypt key"
  2223. }
  2224. // o2.Actions.load("x_organization_assemble_personal").PasswordAction.changePassword( d, function (json) {
  2225. o2.Actions.load("x_organization_assemble_personal").ResetAction.setPasswordAnonymous( d, function (json) {
  2226. if (callback) callback(json);
  2227. //this.fireEvent("postOk")
  2228. }.bind(this), function (errorObj) {
  2229. var error = JSON.parse(errorObj.responseText);
  2230. this.setWarning(error.message);
  2231. }.bind(this) )
  2232. }
  2233. });