Authentication.js 92 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942
  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": "480",
  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.captchaLogin = true;
  416. this.actions.getLoginMode(function( json ){
  417. this.codeLogin = json.data.codeLogin;
  418. this.bindLogin = json.data.bindLogin;
  419. this.captchaLogin = json.data.captchaLogin;
  420. }.bind(this), null, false);
  421. MWF.Actions.get("x_organization_assemble_personal").getRegisterMode(function(json){
  422. this.signUpMode = json.data.value;
  423. }.bind(this), null ,false);
  424. if( this.bindLogin ){
  425. this.bindLoginTipPic = new Element("div.bindLoginTipPic", {styles : this.css.bindLoginTipPic}).inject( this.formContentNode, "top" );
  426. this.bindLoginAction = new Element("div.bindLoginAction", {styles : this.css.bindLoginAction}).inject( this.formContentNode, "top" );
  427. this.bindLoginAction.addEvent("click", function(){
  428. this.showBindCodeLogin();
  429. }.bind(this));
  430. this.backtoPasswordLoginTipPic = new Element("div.backtoPasswordLoginTipPic", {styles : this.css.backtoPasswordLoginTipPic}).inject( this.formContentNode, "top" );
  431. this.backtoPasswordLoginAction = new Element("div.backtoPasswordLoginAction", {styles : this.css.backtoPasswordLoginAction}).inject( this.formContentNode, "top" );
  432. this.backtoPasswordLoginAction.addEvent("click", function(){
  433. this.backtoPasswordLogin();
  434. }.bind(this));
  435. }
  436. var html =
  437. "<table width='100%' bordr='0' cellpadding='0' cellspacing='0' styles='formTable'>" +
  438. "<tr><div><div item='passwordAction'>";
  439. if( this.codeLogin ){
  440. html+="</div><div styles='titleSep'></div><div item='codeAction'></div></tr>";
  441. }
  442. html+="</table>";
  443. html+="<table width='100%' bordr='0' cellpadding='0' cellspacing='0' styles='formTable'>" +
  444. "<tr item='credentialTr'><td styles='formTableValueTop20' item='credential'></td></tr>" +
  445. "<tr item='passwordTr'><td styles='formTableValueTop20' item='password'></td></tr>";
  446. if( this.captchaLogin ){
  447. html += "<tr item='captchaTr'><td styles='formTableValueTop20'>"+
  448. "<div item='captchaAnswer' style='float:left;'></div><div item='captchaPic' style='float:left;'></div><div item='changeCaptchaAction' style='float:left;'></div>"+
  449. "</td></tr>";
  450. }
  451. if( this.codeLogin ){
  452. html += "<tr item='codeTr' style='display: none'><td styles='formTableValueTop20'>"+
  453. " <div item='codeAnswer' style='float:left;'></div>"+
  454. " <div item='verificationAction' style='float:left;'></div>"+
  455. " <div item='resendVerificationAction' style='float:left;display:none;'></div>" +
  456. "</td></tr>";
  457. }
  458. html += "<tr><td styles='formTableValueTop20' item='loginAction'></td></tr>" +
  459. "</table>"+
  460. "<table width='100%' bordr='0' cellpadding='0' cellspacing='0' styles='formTable'>";
  461. if( this.signUpMode && this.signUpMode !== "disable" ){
  462. html += "<tr><td><div item='signUpAction'></div><div item='forgetPassword'></div></td></tr>";
  463. }else{
  464. html += "<tr><td><div styles='signUpAction'></div><div item='forgetPassword'></div></td></tr>";
  465. }
  466. html += "<tr><td styles='formTableValue' item='errorArea'></td></tr>" +
  467. "<tr><td styles='formTableValue' item='oauthArea'></td></tr>" +
  468. "</table>";
  469. this.formTableArea.set("html", html);
  470. new Element("div", {
  471. "styles": {
  472. "text-align": "center",
  473. "height": "40px",
  474. "line-height": "40px"
  475. },
  476. "text": layout.config.footer || layout.config.systemName
  477. }).inject(this.formTableArea, "after");
  478. if( this.captchaLogin )this.setCaptchaPic();
  479. this.errorArea = this.formTableArea.getElement("[item=errorArea]");
  480. this.oauthArea = this.formTableArea.getElement("[item=oauthArea]");
  481. MWF.xDesktop.requireApp("Template", "MForm", function () {
  482. this.form = new MForm(this.formTableArea, this.data, {
  483. style: this.options.popupStyle,
  484. verifyType : "single", //batch一起校验,或alert弹出
  485. isEdited: this.isEdited || this.isNew,
  486. itemTemplate: {
  487. credential: {
  488. text: this.lp.userName,
  489. defaultValue : this.lp.userName,
  490. className : "inputUser",
  491. notEmpty : true,
  492. defaultValueAsEmpty: true,
  493. emptyTip: this.lp.inputYourUserName,
  494. event : {
  495. focus : function( it ){
  496. if (this.lp.userName === it.getValue()) it.setValue("");
  497. if (!it.warningStatus) it.getElements()[0].setStyles( this.css.inputActive );
  498. }.bind(this),
  499. blur : function( it ){
  500. if ("" === it.getValue()) it.setValue(this.lp.userName);
  501. if (!it.warningStatus) it.getElements()[0].setStyles( this.css.inputUser );
  502. }.bind(this),
  503. keyup : function( it, ev ){
  504. if (ev.event.keyCode === 13) this.ok();
  505. }.bind(this)
  506. },
  507. onEmpty : function( it ){
  508. it.getElements()[0].setStyles(this.css.inputEmpty);
  509. }.bind(this),
  510. onUnempty : function( it ){
  511. it.getElements()[0].setStyles(this.css.inputUser);
  512. }.bind(this)
  513. },
  514. password : {
  515. text: this.lp.password,
  516. type : "password",
  517. defaultValue : "password",
  518. className : "inputPassword",
  519. notEmpty : true,
  520. defaultValueAsEmpty: true,
  521. emptyTip: this.lp.inputYourPassword,
  522. event : {
  523. focus : function(it){
  524. if ("password" === it.getValue()) it.setValue("");
  525. if(!it.warningStatus) it.getElements()[0].setStyles(this.css.inputActive);
  526. }.bind(this),
  527. blur : function( it ){
  528. if (!it.warningStatus) it.getElements()[0].setStyles(this.css.inputPassword);
  529. }.bind(this),
  530. keyup : function(it, ev){
  531. if( ev.event.keyCode === 13 ) this.ok();
  532. }.bind(this)
  533. },
  534. onEmpty : function( it ){
  535. it.getElements()[0].setStyles( this.css.inputEmpty );
  536. }.bind(this),
  537. onUnempty : function( it ){
  538. it.getElements()[0].setStyles( this.css.inputPassword );
  539. }.bind(this)
  540. },
  541. captchaAnswer : {
  542. tType:"number",
  543. text: this.lp.verificationCode,
  544. defaultValue : this.lp.verificationCode,
  545. className : "inputVerificationCode",
  546. notEmpty : true,
  547. defaultValueAsEmpty: true,
  548. emptyTip: this.lp.inputPicVerificationCode,
  549. event : {
  550. focus : function( it ){
  551. if (this.lp.verificationCode === it.getValue()) it.setValue("");
  552. if (!it.warningStatus) it.getElements()[0].setStyles( this.css.inputActive );
  553. }.bind(this),
  554. blur : function( it ){
  555. if ("" === it.getValue()) it.setValue(this.lp.verificationCode);
  556. if (!it.warningStatus) it.getElements()[0].setStyles( this.css.inputVerificationCode );
  557. }.bind(this),
  558. keyup : function( it, ev ){
  559. if (ev.event.keyCode === 13) this.ok();
  560. }.bind(this)
  561. },
  562. onEmpty : function( it ){
  563. it.getElements()[0].setStyles( this.css.inputEmpty );
  564. }.bind(this),
  565. onUnempty : function( it ){
  566. it.getElements()[0].setStyles( this.css.inputVerificationCode );
  567. }.bind(this)
  568. },
  569. changeCaptchaAction :{
  570. value : this.lp.changeVerification,
  571. type : "innerText",
  572. className : "verificationChange",
  573. event : {
  574. click : function(){
  575. this.setCaptchaPic();
  576. }.bind(this)
  577. }
  578. },
  579. codeAnswer : {
  580. text: this.lp.verificationCode,
  581. defaultValue : this.lp.inputVerificationCode,
  582. className : "inputVerificationCode2",
  583. notEmpty : true,
  584. defaultValueAsEmpty: true,
  585. emptyTip: this.lp.inputVerificationCode,
  586. event : {
  587. focus : function( it ){
  588. if (this.lp.inputVerificationCode === it.getValue()) it.setValue("");
  589. if (!it.warningStatus) it.getElements()[0].setStyles( this.css.inputActive );
  590. }.bind(this),
  591. blur : function( it ){
  592. if ("" === it.getValue()) it.setValue(this.lp.inputVerificationCode);
  593. if (!it.warningStatus) it.getElements()[0].setStyles( this.css.inputVerificationCode2 );
  594. }.bind(this),
  595. keyup : function( it, ev ){
  596. if (ev.event.keyCode === 13) this.ok();
  597. }.bind(this)
  598. },
  599. onEmpty : function( it ){
  600. it.getElements()[0].setStyles( this.css.inputEmpty );
  601. }.bind(this),
  602. onUnempty : function( it ){
  603. it.getElements()[0].setStyles( this.css.inputVerificationCode2 );
  604. }.bind(this)
  605. },
  606. verificationAction : {
  607. value: this.lp.sendVerification,
  608. type : "button",
  609. className : "inputSendVerification",
  610. event : {
  611. click : function(){
  612. this.sendVerificationAction();
  613. }.bind(this)
  614. }
  615. },
  616. resendVerificationAction : {
  617. value: this.lp.resendVerification,
  618. type : "button",
  619. className : "inputResendVerification"
  620. },
  621. loginAction: {
  622. value: this.lp.loginAction,
  623. type : "button",
  624. className : "inputLogin",
  625. event : {
  626. click : function(){
  627. this.ok();
  628. }.bind(this)
  629. }
  630. },
  631. passwordAction: {
  632. value : this.lp.passwordLogin,
  633. type : "innerText",
  634. className : "titleNode_active",
  635. event : {
  636. click : function(){
  637. if( this.codeLogin )this.showPasswordLogin();
  638. }.bind(this)
  639. }
  640. },
  641. codeAction: {
  642. value : this.lp.codeLogin,
  643. type : "innerText",
  644. className : "titleNode_normal",
  645. event : {
  646. click : function(){
  647. this.showCodeLogin();
  648. }.bind(this)
  649. }
  650. },
  651. signUpAction : {
  652. value : this.lp.signUp,
  653. type : "innerText",
  654. className : "signUpAction",
  655. event : {
  656. click : function(){
  657. this.gotoSignup();
  658. }.bind(this)
  659. }
  660. },
  661. forgetPassword : {
  662. value : this.lp.forgetPassword,
  663. type : "innerText",
  664. className : "forgetPassword",
  665. event :{
  666. click : function(){
  667. this.gotoResetPassword();
  668. }.bind(this)
  669. }
  670. }
  671. }
  672. }, this.app, this.css);
  673. this.form.load();
  674. }.bind(this), true);
  675. if( this.bindLogin ){
  676. this.bindLoginContainer = new Element("div", {
  677. styles : this.css.bindLoginContainer
  678. }).inject( this.formContentNode );
  679. var html2 = "<div item='bindLoginTitle' styles='bindTitleNode'></div>"+
  680. "<div styles='bindBodyArea'>" +
  681. "<div item='bindPicArea' styles='bindPicArea'></div>" +
  682. "<div styles='bindSepArea'></div>" +
  683. "<div styles='bindExampleArea'></div>" +
  684. "</div>"+
  685. "<div styles='bindTipArea'>"+
  686. " <div styles='bindTipIconArea'></div>" +
  687. " <div styles='bindTipTextArea'>"+
  688. " <div>打开<div styles='bindTipLinkArea'>APP</div>扫一扫</div>" +
  689. " <div>登录网页版</div>" +
  690. "</div>";
  691. this.bindLoginContainer.set("html",html2);
  692. this.isShowEnable = true;
  693. this.bindBodyArea = this.bindLoginContainer.getElement("[styles='bindBodyArea']");
  694. this.bindLoginContainer.addEvent("mousemove", function(ev){
  695. if( this.bindBodyArea.isOutside( ev ) ){
  696. this.hideExampleArea(ev);
  697. }else{
  698. this.showExampleArea(ev);
  699. }
  700. }.bind(this));
  701. this.bindPicArea = this.bindLoginContainer.getElement("[item='bindPicArea']");
  702. this.setBindPic();
  703. this.bindExampleArea = this.bindLoginContainer.getElement("[styles='bindExampleArea']");
  704. this.bindSepArea = this.bindLoginContainer.getElement("[styles='bindSepArea']");
  705. var link = this.bindLoginContainer.getElement("[styles='bindTipLinkArea']");
  706. link.addEvent("click", function(){
  707. window.open( this.lp.o2downloadLink, "_blank" );
  708. }.bind(this));
  709. MWF.xDesktop.requireApp("Template", "MForm", function () {
  710. this.bindform = new MForm(this.bindLoginContainer, {}, {
  711. style: "o2platform",
  712. verifyType : "single", //batch一起校验,或alert弹出
  713. isEdited: this.isEdited || this.isNew,
  714. itemTemplate: {
  715. bindLoginTitle: {value : this.lp.bingLoginTitle, type : "innerText"}
  716. }
  717. }, this.app, this.css);
  718. this.bindform.load();
  719. }.bind(this), true);
  720. }
  721. this.loadOauthContent()
  722. },
  723. _beforeFormNodeSize : function(){
  724. if( !this.isPlusOauthSize && this.oauthListNode ){
  725. this.options.height = parseInt(this.options.height) + this.oauthArea.getSize().y ;
  726. this.isPlusOauthSize = true;
  727. }
  728. if( this.oauthListNode || (!this.captchaLogin && !this.bindLogin) ){ //留高度给二维码
  729. this.options.height = this.options.height - 60;
  730. }
  731. if( this.oauthListNode && this.captchaLogin ){
  732. this.options.height = this.options.height + 60;
  733. }
  734. },
  735. loadOauthContent : function(){
  736. this.actions.listOauthServer(function( json ){
  737. this.oauthList = json.data || [];
  738. if( this.oauthList.length > 0 ){
  739. this.oauthListNode = new Element("div", { styles : this.css.oauthListNode } ).inject( this.oauthArea );
  740. this.oauthList.each( function( d ){
  741. this.loadOauthItem( d );
  742. }.bind(this));
  743. }
  744. }.bind(this), null, false);
  745. },
  746. loadOauthItem : function( data ){
  747. var url = data.icon.indexOf("http") == 0 ? data.icon : ("data:image/png;base64,"+data.icon);
  748. var itemNode = new Element("div", {
  749. styles : this.css.oauthItemNode,
  750. events : {
  751. click : function(){
  752. window.location = "/x_desktop/oauth.html?oauth="+ encodeURIComponent(this.name);
  753. }.bind(data)
  754. }
  755. } ).inject( this.oauthListNode );
  756. var iconNode = new Element("img", {
  757. styles : this.css.oauthItemIconNode,
  758. src : url
  759. } ).inject( itemNode );
  760. var textNode = new Element("div", {
  761. styles : this.css.oauthItemTextNode,
  762. text : data.name
  763. } ).inject( itemNode );
  764. },
  765. showExampleArea: function( ){
  766. if( this.isHiddingExample || this.isShowingExample)return;
  767. if( !this.isShowEnable )return;
  768. this.isShowingExample = true;
  769. var left = this.bindBodyArea.getPosition( this.bindBodyArea.getParent()).x;
  770. this.intervalId = setInterval( function(){
  771. if( left > 136 ){
  772. this.bindBodyArea.setStyle("margin-left",(left-5)+"px");
  773. left = left -5;
  774. }else{
  775. clearInterval(this.intervalId);
  776. this.bindBodyArea.setStyle("width","400px");
  777. this.bindSepArea.setStyle("display", "");
  778. this.bindExampleArea.setStyle("display", "");
  779. this.isHidEnable = true;
  780. this.isShowEnable = false;
  781. this.isShowingExample = false;
  782. }
  783. }.bind(this), 10 )
  784. },
  785. hideExampleArea: function( ){
  786. if( this.isShowingExample || this.isHiddingExample )return;
  787. if( !this.isHidEnable )return;
  788. this.isHiddingExample = true;
  789. var left = this.bindBodyArea.getPosition( this.bindBodyArea.getParent()).x;
  790. this.bindSepArea.setStyle("display", "none");
  791. this.bindExampleArea.setStyle("display", "none");
  792. this.intervalId2 = setInterval( function(){
  793. if( left < 220 ){
  794. this.bindBodyArea.setStyle("margin-left",(left+5)+"px");
  795. left = left + 5;
  796. }else{
  797. clearInterval(this.intervalId2);
  798. this.bindBodyArea.setStyle("width","204px");
  799. this.isHidEnable = false;
  800. this.isShowEnable = true;
  801. this.isHiddingExample = false;
  802. }
  803. }.bind(this), 10 )
  804. },
  805. showPasswordLogin: function(){
  806. this.errorArea.empty();
  807. this.loginType = "captcha";
  808. this.form.getItem("passwordAction").setStyles(this.css.titleNode_active);
  809. this.form.getItem("codeAction").setStyles(this.css.titleNode_normal);
  810. this.formTableArea.getElement("[item='passwordTr']").setStyle("display","");
  811. var captchaTr = this.formTableArea.getElement("[item='captchaTr']");
  812. if(captchaTr)captchaTr.setStyle("display","");
  813. this.formTableArea.getElement("[item='codeTr']").setStyle("display","none");
  814. },
  815. showCodeLogin: function(){
  816. this.errorArea.empty();
  817. this.loginType = "code";
  818. this.form.getItem("passwordAction").setStyles(this.css.titleNode_normal);
  819. this.form.getItem("codeAction").setStyles(this.css.titleNode_active);
  820. this.formTableArea.getElement("[item='passwordTr']").setStyle("display","none");
  821. var captchaTr = this.formTableArea.getElement("[item='captchaTr']");
  822. if(captchaTr)captchaTr.setStyle("display","none");
  823. this.formTableArea.getElement("[item='codeTr']").setStyle("display","");
  824. },
  825. showBindCodeLogin:function(){
  826. this.errorArea.empty();
  827. this.formTableContainer.setStyle("display","none");
  828. this.bindLoginContainer.setStyle("display","");
  829. this.bindLoginTipPic.setStyle("display","none");
  830. this.bindLoginAction.setStyle("display","none");
  831. this.backtoPasswordLoginTipPic.setStyle("display","");
  832. this.backtoPasswordLoginAction.setStyle("display","");
  833. this.checkBindStatus();
  834. },
  835. backtoPasswordLogin: function(){
  836. this.errorArea.empty();
  837. if( this.bindStatusInterval )clearInterval( this.bindStatusInterval );
  838. this.formTableContainer.setStyle("display","");
  839. this.bindLoginContainer.setStyle("display","none");
  840. this.bindLoginTipPic.setStyle("display","");
  841. this.bindLoginAction.setStyle("display","");
  842. this.backtoPasswordLoginTipPic.setStyle("display","none");
  843. this.backtoPasswordLoginAction.setStyle("display","none");
  844. },
  845. setBindPic: function(){
  846. this.bindPicArea.empty();
  847. this.actions.getLoginBind( function( json ){
  848. this.bindMeta = json.data.meta;
  849. new Element("img", {
  850. src : "data:image/png;base64,"+json.data.image
  851. }).inject( this.bindPicArea );
  852. }.bind(this))
  853. },
  854. setCaptchaPic: function(){
  855. if( !this.captchaLogin )return;
  856. var captchaPic = this.formTableArea.getElement("[item='captchaPic']");
  857. captchaPic.empty();
  858. this.actions.getLoginCaptcha(120, 50, function( json ){
  859. this.captcha = json.data.id;
  860. new Element("img", {
  861. src : "data:image/png;base64,"+json.data.image,
  862. styles : this.css.verificationImage
  863. }).inject( captchaPic );
  864. }.bind(this))
  865. },
  866. sendVerificationAction: function(){
  867. var flag = true;
  868. var credentialItem = this.form.getItem("credential");
  869. var credential = credentialItem.getValue();
  870. if( !credential || credential.trim() === "" ){
  871. credentialItem.setWarning( this.lp.inputYourUserName, "empty");
  872. return;
  873. }else{
  874. this.actions.checkCredential( credential, function( json ){
  875. if( !json.data.value ){
  876. flag = false;
  877. credentialItem.setWarning( this.lp.userNotExist , "invalid");
  878. }
  879. }.bind(this),function( errorObj ){
  880. flag = false;
  881. var error = JSON.parse( errorObj.responseText );
  882. credentialItem.setWarning( error.message , "invalid");
  883. }.bind(this), false )
  884. }
  885. if( !flag ){
  886. return;
  887. }else{
  888. credentialItem.clearWarning("invalid");
  889. }
  890. this.actions.createCredentialCode( credential, function( json ){
  891. }, function( errorObj ){
  892. var error = JSON.parse( errorObj.responseText );
  893. this.setWarning( error.message );
  894. flag = false
  895. }.bind(this));
  896. if( !flag ){
  897. return;
  898. }else{
  899. this.errorArea.empty();
  900. }
  901. this.form.getItem("verificationAction").container.setStyle("display","none");
  902. this.setResendVerification();
  903. },
  904. setResendVerification: function(){
  905. var resendItem = this.form.getItem("resendVerificationAction");
  906. resendItem.container.setStyle("display","");
  907. this.resendElement = resendItem.getElements()[0];
  908. this.resendElement.set("text", this.lp.resendVerification + "(60)");
  909. var i=60;
  910. this.timer = setInterval( function(){
  911. if( i > 0 ){
  912. this.resendElement.set("text", this.lp.resendVerification + "("+ --i +")")
  913. }else{
  914. this.form.getItem("verificationAction").container.setStyle("display","");
  915. resendItem.container.setStyle("display","none");
  916. clearInterval( this.timer )
  917. }
  918. }.bind(this), 1000 )
  919. },
  920. gotoSignup: function(){
  921. this.explorer.openSignUpForm();
  922. this.close();
  923. },
  924. gotoResetPassword: function(){
  925. this.explorer.openResetPasswordForm();
  926. this.close();
  927. },
  928. checkBindStatus: function(){
  929. this.bindStatusInterval = setInterval( function(){
  930. this.actions.checkBindStatus( this.bindMeta, function( json ){
  931. if( json.data ){
  932. if( json.data.name && json.data.name !== "anonymous" ){
  933. this.fireEvent("queryOk");
  934. this._close();
  935. if(this.formMaskNode)this.formMaskNode.destroy();
  936. this.formAreaNode.destroy();
  937. if (this.explorer && this.explorer.view)this.explorer.view.reload();
  938. if(this.app)this.app.notice( this.lp.loginSuccess, "success");
  939. this.fireEvent("postOk", json);
  940. }
  941. }
  942. }.bind(this), function( errorObj ){
  943. //var error = JSON.parse( errorObj.responseText );
  944. //this.setWarning( error.message );
  945. }.bind(this))
  946. }.bind(this) , 3000 );
  947. },
  948. _close: function(){
  949. if( this.bindStatusInterval )clearInterval( this.bindStatusInterval );
  950. if(this.timer) clearInterval( this.timer );
  951. },
  952. ok: function () {
  953. this.fireEvent("queryOk");
  954. this.errorArea.empty();
  955. var captchaItem = null;
  956. var codeItem = null;
  957. if( this.loginType === "captcha" ){
  958. this.form.getItem("password").options.notEmpty = true;
  959. if( this.captchaLogin ){
  960. captchaItem = this.form.getItem("captchaAnswer");
  961. if( captchaItem )captchaItem.options.notEmpty = true;
  962. }
  963. codeItem = this.form.getItem("codeAnswer");
  964. if(codeItem)codeItem.options.notEmpty = false;
  965. }else if( this.loginType === "code" ){
  966. this.form.getItem("password").options.notEmpty = false;
  967. if( this.captchaLogin ){
  968. captchaItem = this.form.getItem("captchaAnswer");
  969. if( captchaItem )captchaItem.options.notEmpty = false;
  970. }
  971. codeItem = this.form.getItem("codeAnswer");
  972. if(codeItem)codeItem.options.notEmpty = true;
  973. }
  974. var data = this.form.getResult(true, ",", true, false, true);
  975. if (data) {
  976. this._ok(data, function (json) {
  977. if (json.type === "error") {
  978. if(this.app)this.app.notice(json.message, "error");
  979. } else {
  980. this._close();
  981. if( this.formMaskNode ) this.formMaskNode.destroy();
  982. this.formAreaNode.destroy();
  983. if (this.explorer && this.explorer.view)this.explorer.view.reload();
  984. if(this.app)this.app.notice( this.lp.loginSuccess, "success");
  985. this.fireEvent("postOk",json);
  986. }
  987. }.bind(this));
  988. }
  989. },
  990. setWarning : function(text){
  991. this.errorArea.empty();
  992. new Element("div",{
  993. "text" : text,
  994. "styles" : this.css.warningMessageNode
  995. }).inject( this.errorArea );
  996. },
  997. _ok: function (data, callback) {
  998. var d = null;
  999. if( this.loginType === "captcha" ){
  1000. d = {
  1001. credential : data.credential,
  1002. password : data.password
  1003. };
  1004. if( this.captchaLogin ){
  1005. d.captchaAnswer = data.captchaAnswer;
  1006. d.captcha = this.captcha;
  1007. }
  1008. this.actions.loginByCaptcha( d, function( json ){
  1009. if( callback )callback( json );
  1010. //this.fireEvent("postOk")
  1011. }.bind(this), function( errorObj ){
  1012. var error = JSON.parse( errorObj.responseText );
  1013. this.setWarning( error.message );
  1014. this.setCaptchaPic();
  1015. if(this.form.getItem( "captchaAnswer"))this.form.getItem( "captchaAnswer").setValue("");
  1016. }.bind(this));
  1017. }else if( this.loginType === "code" ){
  1018. d = {
  1019. credential : data.credential,
  1020. codeAnswer : data.codeAnswer
  1021. };
  1022. this.actions.loginByCode( d, function( json ){
  1023. if( callback )callback( json );
  1024. //this.fireEvent("postOk")
  1025. }.bind(this), function( errorObj ){
  1026. var error = JSON.parse( errorObj.responseText );
  1027. this.setWarning( error.message );
  1028. }.bind(this ) );
  1029. }
  1030. }
  1031. });
  1032. MWF.xDesktop.Authentication.SignUpForm = new Class({
  1033. Extends: MPopupForm,
  1034. Implements: [Options, Events],
  1035. options: {
  1036. "style": "default",
  1037. "popupStyle" : "o2platformSignup",
  1038. "width": "910",
  1039. "height": "620",
  1040. "hasTop": true,
  1041. "hasIcon": false,
  1042. "hasTopIcon" : true,
  1043. "hasTopContent" : true,
  1044. "hasBottom": false,
  1045. "title": MWF.LP.authentication.SignUpFormTitle,
  1046. "draggable": true,
  1047. "closeAction": true
  1048. },
  1049. _createTableContent: function () {
  1050. var self = this;
  1051. this.actions = MWF.Actions.get("x_organization_assemble_personal");
  1052. var signUpMode = "code";
  1053. this.actions.getRegisterMode(function(json){
  1054. signUpMode = json.data.value;
  1055. }.bind(this), null ,false);
  1056. this.formTableContainer.setStyles({
  1057. "width" : "890px",
  1058. "margin-top" : "50px"
  1059. });
  1060. var html = "<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>" +
  1061. "<tr><td styles='formTableTitle' lable='name' width='200'></td>" +
  1062. " <td styles='formTableValue' item='name' width='350'></td>" +
  1063. " <td styles='formTableValue' item='nameTip'></td></tr>" +
  1064. "<tr><td styles='formTableTitle' lable='password'></td>" +
  1065. " <td styles='formTableValue' item='password'></td>" +
  1066. " <td styles='formTableValue'><div item='passwordStrengthArea'></div></div><div item='passwordTip'></div></td></tr>" +
  1067. "<tr><td styles='formTableTitle' lable='confirmPassword'></td>" +
  1068. " <td styles='formTableValue' item='confirmPassword'></td>" +
  1069. " <td styles='formTableValue' item='confirmPasswordTip'></td></tr>" +
  1070. "<tr><td styles='formTableTitle' lable='genderType'></td>" +
  1071. " <td styles='formTableValue' item='genderType'></td>" +
  1072. " <td styles='formTableValue' item='genderTypeTip'></td></tr>" +
  1073. //"<tr><td styles='formTableTitle' lable='mail'></td>" +
  1074. //" <td styles='formTableValue' item='mail'></td>" +
  1075. //" <td styles='formTableValue' item='mailTip'></td></tr>" +
  1076. "<tr><td styles='formTableTitle' lable='mobile'></td>" +
  1077. " <td styles='formTableValue' item='mobile'></td>" +
  1078. " <td styles='formTableValue' item='mobileTip'></td></tr>";
  1079. if( signUpMode === "code" ){
  1080. html += "<tr><td styles='formTableTitle' lable='codeAnswer'></td>" +
  1081. " <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>" +
  1082. " <td styles='formTableValue' item='verificationCodeTip'></td></tr>";
  1083. }else{
  1084. html += "<tr><td styles='formTableTitle' lable='captchaAnswer'></td>" +
  1085. " <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>" +
  1086. " <td styles='formTableValue' item='captchaAnswerTip'></td></tr>";
  1087. }
  1088. html += "<tr><td styles='formTableTitle'></td>" +
  1089. " <td styles='formTableValue' item='signUpAction'></td>" +
  1090. " <td styles='formTableValue' item='signUpTip'></td></tr>" +
  1091. "<tr><td></td>" +
  1092. " <td><div item='hasAccountArea'></div><div item='gotoLoginAction'></div></td>" +
  1093. " <td></td></tr>" +
  1094. "</table>";
  1095. this.formTableArea.set("html", html);
  1096. if( signUpMode === "captcha" ){
  1097. this.setCaptchaPic();
  1098. }
  1099. //this.createPasswordStrengthNode();
  1100. MWF.xDesktop.requireApp("Template", "MForm", function () {
  1101. this.form = new MForm(this.formTableArea, this.data, {
  1102. style: this.options.popupStyle,
  1103. verifyType : "batchSingle", //batch一起校验,或alert弹出
  1104. isEdited: this.isEdited || this.isNew,
  1105. onPostLoad: function(){
  1106. var form = this.form;
  1107. var table = this.formTableArea;
  1108. form.getItem("name").tipNode = table.getElement("[item='nameTip']");
  1109. form.getItem("password").tipNode = table.getElement("[item='passwordTip']");
  1110. form.getItem("confirmPassword").tipNode = table.getElement("[item='confirmPasswordTip']");
  1111. //form.getItem("mail").tipNode = table.getElement("[item='mailTip']")[0];
  1112. form.getItem("genderType").tipNode = table.getElement("[item='genderTypeTip']");
  1113. form.getItem("mobile").tipNode = table.getElement("[item='mobileTip']");
  1114. this.tipNode = table.getElement("[item='signUpTip']");
  1115. var captchaAnswer = form.getItem("captchaAnswer");
  1116. if( captchaAnswer ){
  1117. form.getItem("captchaAnswer").tipNode = table.getElement("[item='captchaAnswerTip']");
  1118. }
  1119. var codeAnswer = form.getItem("codeAnswer");
  1120. if( codeAnswer ){
  1121. form.getItem("codeAnswer").tipNode = table.getElement("[item='verificationCodeTip']");
  1122. }
  1123. }.bind(this),
  1124. itemTemplate: {
  1125. name: { text: this.lp.userName, defaultValue : this.lp.userName, className : "inputUser",
  1126. notEmpty : true, defaultValueAsEmpty: true, emptyTip: this.lp.inputYourUserName,
  1127. validRule : { isInvalid : function( value, it ){ return this.checkUserName( value, it ); }.bind(this)},
  1128. validMessage : { isInvalid : this.lp.userExist },
  1129. event : {
  1130. focus : function( it ){ if( this.lp.userName === it.getValue() )it.setValue(""); if( !it.warningStatus )it.getElements()[0].setStyles( this.css.inputActive ); }.bind(this),
  1131. keyup : function( it, ev ){ if( ev.event.keyCode === 13 ){ this.ok() } }.bind(this),
  1132. blur: function (it) {
  1133. if( it.verify( true ) ){
  1134. if( !it.warningStatus )it.getElements()[0].setStyles( this.css.inputUser );
  1135. }
  1136. }.bind(this)
  1137. }, onEmpty : function( it ){
  1138. it.getElements()[0].setStyles( this.css.inputEmpty );
  1139. }.bind(this), onUnempty : function( it ){
  1140. it.getElements()[0].setStyles( this.css.inputUser );
  1141. }.bind(this) },
  1142. password : { text: this.lp.password, type : "password", className : "inputPassword",
  1143. notEmpty : true, defaultValueAsEmpty: true, emptyTip: this.lp.inputYourPassword,
  1144. validRule : { passwordIsWeak: function( value, it ){
  1145. return !this.getPasswordRule( it.getValue() );
  1146. }.bind(this)},
  1147. validMessage : { passwordIsWeak : function(){
  1148. return self.getPasswordRule( this.getValue() );
  1149. }}, //this.lp.passwordIsSimple
  1150. event : {
  1151. focus : function( it ){ if( "password" === it.getValue() )it.setValue(""); if( !it.warningStatus )it.getElements()[0].setStyles( this.css.inputActive ); }.bind(this),
  1152. //keyup : function(it){ this.pwStrength(it.getValue()) }.bind(this),
  1153. blur: function (it) { it.verify( true ) }.bind(this)
  1154. }, onEmpty : function( it ){
  1155. it.getElements()[0].setStyles( this.css.inputEmpty );
  1156. }.bind(this), onUnempty : function( it ){
  1157. it.getElements()[0].setStyles( this.css.inputPassword );
  1158. }.bind(this) },
  1159. confirmPassword : { text: this.lp.confirmPassword, type : "password", className : "inputComfirmPassword",
  1160. notEmpty : true,defaultValueAsEmpty: true, emptyTip: this.lp.inputComfirmPassword,
  1161. validRule : { passwordNotEqual: function( value, it ){
  1162. if( it.getValue() === this.form.getItem("password").getValue() )return true;
  1163. }.bind(this)},
  1164. validMessage : { passwordNotEqual : this.lp.passwordNotEqual },
  1165. event : {
  1166. focus : function( it ){ if( "password" === it.getValue() )it.setValue(""); if( !it.warningStatus )it.getElements()[0].setStyles( this.css.inputActive ); }.bind(this),
  1167. keyup : function( it, ev ){ if( ev.event.keyCode === 13 ){ this.ok() } }.bind(this),
  1168. blur: function (it) {
  1169. if( it.verify( true ) ) {
  1170. if( !it.warningStatus )it.getElements()[0].setStyles( this.css.inputComfirmPassword );
  1171. }
  1172. }.bind(this)
  1173. }, onEmpty : function( it ){
  1174. it.getElements()[0].setStyles( this.css.inputEmpty );
  1175. }.bind(this), onUnempty : function( it ){
  1176. it.getElements()[0].setStyles( this.css.inputComfirmPassword );
  1177. }.bind(this) },
  1178. mail : { text: this.lp.mail, defaultValue : this.lp.inputYourMail, className : "inputMail",
  1179. notEmpty : true, defaultValueAsEmpty: true, emptyTip: this.lp.inputYourMail, validRule: { email : true }, event : {
  1180. focus : function( it ){ if( this.lp.inputYourMail === it.getValue() )it.setValue(""); if( !it.warningStatus )it.getElements()[0].setStyles( this.css.inputActive ); }.bind(this),
  1181. blur: function (it) { it.verify( true ); if( !it.warningStatus )it.getElements()[0].setStyles( this.css.inputMail ); }.bind(this),
  1182. keyup : function( it, ev ){ if( ev.event.keyCode === 13 ){ this.ok() } }.bind(this)
  1183. }, onEmpty : function( it ){
  1184. it.getElements()[0].setStyles( this.css.inputEmpty );
  1185. }.bind(this), onUnempty : function( it ){
  1186. it.getElements()[0].setStyles( this.css.inputMail );
  1187. }.bind(this) },
  1188. genderType : { text: this.lp.genderType, className : "inputGenderType", type : "select", selectValue : this.lp.genderTypeValue.split(","), selectText : this.lp.genderTypeText.split(","),
  1189. notEmpty : true, emptyTip: this.lp.selectGenderType, event : {
  1190. focus: function(it){ if( !it.warningStatus )it.getElements()[0].setStyles( this.css.inputActive ); }.bind(this),
  1191. blur: function (it) { it.verify( true ); if( !it.warningStatus )it.getElements()[0].setStyles( this.css.inputGenderType ); }.bind(this),
  1192. keyup : function( it, ev ){ if( ev.event.keyCode === 13 ){ this.ok() } }.bind(this)
  1193. }, onEmpty : function( it ){
  1194. it.getElements()[0].setStyles( this.css.inputEmpty );
  1195. }.bind(this), onUnempty : function( it ){
  1196. it.getElements()[0].setStyles( this.css.inputGenderType );
  1197. }.bind(this) },
  1198. mobile : { text: this.lp.mobile, defaultValue : this.lp.inputYourMobile, className : "inputMobile", tType : "number",
  1199. notEmpty : true, defaultValueAsEmpty: true, emptyTip: this.lp.inputYourMobile,
  1200. validRule : { isInvalid: function( value, it ){ return this.checkMobile( value, it ); }.bind(this)},
  1201. validMessage : { isInvalid : this.lp.mobileIsRegisted },
  1202. event : {
  1203. focus : function( it ){ if( this.lp.inputYourMobile === it.getValue() )it.setValue(""); if( !it.warningStatus )it.getElements()[0].setStyles( this.css.inputActive ); }.bind(this),
  1204. keyup : function( it, ev ){ if( ev.event.keyCode === 13 ){ this.ok() } }.bind(this),
  1205. blur: function (it) { if( it.verify( true )){
  1206. if( !it.warningStatus )it.getElements()[0].setStyles( this.css.inputMobile );
  1207. } }.bind(this)
  1208. }, onEmpty : function( it ){
  1209. it.getElements()[0].setStyles( this.css.inputEmpty );
  1210. }.bind(this), onUnempty : function( it ){
  1211. it.getElements()[0].setStyles( this.css.inputMobile );
  1212. }.bind(this) },
  1213. captchaAnswer: { tType: "number", text: this.lp.verificationCode, defaultValue : this.lp.verificationCode, className : "inputVerificationCode",
  1214. notEmpty : true,defaultValueAsEmpty: true, emptyTip: this.lp.inputPicVerificationCode, event : {
  1215. focus : function( it ){ if( this.lp.verificationCode === it.getValue() )it.setValue(""); if( !it.warningStatus )it.getElements()[0].setStyles( this.css.inputActive ); }.bind(this),
  1216. blur: function (it) { it.verify( true ); if( !it.warningStatus )it.getElements()[0].setStyles( this.css.inputVerificationCode ); }.bind(this),
  1217. keyup : function( it, ev ){ if( ev.event.keyCode === 13 ){ this.ok() } }.bind(this)
  1218. }, onEmpty : function( it ){
  1219. it.getElements()[0].setStyles( this.css.inputEmpty );
  1220. }.bind(this), onUnempty : function( it ){
  1221. it.getElements()[0].setStyles( this.css.inputVerificationCode );
  1222. }.bind(this) },
  1223. changeCaptchaAction :{ value : this.lp.changeVerification, type : "innerText", className : "verificationChange", event : {
  1224. click : function(){
  1225. this.setCaptchaPic();
  1226. }.bind(this)
  1227. } },
  1228. codeAnswer : { text: this.lp.verificationCode, defaultValue : this.lp.inputVerificationCode, className : "inputVerificationCode2",
  1229. notEmpty : true,defaultValueAsEmpty: true, emptyTip: this.lp.inputVerificationCode, event : {
  1230. focus : function( it ){ if( this.lp.inputVerificationCode === it.getValue() )it.setValue(""); if( !it.warningStatus )it.getElements()[0].setStyles( this.css.inputActive ); }.bind(this),
  1231. blur: function (it) { it.verify( true ); if( !it.warningStatus )it.getElements()[0].setStyles( this.css.inputVerificationCode2 ); }.bind(this),
  1232. keyup : function( it, ev ){ if( ev.event.keyCode === 13 ){ this.ok() } }.bind(this)
  1233. }, onEmpty : function( it ){
  1234. it.getElements()[0].setStyles( this.css.inputEmpty );
  1235. }.bind(this), onUnempty : function( it ){
  1236. it.getElements()[0].setStyles( this.css.inputVerificationCode2 );
  1237. }.bind(this) },
  1238. verificationAction : {value: this.lp.sendVerification, type : "button", className : "inputSendVerification", event : {
  1239. click : function(){ this.sendVerificationAction() }.bind(this)
  1240. } },
  1241. resendVerificationAction : {value: this.lp.resendVerification, type : "button", className : "inputResendVerification"},
  1242. signUpAction: {value: this.lp.signUp, type : "button", className : "inputSignUp", event : {
  1243. click : function(){ this.ok() }.bind(this)
  1244. } },
  1245. hasAccountArea : { value : this.lp.hasAccount, type : "innerText", className : "hasCountArea" },
  1246. gotoLoginAction : { value : this.lp.gotoLogin, type : "innerText", className : "gotoLoginAction", event : {
  1247. click : function(){ this.gotoLogin() }.bind(this)
  1248. }}
  1249. }
  1250. }, this.app, this.css);
  1251. this.form.load();
  1252. }.bind(this), true);
  1253. },
  1254. checkMobile: function( mobile, it ){
  1255. var flag = true;
  1256. this.actions.checkRegisterMobile( mobile, function( ){
  1257. flag = true
  1258. }.bind(this), function( errorObj ){
  1259. if( errorObj.status === 404){
  1260. it.options.validMessage.isInvalid = this.lp.pageNotFound;
  1261. flag = false;
  1262. }else{
  1263. var error = JSON.parse( errorObj.responseText );
  1264. it.options.validMessage.isInvalid = error.message;
  1265. flag = false;
  1266. }
  1267. }.bind(this), false );
  1268. return flag;
  1269. },
  1270. checkUserName: function( userName, it ){
  1271. var flag = true;
  1272. this.actions.checkRegisterName( userName, function( ){
  1273. flag = true
  1274. }.bind(this), function( errorObj ){
  1275. if( errorObj.status === 404){
  1276. it.options.validMessage.isInvalid = this.lp.pageNotFound;
  1277. flag = false
  1278. }else{
  1279. var error = JSON.parse( errorObj.responseText );
  1280. it.options.validMessage.isInvalid = error.message;
  1281. flag = false
  1282. }
  1283. }.bind(this), false );
  1284. return flag;
  1285. },
  1286. setCaptchaPic: function(){
  1287. var captchaPic = this.formTableArea.getElement("[item='captchaPic']");
  1288. captchaPic.empty();
  1289. this.actions.getRegisterCaptcha(120, 50, function( json ){
  1290. this.captcha = json.data.id;
  1291. new Element("img", {
  1292. src : "data:image/png;base64,"+json.data.image,
  1293. styles : this.css.verificationImage
  1294. }).inject( captchaPic );
  1295. }.bind(this))
  1296. },
  1297. sendVerificationAction: function(){
  1298. var flag = true;
  1299. var it = this.form.getItem("mobile");
  1300. if( it.verify( true )){
  1301. it.clearWarning();
  1302. it.getElements()[0].setStyles(this.css.inputMobile);
  1303. }else{
  1304. return;
  1305. }
  1306. this.actions.createRegisterCode( it.getValue(), function( json ){
  1307. }, function( errorObj ){
  1308. var codeIt = this.form.getItem("codeAnswer");
  1309. var error = JSON.parse( errorObj.responseText );
  1310. if( errorObj.status === 404){
  1311. codeIt.setWarning(error.message, this.lp.pageNotFound);
  1312. flag = false;
  1313. }else{
  1314. codeIt.setWarning(error.message, "invalid");
  1315. flag = false;
  1316. }
  1317. }.bind(this), false);
  1318. if( !flag )return false;
  1319. this.form.getItem("verificationAction").container.setStyle("display","none");
  1320. this.setResendVerification();
  1321. },
  1322. setResendVerification: function(){
  1323. var resendItem = this.form.getItem("resendVerificationAction");
  1324. resendItem.container.setStyle("display","");
  1325. this.resendElement = resendItem.getElements()[0];
  1326. this.resendElement.set("text", this.lp.resendVerification + "(60)");
  1327. var i=60;
  1328. this.timer = setInterval( function(){
  1329. if( i > 0 ){
  1330. this.resendElement.set("text", this.lp.resendVerification + "("+ --i +")")
  1331. }else{
  1332. this.form.getItem("verificationAction").container.setStyle("display","");
  1333. resendItem.container.setStyle("display","none");
  1334. clearInterval( this.timer )
  1335. }
  1336. }.bind(this), 1000 )
  1337. },
  1338. getPasswordRule: function( password ){
  1339. var str = "";
  1340. this.actions.checkRegisterPassword( password, function( json ){
  1341. str = json.data.value || "";
  1342. }.bind(this), null, false );
  1343. return str;
  1344. },
  1345. //createPasswordStrengthNode : function(){
  1346. // var passwordStrengthArea = this.formTableArea.getElement("[item='passwordStrengthArea']");
  1347. //
  1348. // var lowNode = new Element( "div", {styles : this.css.passwordStrengthNode }).inject( passwordStrengthArea );
  1349. // this.lowColorNode = new Element( "div", {styles : this.css.passwordStrengthColor }).inject( lowNode );
  1350. // this.lowTextNode = new Element( "div", {styles : this.css.passwordStrengthText, text : this.lp.weak }).inject( lowNode );
  1351. //
  1352. // var middleNode = new Element( "div" , {styles : this.css.passwordStrengthNode }).inject( passwordStrengthArea );
  1353. // this.middleColorNode = new Element( "div", {styles : this.css.passwordStrengthColor }).inject( middleNode );
  1354. // this.middleTextNode = new Element( "div", {styles : this.css.passwordStrengthText, text : this.lp.middle }).inject( middleNode );
  1355. //
  1356. // var highNode = new Element("div", {styles : this.css.passwordStrengthNode }).inject( passwordStrengthArea );
  1357. // this.highColorNode = new Element( "div", {styles : this.css.passwordStrengthColor }).inject( highNode );
  1358. // this.highTextNode = new Element( "div", {styles : this.css.passwordStrengthText, text : this.lp.high }).inject( highNode );
  1359. //},
  1360. //getPasswordLevel: function( password ){
  1361. // // Level(级别)
  1362. // // •0-3 : [easy]
  1363. // // •4-6 : [midium]
  1364. // // •7-9 : [strong]
  1365. // // •10-12 : [very strong]
  1366. // // •>12 : [extremely strong]
  1367. // var level = 0;
  1368. // this.actions.checkRegisterPassword( password, function( json ){
  1369. // level = json.data.value;
  1370. // }.bind(this), null, false );
  1371. // return level;
  1372. //},
  1373. //pwStrength: function(pwd){
  1374. // this.lowColorNode.setStyles( this.css.passwordStrengthColor );
  1375. // this.lowTextNode.setStyles( this.css.passwordStrengthText );
  1376. // this.middleColorNode.setStyles( this.css.passwordStrengthColor );
  1377. // this.middleTextNode.setStyles( this.css.passwordStrengthText );
  1378. // this.highColorNode.setStyles( this.css.passwordStrengthColor );
  1379. // this.highTextNode.setStyles( this.css.passwordStrengthText );
  1380. // if (!pwd){
  1381. // }else{
  1382. // //var level = this.checkStrong(pwd);
  1383. // var level = this.getPasswordLevel(pwd);
  1384. // switch(level) {
  1385. // case 0:
  1386. // case 1:
  1387. // case 2:
  1388. // case 3:
  1389. // this.lowColorNode.setStyles( this.css.passwordStrengthColor_low );
  1390. // this.lowTextNode.setStyles( this.css.passwordStrengthText_current );
  1391. // break;
  1392. // case 4:
  1393. // case 5:
  1394. // case 6:
  1395. // this.middleColorNode.setStyles( this.css.passwordStrengthColor_middle );
  1396. // this.middleTextNode.setStyles( this.css.passwordStrengthText_current );
  1397. // break;
  1398. // default:
  1399. // this.highColorNode.setStyles( this.css.passwordStrengthColor_high );
  1400. // this.highTextNode.setStyles( this.css.passwordStrengthText_current );
  1401. // }
  1402. // }
  1403. //},
  1404. gotoLogin: function(){
  1405. this.explorer.openLoginForm( {}, function(){ window.location.reload(); } );
  1406. this.close();
  1407. },
  1408. setWarning : function(text){
  1409. this.tipNode.empty();
  1410. new Element("div",{
  1411. "text" : text,
  1412. "styles" : this.css.warningMessageNode
  1413. }).inject( this.tipNode );
  1414. },
  1415. setNotice : function(text){
  1416. this.tipNode.empty();
  1417. new Element("div",{
  1418. "text" : text,
  1419. "styles" : this.css.noticeMessageNode
  1420. }).inject( this.tipNode );
  1421. },
  1422. ok: function () {
  1423. this.tipNode.empty();
  1424. this.fireEvent("queryOk");
  1425. var data = this.form.getResult(true, ",", true, false, true);
  1426. if (data) {
  1427. this._ok(data, function (json) {
  1428. if (json.type === "error") {
  1429. if(this.app)this.app.notice(json.message, "error");
  1430. } else {
  1431. if(this.formMaskNode)this.formMaskNode.destroy();
  1432. this.formAreaNode.destroy();
  1433. this.setNotice( this.lp.registeSuccess );
  1434. if(this.app)this.app.notice( this.lp.registeSuccess, "success");
  1435. this.fireEvent("postOk", json);
  1436. this.gotoLogin();
  1437. }
  1438. }.bind(this))
  1439. }
  1440. },
  1441. _ok: function (data, callback) {
  1442. data.captcha = this.captcha;
  1443. this.actions.register( data, function(json){
  1444. if( callback )callback( json );
  1445. }.bind(this), function( errorObj ){
  1446. if( errorObj.status === 404){
  1447. this.setWarning(this.lp.pageNotFound);
  1448. }else{
  1449. var error = JSON.parse( errorObj.responseText );
  1450. this.setWarning(error.message);
  1451. }
  1452. }.bind(this) );
  1453. }
  1454. });
  1455. MWF.xDesktop.Authentication.ResetPasswordForm = new Class({
  1456. Extends: MPopupForm,
  1457. Implements: [Options, Events],
  1458. options: {
  1459. "style": "default",
  1460. "popupStyle" : "o2platformSignup",
  1461. "width": "710",
  1462. "height": "450",
  1463. "hasTop": true,
  1464. "hasIcon": false,
  1465. "hasTopIcon" : true,
  1466. "hasTopContent" : true,
  1467. "hasBottom": false,
  1468. "title": MWF.LP.authentication.ResetPasswordFormTitle,
  1469. "draggable": true,
  1470. "closeAction": true
  1471. },
  1472. _createTopContent: function(){
  1473. this.actions = MWF.Actions.get("x_organization_assemble_personal");
  1474. this.actions.getRegisterMode(function(json){
  1475. this.signUpMode = json.data.value;
  1476. }.bind(this), null ,false);
  1477. if( this.signUpMode && this.signUpMode!=="disable" ){
  1478. this.gotoSignupNode = new Element("div", {
  1479. styles : this.css.formTopContentCustomNode,
  1480. text : this.lp.signUp
  1481. }).inject( this.formTopContentNode );
  1482. this.gotoSignupNode.addEvent( "click", function(){ this.gotoSignup() }.bind(this) );
  1483. new Element("div", {styles : this.css.formTopContentSepNode}).inject( this.formTopContentNode );
  1484. }
  1485. this.gotoLoginNode = new Element("div", {
  1486. styles : this.css.formTopContentCustomNode,
  1487. text : this.lp.loginAction
  1488. }).inject( this.formTopContentNode );
  1489. this.gotoLoginNode.addEvent( "click", function(){ this.gotoLogin() }.bind(this) );
  1490. },
  1491. _createTableContent: function () {
  1492. this.formTableContainer.setStyles( this.css.formTableContainer2 );
  1493. this.loadSteps();
  1494. this.loadStepForm_1();
  1495. this.loadStepForm_2();
  1496. this.loadStepForm_3();
  1497. },
  1498. reset: function(){
  1499. this.formTableArea.empty();
  1500. this._createTableContent();
  1501. },
  1502. loadSteps: function() {
  1503. var stepsContainer = new Element("div", { styles : this.css.stepsContainer }).inject( this.formTableArea );
  1504. this.step_1 = new Element( "div", {
  1505. styles : this.css.step_1_active,
  1506. text : this.lp.shotMessageCheck
  1507. }).inject(stepsContainer);
  1508. this.stepLink_1 = new Element( "div", { styles : this.css.stepLink_1 }).inject(this.step_1);
  1509. this.step_2 = new Element( "div", {
  1510. styles : this.css.step_2,
  1511. text : this.lp.setMewPassword
  1512. }).inject(stepsContainer);
  1513. this.stepLink_2 = new Element( "div", { styles : this.css.stepLink_2 }).inject(this.step_2);
  1514. this.step_3 = new Element( "div", {
  1515. styles : this.css.step_3,
  1516. text : this.lp.completed
  1517. }).inject(stepsContainer);
  1518. },
  1519. loadStepForm_1: function(){
  1520. var html = "<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>" +
  1521. "<tr><td styles='formTableTitle' lable='name' width='80'></td>" +
  1522. " <td styles='formTableValue' item='name' width='350'></td></tr>" +
  1523. "<tr><td styles='formTableTitle' lable='codeAnswer'></td>" +
  1524. " <td styles='formTableValue'>" +
  1525. " <div item='codeAnswer' style='float:left;'></div>" +
  1526. " <div item='verificationAction' style='float:left;'></div>" +
  1527. " <div item='resendVerificationAction' style='float:left;display:none;'></div></td>" +
  1528. " </tr>"+
  1529. "<tr><td styles='formTableTitle'></td>" +
  1530. " <td styles='formTableValue' item='nextStep'></td></tr>" +
  1531. "</table>";
  1532. this.stepNode_1 = new Element("div", {html: html , styles : {display:""} }).inject(this.formTableArea );
  1533. MWF.xDesktop.requireApp("Template", "MForm", function () {
  1534. this.stepForm_1 = new MForm(this.stepNode_1, {}, {
  1535. style: this.options.popupStyle,
  1536. verifyType : "single", //batch一起校验,或alert弹出
  1537. isEdited: this.isEdited || this.isNew,
  1538. itemTemplate: {
  1539. name: { text: this.lp.userName, defaultValue : this.lp.userName, className : "inputUser",
  1540. notEmpty : true, defaultValueAsEmpty: true, emptyTip: this.lp.inputYourUserName,
  1541. validRule : { isInvalid: function( value, it ){ return this.checkUserName( value, it ); }.bind(this)},
  1542. validMessage : { isInvalid : this.lp.userNotExist },
  1543. event : {
  1544. focus : function( it ){ if( this.lp.userName === it.getValue() )it.setValue(""); if( !it.warningStatus )it.getElements()[0].setStyles( this.css.inputActive ); }.bind(this),
  1545. blur: function (it) { if( it.getValue() === "" )it.setValue( this.lp.userName ); if( !it.warningStatus )it.getElements()[0].setStyles( this.css.inputUser ); }.bind(this),
  1546. keyup : function( it, ev ){ if( ev.event.keyCode === 13 ){ this.gotoStep( 2 ) } }.bind(this)
  1547. }, onEmpty : function( it ){
  1548. it.getElements()[0].setStyles( this.css.inputEmpty );
  1549. }.bind(this), onUnempty : function( it ){
  1550. it.getElements()[0].setStyles( this.css.inputUser );
  1551. }.bind(this) },
  1552. codeAnswer : { text: this.lp.verificationCode, defaultValue : this.lp.inputVerificationCode, className : "inputVerificationCode2",
  1553. notEmpty : true,defaultValueAsEmpty: true, emptyTip: this.lp.inputVerificationCode, event : {
  1554. focus : function( it ){ if( this.lp.inputVerificationCode === it.getValue() )it.setValue(""); if( !it.warningStatus )it.getElements()[0].setStyles( this.css.inputActive ); }.bind(this),
  1555. blur: function (it) {
  1556. if( it.getValue() === "" )it.setValue( this.lp.inputVerificationCode );
  1557. if( !it.warningStatus )it.getElements()[0].setStyles( this.css.inputVerificationCode2 );
  1558. }.bind(this),
  1559. keyup : function( it, ev ){ if( ev.event.keyCode === 13 ){ this.gotoStep( 2 ) } }.bind(this)
  1560. }, onEmpty : function( it ){
  1561. it.getElements()[0].setStyles( this.css.inputEmpty );
  1562. }.bind(this), onUnempty : function( it ){
  1563. it.getElements()[0].setStyles( this.css.inputVerificationCode2 );
  1564. }.bind(this) },
  1565. verificationAction : {value: this.lp.sendVerification, type : "button", className : "inputSendVerification", event : {
  1566. click : function(){ this.sendVerificationAction() }.bind(this)
  1567. } },
  1568. resendVerificationAction : {value: this.lp.resendVerification, type : "button", className : "inputResendVerification"},
  1569. nextStep: {value: this.lp.nextStep, type : "button", className : "inputSignUp", event : {
  1570. click : function(){ this.gotoStep( 2 ) }.bind(this)
  1571. } }
  1572. }
  1573. }, this.app, this.css);
  1574. this.stepForm_1.load();
  1575. }.bind(this), true);
  1576. },
  1577. loadStepForm_2 : function(){
  1578. var self = this;
  1579. html = "<table width='100%' bordr='0' cellpadding='5' cellspacing='0' styles='formTable'>" +
  1580. "<tr><td styles='formTableTitle' lable='password' width='80'></td>" +
  1581. " <td styles='formTableValue' item='password' width='350'></td>" +
  1582. " <td styles='formTableValue'><div item='passwordStrengthArea'></div></td></tr>" +
  1583. "<tr><td styles='formTableTitle' lable='confirmPassword'></td>" +
  1584. " <td styles='formTableValue' item='confirmPassword'></td>" +
  1585. " <td styles='formTableValue'></td></tr>" +
  1586. "<tr><td styles='formTableTitle'></td>" +
  1587. " <td styles='formTableValue' item='nextStep'></td>"+
  1588. " <td styles='formTableValue'></td></tr>" +
  1589. "</table>";
  1590. this.stepNode_2 = new Element("div", {
  1591. html: html,
  1592. styles : { "display" : "none" }
  1593. }).inject(this.formTableArea );
  1594. MWF.xDesktop.requireApp("Template", "MForm", function () {
  1595. this.stepForm_2 = new MForm(this.stepNode_2, {}, {
  1596. style: "o2platformSignup",
  1597. verifyType : "single", //batch一起校验,或alert弹出
  1598. isEdited: this.isEdited || this.isNew,
  1599. itemTemplate: {
  1600. password : { text: this.lp.setNewPassword, type : "password", className : "inputPassword",
  1601. notEmpty : true, defaultValueAsEmpty: true, emptyTip: this.lp.inputYourPassword,
  1602. validRule : { passwordIsWeak: function( value, it ){
  1603. return !this.getPasswordRule( it.getValue() );
  1604. }.bind(this)},
  1605. validMessage : { passwordIsWeak : function(){
  1606. return self.getPasswordRule( this.getValue() );
  1607. }},
  1608. event : {
  1609. focus : function( it ){ if( "password" === it.getValue() )it.setValue(""); if( !it.warningStatus )it.getElements()[0].setStyles( this.css.inputActive ); }.bind(this),
  1610. blur : function( it ){ it.verify(true); }.bind(this)
  1611. //if( !it.warningStatus )it.getElements()[0].setStyles( this.css.inputPassword );
  1612. //keyup : function(it){ this.pwStrength(it.getValue()) }.bind(this)
  1613. }, onEmpty : function( it ){
  1614. it.getElements()[0].setStyles( this.css.inputEmpty );
  1615. }.bind(this), onUnempty : function( it ){
  1616. it.getElements()[0].setStyles( this.css.inputPassword );
  1617. }.bind(this) },
  1618. confirmPassword : { text: this.lp.confirmNewPassword, type : "password", className : "inputComfirmPassword",
  1619. notEmpty : true,defaultValueAsEmpty: true, emptyTip: this.lp.inputComfirmPassword,
  1620. validRule : { passwordNotEqual: function( value, it ){
  1621. if( it.getValue() === this.stepForm_2.getItem("password").getValue() )return true;
  1622. }.bind(this)},
  1623. validMessage : { passwordNotEqual : this.lp.passwordNotEqual },
  1624. event : {
  1625. focus : function( it ){ if( "password" === it.getValue() )it.setValue(""); if( !it.warningStatus )it.getElements()[0].setStyles( this.css.inputActive ); }.bind(this),
  1626. blur : function( it ){ if( !it.warningStatus )it.getElements()[0].setStyles( this.css.inputComfirmPassword ); }.bind(this),
  1627. keyup : function( it, ev ){ if( ev.event.keyCode === 13 ){ this.gotoStep( 3 ) } }.bind(this)
  1628. }, onEmpty : function( it ){
  1629. it.getElements()[0].setStyles( this.css.inputEmpty );
  1630. }.bind(this), onUnempty : function( it ){
  1631. it.getElements()[0].setStyles( this.css.inputComfirmPassword );
  1632. }.bind(this) },
  1633. nextStep: {value: this.lp.nextStep, type : "button", className : "inputSignUp", event : {
  1634. click : function(){ this.gotoStep( 3 ) }.bind(this)
  1635. } }
  1636. }
  1637. }, this.app, this.css);
  1638. this.stepForm_2.load();
  1639. }.bind(this), true);
  1640. //this.createPasswordStrengthNode();
  1641. },
  1642. loadStepForm_3: function(){
  1643. this.stepNode_3 = new Element("div", {
  1644. styles : this.css.stepFormResult
  1645. }).inject(this.formTableArea );
  1646. },
  1647. createSetForm_3 : function( isSuccess, text ){
  1648. var area = null;
  1649. var action = null;
  1650. if( isSuccess ){
  1651. this.stepNode_3.setStyles( this.css.stepFormResult );
  1652. this.stepNode_3.setStyle("display","");
  1653. new Element("div", {
  1654. styles : this.css.resetPasswordSuccess,
  1655. text : this.lp.resetPasswordSuccess
  1656. }).inject( this.stepNode_3 );
  1657. area = new Element("div", {
  1658. styles : this.css.resetPasswordResultArea
  1659. }).inject( this.stepNode_3 );
  1660. new Element("div", {
  1661. styles : this.css.resetPasswordResultWord,
  1662. text : this.lp.resetPasswordSuccessWord
  1663. }).inject( area );
  1664. action = new Element("div", {
  1665. styles : this.css.resetPasswordResultAction,
  1666. text : this.lp.gotoLogin
  1667. }).inject( area );
  1668. action.addEvent("click", function(){ this.gotoLogin() }.bind(this));
  1669. }else{
  1670. this.stepNode_3.setStyles( this.css.stepFormResult_fail );
  1671. this.stepNode_3.setStyle("display","");
  1672. new Element("div", {
  1673. styles : this.css.resetPasswordFail,
  1674. text : text + this.lp.resetPasswordFail
  1675. }).inject( this.stepNode_3 );
  1676. area = new Element("div", {
  1677. styles : this.css.resetPasswordResultArea
  1678. }).inject( this.stepNode_3 );
  1679. new Element("div", {
  1680. styles : this.css.resetPasswordResultWord,
  1681. text : this.lp.resetPasswordFailWord
  1682. }).inject( area );
  1683. action = new Element("div", {
  1684. styles : this.css.resetPasswordResultAction,
  1685. text : this.lp.backtoModify
  1686. }).inject( area );
  1687. action.addEvent("click", function(){ this.reset() }.bind(this));
  1688. }
  1689. },
  1690. gotoStep: function( step ){
  1691. var form = this["stepForm_"+(step-1)];
  1692. form.clearWarning();
  1693. var data = form.getResult(true, ",", true, false, true);
  1694. if( !data ){
  1695. return;
  1696. }
  1697. var i;
  1698. for( i = 1; i<=step; i++ ){
  1699. this["step_"+i].setStyles( this.css["step_"+i+"_active"] );
  1700. if( i!==step && this["stepLink_"+i]){
  1701. this["stepLink_"+i].setStyles( this.css["stepLink_"+i+"_active"] );
  1702. }
  1703. }
  1704. for( i = step+1; i<=3; i++ ){
  1705. this["step_"+i].setStyles( this.css["step_"+i] );
  1706. if( i!==3 ){
  1707. this["stepLink_"+i].setStyles( this.css["stepLink_"+i] );
  1708. }
  1709. }
  1710. for( i = 1; i<=3; i++ ){
  1711. if( i===step ){
  1712. this["stepNode_"+i].setStyle( "display" , "" );
  1713. }else{
  1714. this["stepNode_"+i].setStyle( "display" , "none" );
  1715. }
  1716. }
  1717. if( step === 3 ){
  1718. var d = {
  1719. credential : this.stepForm_1.getItem("name").getValue(),
  1720. codeAnswer : this.stepForm_1.getItem("codeAnswer").getValue(),
  1721. password : this.stepForm_2.getItem("password").getValue()
  1722. };
  1723. this.actions.resetPassword( d, function( ){
  1724. this.createSetForm_3( true )
  1725. }.bind(this), function( errorObj ){
  1726. var error = JSON.parse( errorObj.responseText );
  1727. //this.app.notice( error.message );
  1728. this.createSetForm_3( false, error.message )
  1729. }.bind(this), false );
  1730. }
  1731. },
  1732. checkMobile: function( mobile ){
  1733. var flag = true;
  1734. this.actions.checkRegisterMobile( mobile, function(){
  1735. flag = true
  1736. }.bind(this), function(){
  1737. flag = false;
  1738. }.bind(this), false );
  1739. return flag;
  1740. },
  1741. checkUserName: function( userName, it ){
  1742. var flag = false;
  1743. this.actions.checkCredentialOnResetPassword( userName, function( json ){
  1744. if( json.data ){
  1745. flag = json.data.value;
  1746. }
  1747. }.bind(this), function( errorObj ){
  1748. if( errorObj.status === 404){
  1749. it.options.validMessage.isInvalid = this.lp.pageNotFound;
  1750. flag = false
  1751. }else{
  1752. var error = JSON.parse( errorObj.responseText );
  1753. it.options.validMessage.isInvalid = error.message;
  1754. flag = false
  1755. }
  1756. }.bind(this), false );
  1757. return flag;
  1758. },
  1759. sendVerificationAction: function(){
  1760. var flag = true;
  1761. var it = this.stepForm_1.getItem("name");
  1762. this.stepForm_1.clearWarning();
  1763. if( it.verify( true )){
  1764. }else{
  1765. return;
  1766. }
  1767. this.actions.createCodeOnResetPassword( it.getValue(), function( json ){
  1768. }, function( errorObj ){
  1769. var error = JSON.parse( errorObj.responseText );
  1770. it.setWarning(error.message, "invalid");
  1771. flag = false
  1772. }.bind(this), false);
  1773. if( !flag )return false;
  1774. this.stepForm_1.getItem("verificationAction").container.setStyle("display","none");
  1775. this.setResendVerification();
  1776. },
  1777. setResendVerification: function(){
  1778. var resendItem = this.stepForm_1.getItem("resendVerificationAction");
  1779. resendItem.container.setStyle("display","");
  1780. this.resendElement = resendItem.getElements()[0];
  1781. this.resendElement.set("text", this.lp.resendVerification + "(60)");
  1782. var i=60;
  1783. this.timer = setInterval( function(){
  1784. if( i > 0 ){
  1785. this.resendElement.set("text", this.lp.resendVerification + "("+ --i +")")
  1786. }else{
  1787. this.stepForm_1.getItem("verificationAction").container.setStyle("display","");
  1788. resendItem.container.setStyle("display","none");
  1789. clearInterval( this.timer )
  1790. }
  1791. }.bind(this), 1000 )
  1792. },
  1793. getPasswordRule: function( password ){
  1794. var str = "";
  1795. this.actions.checkRegisterPassword( password, function( json ){
  1796. str = json.data.value || "";
  1797. }.bind(this), null, false );
  1798. return str;
  1799. },
  1800. //createPasswordStrengthNode : function(){
  1801. // var passwordStrengthArea = this.formTableArea.getElement("[item='passwordStrengthArea']");
  1802. //
  1803. // var lowNode = new Element( "div", {styles : this.css.passwordStrengthNode }).inject( passwordStrengthArea );
  1804. // this.lowColorNode = new Element( "div", {styles : this.css.passwordStrengthColor }).inject( lowNode );
  1805. // this.lowTextNode = new Element( "div", {styles : this.css.passwordStrengthText, text : this.lp.weak }).inject( lowNode );
  1806. //
  1807. // var middleNode = new Element( "div" , {styles : this.css.passwordStrengthNode }).inject( passwordStrengthArea );
  1808. // this.middleColorNode = new Element( "div", {styles : this.css.passwordStrengthColor }).inject( middleNode );
  1809. // this.middleTextNode = new Element( "div", {styles : this.css.passwordStrengthText, text : this.lp.middle }).inject( middleNode );
  1810. //
  1811. // var highNode = new Element("div", {styles : this.css.passwordStrengthNode }).inject( passwordStrengthArea );
  1812. // this.highColorNode = new Element( "div", {styles : this.css.passwordStrengthColor }).inject( highNode );
  1813. // this.highTextNode = new Element( "div", {styles : this.css.passwordStrengthText, text : this.lp.high }).inject( highNode );
  1814. //},
  1815. //getPasswordLevel: function( password ){
  1816. // /*Level(级别)
  1817. // •0-3 : [easy]
  1818. // •4-6 : [midium]
  1819. // •7-9 : [strong]
  1820. // •10-12 : [very strong]
  1821. // •>12 : [extremely strong]
  1822. // */
  1823. // var level = 0;
  1824. // this.actions.checkRegisterPassword( password, function( json ){
  1825. // level = json.data.value;
  1826. // }.bind(this), null, false );
  1827. // return level;
  1828. //},
  1829. //pwStrength: function(pwd){
  1830. // this.lowColorNode.setStyles( this.css.passwordStrengthColor );
  1831. // this.lowTextNode.setStyles( this.css.passwordStrengthText );
  1832. // this.middleColorNode.setStyles( this.css.passwordStrengthColor );
  1833. // this.middleTextNode.setStyles( this.css.passwordStrengthText );
  1834. // this.highColorNode.setStyles( this.css.passwordStrengthColor );
  1835. // this.highTextNode.setStyles( this.css.passwordStrengthText );
  1836. // if (!pwd){
  1837. // }else{
  1838. // //var level = this.checkStrong(pwd);
  1839. // var level = this.getPasswordLevel(pwd);
  1840. // switch(level) {
  1841. // case 0:
  1842. // case 1:
  1843. // case 2:
  1844. // case 3:
  1845. // this.lowColorNode.setStyles( this.css.passwordStrengthColor_low );
  1846. // this.lowTextNode.setStyles( this.css.passwordStrengthText_current );
  1847. // break;
  1848. // case 4:
  1849. // case 5:
  1850. // case 6:
  1851. // this.middleColorNode.setStyles( this.css.passwordStrengthColor_middle );
  1852. // this.middleTextNode.setStyles( this.css.passwordStrengthText_current );
  1853. // break;
  1854. // default:
  1855. // this.highColorNode.setStyles( this.css.passwordStrengthColor_high );
  1856. // this.highTextNode.setStyles( this.css.passwordStrengthText_current );
  1857. // }
  1858. // }
  1859. //},
  1860. gotoLogin: function(){
  1861. this.explorer.openLoginForm( {}, function(){ window.location.reload(); } );
  1862. this.close();
  1863. },
  1864. gotoSignup: function(){
  1865. this.explorer.openSignUpForm();
  1866. this.close();
  1867. }
  1868. });