Authentication.js 91 KB

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