Authentication.js 90 KB

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