Authentication.js 95 KB

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