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