/jf/PHPReportMaker/Templates/phprpt50.zip/Script/rpt-login.php
PHP | 251 lines | 251 code | 0 blank | 0 comment | 0 complexity | c7999f8fd83d7dc7397e744cbbd55821 MD5 | raw file
Possible License(s): LGPL-2.1
- <!--##session currenttable##-->
- <!--##
- ' Set security table current
- If PROJ.SecTbl <> "" Then
- Set TABLE = DB.Tables(PROJ.SecTbl)
- sTblVar = TABLE.TblVar
- End If
-
- sLoginOption = PROJ.LoginOption
- arLoginOption = Split(sLoginOption,",")
- Set dLoginOption = CreateObject("Scripting.Dictionary")
- For i = 0 to UBound(arLoginOption)
- sOption = Trim(arLoginOption(i))
- If sOption = "AUTO" Or sOption = "USER" or sOption = "ASK" Then
- If Not dLoginOption.Exists(sOption) Then
- Call dLoginOption.Add(sOption, sOption)
- End If
- End If
- Next
- ##-->
- <!--##/session##-->
-
-
- <?php
- <!--##session phpmain##-->
-
- // Initialize common variables
- var $Username;
- var $LoginType;
-
- //
- // Page main
- //
- function Page_Main() {
- global $ReportLanguage;
- global $Security;
-
- $bValidPwd = FALSE;
- $this->Username = "";
- $sPassword = "";
-
- if (!$Security->IsLoggedIn()) $Security->AutoLogin(); // Auto login
-
- <!--## If bUserLevel Then ##-->
- $Security->LoadUserLevel(); // Load user level
- <!--## End If ##-->
-
- $sLastUrl = $Security->LastUrl();
-
- if ($sLastUrl == "")
- $sLastUrl = "<!--##=sFnDefault##-->";
-
- if (@$_POST["submit"] <> "") {
-
- $bValidPwd = FALSE;
-
- // Setup variables
- $this->Username = ewrpt_StripSlashes(@$_POST["username"]);
- $sPassword = ewrpt_StripSlashes(@$_POST["password"]);
- $this->LoginType = strtolower(@$_POST["rememberme"]);
-
- $bValidate = $this->ValidateForm($this->Username, $sPassword);
- if (!$bValidate)
- $this->setMessage($gsFormError);
-
- if ($bValidate) {
- if ($Security->ValidateUser($this->Username, $sPassword, FALSE)) {
- // Write cookies
- if ($this->LoginType == "a") {
- setcookie(EWRPT_PROJECT_VAR . '[AutoLogin]', "autologin", EWRPT_COOKIE_EXPIRY_TIME);
- setcookie(EWRPT_PROJECT_VAR . '[Username]', TEAencrypt($this->Username, EWRPT_RANDOM_KEY), EWRPT_COOKIE_EXPIRY_TIME);
- setcookie(EWRPT_PROJECT_VAR . '[Password]', TEAencrypt($sPassword, EWRPT_RANDOM_KEY), EWRPT_COOKIE_EXPIRY_TIME);
- setcookie(EWRPT_PROJECT_VAR . '[Checksum]', crc32(md5(EWRPT_RANDOM_KEY)), EWRPT_COOKIE_EXPIRY_TIME);
- } elseif ($this->LoginType == "u") {
- setcookie(EWRPT_PROJECT_VAR . '[AutoLogin]', "rememberusername", EWRPT_COOKIE_EXPIRY_TIME);
- setcookie(EWRPT_PROJECT_VAR . '[Username]', TEAencrypt($this->Username, EWRPT_RANDOM_KEY), EWRPT_COOKIE_EXPIRY_TIME);
- setcookie(EWRPT_PROJECT_VAR . '[Checksum]', crc32(md5(EWRPT_RANDOM_KEY)), EWRPT_COOKIE_EXPIRY_TIME);
- } else {
- setcookie(EWRPT_PROJECT_VAR . '[AutoLogin]', "", EWRPT_COOKIE_EXPIRY_TIME);
- }
- $_SESSION[EWRPT_SESSION_STATUS] = "login";
- $this->Page_Terminate($sLastUrl); // Return to last accessed page
- } else {
- $this->setMessage($ReportLanguage->Phrase("InvalidUidPwd"));
- }
- }
-
- } else {
- if ($Security->IsLoggedIn()) {
- if ($this->getMessage() == "")
- $this->Page_Terminate($sLastUrl); // Return to last accessed page
- }
-
- // Restore settings
- if (@$_COOKIE[EWRPT_PROJECT_VAR]['Checksum'] == strval(crc32(md5(EWRPT_RANDOM_KEY))))
- $this->Username = TEAdecrypt(@$_COOKIE[EWRPT_PROJECT_VAR]['Username'], EWRPT_RANDOM_KEY);
- if (@$_COOKIE[EWRPT_PROJECT_VAR]['AutoLogin'] == "autologin") {
- $this->LoginType = "a";
- } elseif (@$_COOKIE[EWRPT_PROJECT_VAR]['AutoLogin'] == "rememberusername") {
- $this->LoginType = "u";
- } else {
- $this->LoginType = "";
- }
-
- }
-
- }
-
- <!--##/session##-->
- ?>
-
-
- <!--##session login_htm##-->
- <script type="text/javascript" src="<!--##=ew_FolderPath("_js")##-->/ewrpt.js"></script>
- <script type="text/javascript">
- <!--
- var <!--##=sPageObj##--> = new ewrpt_Page("<!--##=sPageObj##-->");
-
- // extend page with ValidateForm function
- <!--##=sPageObj##-->.ValidateForm = function(fobj)
- {
- if (!this.ValidateRequired)
- return true; // ignore validation
- if (!ewrpt_HasValue(fobj.username))
- return ewrpt_OnError(fobj.username, ewLanguage.Phrase("EnterUid"));
- if (!ewrpt_HasValue(fobj.password))
- return ewrpt_OnError(fobj.password, ewLanguage.Phrase("EnterPwd"));
- <!--## If SYSTEMFUNCTIONS.ClientScriptExist("Other","Form_CustomValidate") Then ##-->
- // Call Form Custom Validate event
- if (!this.Form_CustomValidate(fobj)) return false;
- <!--## End If ##-->
- return true;
- }
-
- <!--## If SYSTEMFUNCTIONS.ClientScriptExist("Other","Form_CustomValidate") Then ##-->
- // extend page with Form_CustomValidate function
- <!--##=sPageObj##-->.Form_CustomValidate = <!--##~SYSTEMFUNCTIONS.GetClientScript("Other","Form_CustomValidate")##-->
- <!--## End If ##-->
-
- // requires js validation
- <?php if (EWRPT_CLIENT_VALIDATE) { ?>
- <!--##=sPageObj##-->.ValidateRequired = true;
- <?php } else { ?>
- <!--##=sPageObj##-->.ValidateRequired = false;
- <?php } ?>
- //-->
- </script>
-
- <p class="phpreportmaker ewTitle"><!--##@LoginPage##--></p>
-
- <!--##include rpt-phpcommon.php/common-message##-->
-
- <form action="<!--##=sFnLogin##-->" method="post" onsubmit="return <!--##=sPageObj##-->.ValidateForm(this);">
- <table border="0" cellspacing="0" cellpadding="4">
- <tr>
- <td><span class="phpreportmaker"><!--##@Username##--></span></td>
- <td><span class="phpreportmaker"><input type="text" name="username" size="20" value="<?php echo $<!--##=sPageObj##-->->Username ?>"></span></td>
- </tr>
- <tr>
- <td><span class="phpreportmaker"><!--##@Password##--></span></td>
- <td><span class="phpreportmaker"><input type="password" name="password" size="20"></span></td>
- </tr>
- <!--## If dLoginOption.Count > 1 Then ##-->
- <tr>
- <td> </td>
- <td><span class="phpreportmaker">
- <!--## If dLoginOption.Exists("AUTO") Then ##-->
- <label><input type="radio" name="rememberme" id="rememberme" value="a"<?php if ($<!--##=sPageObj##-->->LoginType == "a") { ?> checked="checked"<?php } ?> /><!--##@AutoLogin##--></label><br />
- <!--## End If ##-->
- <!--## If dLoginOption.Exists("USER") Then ##-->
- <label><input type="radio" name="rememberme" id="rememberme" value="u"<?php if ($<!--##=sPageObj##-->->LoginType == "u") { ?> checked="checked"<?php } ?> /><!--##@SaveUserName##--></label><br />
- <!--## End If ##-->
- <!--## If dLoginOption.Exists("ASK") Then ##-->
- <label><input type="radio" name="rememberme" id="rememberme" value=""<?php if ($<!--##=sPageObj##-->->LoginType == "") { ?> checked="checked"<?php } ?> /><!--##@AlwaysAsk##--></label><br />
- <!--## End If ##-->
- </span></td>
- </tr>
- <!--## End If ##-->
- <tr>
- <td colspan="2" align="center"><span class="phpreportmaker"><input type="submit" name="submit" value="<!--##@Login##-->"></span></td>
- </tr>
- </table>
-
- <!--## If dLoginOption.Count = 1 Then ##-->
- <!--## If dLoginOption.Exists("AUTO") Then ##-->
- <input type="hidden" name="rememberme" id="rememberme" value="a" />
- <!--## ElseIf dLoginOption.Exists("USER") Then ##-->
- <input type="hidden" name="rememberme" id="rememberme" value="u" />
- <!--## ElseIf dLoginOption.Exists("ASK") Then ##-->
- <input type="hidden" name="rememberme" id="rememberme" value="" />
- <!--## End If ##-->
- <!--## End If ##-->
-
- </form>
- <br />
-
- <!--##/session##-->
-
-
- <?php
- <!--##session phpfunction##-->
-
- //
- // Validate form
- //
- function ValidateForm($usr, $pwd) {
- global $ReportLanguage, $gsFormError;
-
- // Initialize form error message
- $gsFormError = "";
-
- // Check if validation required
- if (!EWRPT_SERVER_VALIDATE)
- return TRUE;
-
- if (trim($usr) == "") {
- $gsFormError .= ($gsFormError <> "") ? "<br />" : "";
- $gsFormError .= $ReportLanguage->Phrase("EnterUid");
- }
-
- if (trim($pwd) == "") {
- $gsFormError .= ($gsFormError <> "") ? "<br />" : "";
- $gsFormError .= $ReportLanguage->Phrase("EnterPwd");
- }
-
- // Return validate result
- $ValidateForm = ($gsFormError == "");
-
- <!--## If SYSTEMFUNCTIONS.ServerScriptExist("Other","Form_CustomValidate") Then ##-->
- // Call Form Custom Validate event
- $sFormCustomError = "";
- $ValidateForm = $ValidateForm && $this->Form_CustomValidate($sFormCustomError);
- if ($sFormCustomError <> "") {
- $gsFormError .= ($gsFormError <> "") ? "<br />" : "";
- $gsFormError .= $sFormCustomError;
- }
- <!--## End If ##-->
-
- return $ValidateForm;
-
- }
-
- <!--##/session##-->
- ?>
-
-
- <?php
- <!--##session phpevents##-->
- <!--##~SYSTEMFUNCTIONS.GetServerScript("Other","Form_CustomValidate")##-->
- <!--##/session##-->
- ?>