Authentication.js 91 KB

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