Authentication.js 107 KB

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