Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- require_once('header.php');
- $userinfo = $SDK->get_info();
- if ($SDK->is_loggedin()=="1")
- {
- $loggedin = true;
- $username = $userinfo['name'];
- }
- $xajax->register(XAJAX_FUNCTION, processLogin);
- $xajax->register(XAJAX_FUNCTION, logout);
- $xajax->register(XAJAX_FUNCTION, show);
- $xajax->register(XAJAX_FUNCTION, hide);
- function show() {
- global $SDK;
- global $smarty;
- $objResponse = new xajaxResponse();
- $linkhtml = "<a onclick=\"xajax_hide();\" id=\"loginlink\" href=\"#\">^Hide Login Box^</a><br />";
- $objResponse->Assign("loginlink","innerHTML",$linkhtml);
- $objResponse->Script("document.getElementById('login').style.display='inline'; ");
- return $objResponse;
- }
- function hide() {
- global $SDK;
- global $smarty;
- $objResponse = new xajaxResponse();
- $linkhtml = "<a onclick=\"xajax_show();\" id=\"loginlink\" href=\"#\">^Show Login Box^</a><br />";
- $objResponse->Assign("loginlink","innerHTML",$linkhtml);
- $objResponse->Script("document.getElementById('login').style.display='none'; ");
- return $objResponse;
- }
- function processLogin($aFormValues)
- {
- global $SDK;
- global $smarty;
- $objResponse = new xajaxResponse();
- // The form was submitted. Lets authenticate!
- if (trim($aFormValues['username']) == "" && trim($aFormValues['password']) == "")
- {
- $smarty->assign('loginMsg', "Please fill in all of the form fields to login");
- $bError = true;
- }
- else {
- if (trim($aFormValues['username']) == "")
- {
- $smarty->assign('loginMsg', "Please enter your username");
- $bError = true;
- }
- if (trim($aFormValues['password']) == "")
- {
- $smarty->assign('loginMsg', "Please enter your password");
- $bError = true;
- }
- }
- if(!$bError)
- {
- $username = trim($aFormValues['username']);
- $password = trim($aFormValues['password']);
- if ($SDK->login($username, $password))
- {
- // The login worked.
- $loginhtml = "You are logged in as <b>" . $username . "</b>. <br> <form id=\"logout\" action=\"javascript:void(null);\" onsubmit=\"submitLogout();\">
- <input value=\"Logout\" name=\"logout\" id=\"logoutButton\" type=\"submit\">
- </form>";
- $objResponse->Assign("login","innerHTML",$loginhtml);
- $smarty->assign('loginMsg', "You have been logged in...");
- $smarty->fetch('templates/index.tpl');
- $objResponse->Script("document.getElementById('loginMsg').style.display='inline';
- setTimeout(\"document.getElementById('loginMsg').style.display='none'\",3000); ");
- }
- else
- {
- $smarty->assign('loginMsg', "Please fill in all of the form fields to login");
- $objResponse->Assign("loginButton","value","Login");
- $objResponse->Assign("loginButton","disabled",false);
- $objResponse->Script("document.getElementById('loginMsg').style.display='inline';
- setTimeout(\"document.getElementById('loginMsg').style.display='none'\",3000); ");
- }
- }
- else
- {
- $objResponse->Assign("loginButton","value","Login");
- $objResponse->Assign("loginButton","disabled",false);
- }
- return $objResponse;
- }
- function logout()
- {
- global $SDK;
- global $smarty;
- $objResponse = new xajaxResponse();
- $SDK->logout();
- $loginhtml = "You are currently a <b>Guest</b>.<form id=\"loginbox\" action=\"javascript:void(null);\" onsubmit=\"submitLogin();\">
- Username:<input type=\"text\" id=\"username\" name=\"username\">
- Password:<input type=\"password\" id=\"password\" name=\"password\">
- <input value=\"Login\" name=\"submit\" id=\"loginButton\" type=\"submit\">
- </form>";
- $objResponse->Assign("login","innerHTML",$loginhtml);
- $smarty->assign('loginMsg', "You have been logged out...");
- $objResponse->Script("document.getElementById('loginMsg').style.display='inline';
- setTimeout(\"document.getElementById('loginMsg').style.display='none'\",3000); ");
- return $objResponse;
- }
- $xajax->processRequest();
- ?>
Add Comment
Please, Sign In to add comment