Authentication.js 107 KB

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