Authentication.js 95 KB

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