Guest User

Untitled

a guest
Jun 14th, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. //This is the function that takes log in credentials from AS form and prepares for php
  2. //run doLogin() if user clicks the login button
  3. function loginViaClick(e:MouseEvent):void
  4. {
  5. doLogin();
  6. }
  7.  
  8. //logs a user in
  9. function doLogin():void
  10.  
  11. {
  12. if(userfield.text == "" || passfield.text == "")
  13. {
  14. status_txt.text = "All fields are Required!";
  15. }
  16. else
  17. {
  18. //enable the preloader dots
  19. dots.visible = true;
  20. dots.play();
  21. //disable all text fields and buttons for now.
  22. //collect variables and send them to the location of login.php
  23. userfield.enabled = false;
  24. passfield.enabled = false;
  25. loginBtn.enabled = false;
  26. remember.enabled = false;
  27. var variables:URLVariables = new URLVariables();
  28. //variables.username and password is what gets sent to php script
  29. variables.username = userfield.text;
  30. variables.password = passfield.text;
  31. if(remember.selected == true)
  32. {
  33. variables.cookie = userfield.text;
  34. }
  35. var req:URLRequest = new URLRequest((this.parent as MovieClip).loginLocation);
  36. req.method = URLRequestMethod.POST;
  37. req.data = variables;
  38.  
  39. var loader:URLLoader = new URLLoader();
  40. loader.dataFormat = URLLoaderDataFormat.VARIABLES;
  41. loader.addEventListener(Event.COMPLETE, onDataIn);
  42. loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
  43.  
  44. try
  45. {
  46. loader.load(req);
  47. } catch (error:Error) {
  48. //occurs if we cant locate login.php
  49. dots.visible = false;
  50. dots.stop();
  51. userfield.enabled = true;
  52. passfield.enabled = true;
  53. loginBtn.enabled = true;
  54. remember.enabled = true;
  55. trace("Unable to load URL");
  56. }
  57. }
  58. }
  59.  
  60. //onDataIn refers to what login.php sends back to Flash!!!
  61. function onDataIn(e:Event)
  62. {
  63. var loader:URLLoader = URLLoader(e.target);
  64. //loader.data.result is refering to echo "result=value" in login.php
  65. var result = loader.data.result;
  66. dots.visible = false;
  67. dots.stop();
  68. //so if result=fail...
  69. if (result == "fail")
  70. {
  71. userfield.enabled = true;
  72. passfield.enabled = true;
  73. loginBtn.enabled = true;
  74. remember.enabled = true;
  75. status_txt.text = "Invalid Username/Password!";
  76. }
  77. else if (result == "notactive")
  78. {
  79. userfield.enabled = true;
  80. passfield.enabled = true;
  81. loginBtn.enabled = true;
  82. remember.enabled = true;
  83. status_txt.text = "Your account is not active.";
  84. }
  85. else if (result == "success")
  86. {
  87. /*
  88. * else they successfully logged in.
  89. * Now lets create a temp Object
  90. * then put that temp object into the userInfo object
  91. * We now have all the users data in one little object =)
  92. */
  93. var tempObj:Object = new Object();
  94. var n = loader.data;
  95. //tempObj.clienttype = n.clienttype
  96. //tempObj.clientnum = n.clientnum;
  97. tempObj.username = n.username;
  98. tempObj.email = n.email;
  99. tempObj.firstname = n.firstname;
  100. tempObj.lastname = n.lastname;
  101. tempObj.address1 = n.address1;
  102. tempObj.fax = n.fax;
  103. tempObj.city = n.city;
  104. tempObj.role = n.role;
  105. tempObj.zip = n.zip;
  106. tempObj.phone = n.phone;
  107. tempObj.contactphone = n.contactphone;
  108. tempObj.orgname = n.orgname;
  109. tempObj.district = n.district;
  110. tempObj.estlawn = n.estlawn;
  111. tempObj.preferday = n.preferday;
  112. tempObj.pmtpref = n.pmtpref;
  113. tempObj.date_added = n.date_added;
  114. (this.parent as MovieClip).userInfo = tempObj;
  115. (this.parent as MovieClip).gotoAndStop("loggedIn");
  116. }
  117.  
  118. else (result == "suppsuccess")
  119. {
  120. /*
  121. * else they successfully logged in.
  122. * Now lets create a temp Object
  123. * then put that temp object into the userInfo object
  124. * We now have all the users data in one little object =)
  125. */
  126. var tempObjp:Object = new Object();
  127. var p = loader.data;
  128. //tempObj.clienttype = n.clienttype
  129. //tempObj.clientnum = n.clientnum;
  130. tempObjp.username = p.username;
  131. tempObjp.email = p.email;
  132. tempObjp.firstname = p.firstname;
  133. tempObjp.lastname = p.lastname;
  134. tempObjp.address1 = p.address1;
  135. tempObjp.fax = p.fax;
  136. tempObjp.city = p.city;
  137. tempObjp.role = p.role;
  138. tempObjp.zip = p.zip;
  139. tempObjp.phone = p.phone;
  140. tempObjp.contactphone = p.contactphone;
  141. tempObjp.orgname = p.orgname;
  142. tempObjp.district = p.district;
  143. tempObjp.estlawn = p.estlawn;
  144. tempObjp.preferday = p.preferday;
  145. tempObjp.pmtpref = p.pmtpref;
  146. tempObjp.date_added = p.date_added;
  147. (this.parent as MovieClip).userInfoS = tempObjp;
  148. (this.parent as MovieClip).gotoAndStop("loggedInsupp");
  149. }
  150.  
  151. }
Add Comment
Please, Sign In to add comment