Guest User

Untitled

a guest
Apr 11th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. <?
  2.  
  3. require_once('header.php');
  4.  
  5. $userinfo = $SDK->get_info();
  6.  
  7. if ($SDK->is_loggedin()=="1")
  8. {
  9. $loggedin = true;
  10.  
  11. $username = $userinfo['name'];
  12.  
  13. }
  14.  
  15. $xajax->register(XAJAX_FUNCTION, processLogin);
  16. $xajax->register(XAJAX_FUNCTION, logout);
  17.  
  18. $xajax->register(XAJAX_FUNCTION, show);
  19. $xajax->register(XAJAX_FUNCTION, hide);
  20.  
  21. function show() {
  22. global $SDK;
  23. global $smarty;
  24. $objResponse = new xajaxResponse();
  25. $linkhtml = "<a onclick=\"xajax_hide();\" id=\"loginlink\" href=\"#\">^Hide Login Box^</a><br />";
  26. $objResponse->Assign("loginlink","innerHTML",$linkhtml);
  27. $objResponse->Script("document.getElementById('login').style.display='inline'; ");
  28. return $objResponse;
  29. }
  30.  
  31. function hide() {
  32. global $SDK;
  33. global $smarty;
  34. $objResponse = new xajaxResponse();
  35. $linkhtml = "<a onclick=\"xajax_show();\" id=\"loginlink\" href=\"#\">^Show Login Box^</a><br />";
  36. $objResponse->Assign("loginlink","innerHTML",$linkhtml);
  37. $objResponse->Script("document.getElementById('login').style.display='none'; ");
  38. return $objResponse;
  39. }
  40.  
  41. function processLogin($aFormValues)
  42. {
  43. global $SDK;
  44. global $smarty;
  45. $objResponse = new xajaxResponse();
  46. // The form was submitted. Lets authenticate!
  47. if (trim($aFormValues['username']) == "" && trim($aFormValues['password']) == "")
  48. {
  49. $smarty->assign('loginMsg', "Please fill in all of the form fields to login");
  50. $bError = true;
  51. }
  52.  
  53. else {
  54.  
  55. if (trim($aFormValues['username']) == "")
  56. {
  57.  
  58. $smarty->assign('loginMsg', "Please enter your username");
  59. $bError = true;
  60.  
  61. }
  62. if (trim($aFormValues['password']) == "")
  63. {
  64.  
  65. $smarty->assign('loginMsg', "Please enter your password");
  66. $bError = true;
  67.  
  68. }
  69.  
  70. }
  71. if(!$bError)
  72. {
  73. $username = trim($aFormValues['username']);
  74. $password = trim($aFormValues['password']);
  75. if ($SDK->login($username, $password))
  76. {
  77.  
  78. // The login worked.
  79. $loginhtml = "You are logged in as <b>" . $username . "</b>. <br> <form id=\"logout\" action=\"javascript:void(null);\" onsubmit=\"submitLogout();\">
  80. <input value=\"Logout\" name=\"logout\" id=\"logoutButton\" type=\"submit\">
  81. </form>";
  82. $objResponse->Assign("login","innerHTML",$loginhtml);
  83. $smarty->assign('loginMsg', "You have been logged in...");
  84. $smarty->fetch('templates/index.tpl');
  85. $objResponse->Script("document.getElementById('loginMsg').style.display='inline';
  86. setTimeout(\"document.getElementById('loginMsg').style.display='none'\",3000); ");
  87.  
  88. }
  89. else
  90. {
  91.  
  92. $smarty->assign('loginMsg', "Please fill in all of the form fields to login");
  93. $objResponse->Assign("loginButton","value","Login");
  94. $objResponse->Assign("loginButton","disabled",false);
  95. $objResponse->Script("document.getElementById('loginMsg').style.display='inline';
  96. setTimeout(\"document.getElementById('loginMsg').style.display='none'\",3000); ");
  97.  
  98. }
  99. }
  100. else
  101. {
  102.  
  103. $objResponse->Assign("loginButton","value","Login");
  104. $objResponse->Assign("loginButton","disabled",false);
  105.  
  106. }
  107.  
  108. return $objResponse;
  109.  
  110. }
  111.  
  112. function logout()
  113. {
  114. global $SDK;
  115. global $smarty;
  116. $objResponse = new xajaxResponse();
  117.  
  118. $SDK->logout();
  119.  
  120.  
  121. $loginhtml = "You are currently a <b>Guest</b>.<form id=\"loginbox\" action=\"javascript:void(null);\" onsubmit=\"submitLogin();\">
  122. Username:<input type=\"text\" id=\"username\" name=\"username\">
  123. Password:<input type=\"password\" id=\"password\" name=\"password\">
  124. <input value=\"Login\" name=\"submit\" id=\"loginButton\" type=\"submit\">
  125. </form>";
  126. $objResponse->Assign("login","innerHTML",$loginhtml);
  127. $smarty->assign('loginMsg', "You have been logged out...");
  128. $objResponse->Script("document.getElementById('loginMsg').style.display='inline';
  129. setTimeout(\"document.getElementById('loginMsg').style.display='none'\",3000); ");
  130.  
  131.  
  132.  
  133. return $objResponse;
  134.  
  135. }
  136. $xajax->processRequest();
  137.  
  138. ?>
Add Comment
Please, Sign In to add comment