Authentication.js 95 KB

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