Authentication.js 90 KB

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