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