PHPMaker does a really good job while generating the login page which is included with the powerful ValidateUser function. Unfortunately, when you optimize the field "Activated" in order to signify whether a user Activated status is "Yes" (enabled=1) or "No" (disabled=0), and when the user status disabled so that the user cannot logged in and this is fine, the message that being displayed is still too common and there is no connection at all with the condition above. The message is: "Incorrect user ID or password". I think this failure message is not so smart as it should be.
The following modifications will overcome the problems above. It will display the related message that corresponding to the condition where the user Activated status is currently disabled. So, that general message above would be replaced with something more accurate like this: "This user is currently being deactivated now".
Does it sound better, huh? 😉
[hidepost]
- Make sure that you have already assigned the activated field from your PHPMaker application in "Advanced Security - User Login Options" -> "User Table Fields" -> "Activated field". In this example below, we are assuming that this field has the type as enum which has two value: 0 and 1.
-
Open your ewcfg.php file, and find this code:
define("EW_USER_PROFILE_FIELD_NAME", "<!--##=sProfileFld##-->", TRUE);
after that line, please insert this following code:
// Begin of modification by Masino Sinaga, for displaying deactivated account properly, October 13, 2011 <!--## If DB.SecuUserIDFld <> "" Then Set FIELD = SECTABLE.Fields(DB.SecuUserIDFld) If FIELD Is Nothing Then Err.Raise -1, "DB.SecuUserIDFld", "Invalid User ID Field" Else sUserIDFld = FIELD.FldName End If End If ##--> define("EW_USER_ID_FIELD_NAME", "<!--##=sUserIDFld##-->", TRUE); <!--## If PROJ.SecRegisterActivate And PROJ.SecRegisterActivateFld <> "" Then Set FIELD = SECTABLE.Fields(PROJ.SecRegisterActivateFld) If FIELD Is Nothing Then Err.Raise -1, "PROJ.SecRegisterActivateFld", "Invalid User Activated Field" Else sRegisterActivateFld = FIELD.FldName End If End If ##--> define("EW_USER_ACTIVATE_FIELD_NAME", "<!--##=sRegisterActivateFld##-->", TRUE); // Begin of modification by Masino Sinaga, for displaying deactivated account properly, October 13, 2011
-
Open your phpfn.php file, and find this code:
// Validate user function ValidateUser($usr, $pwd, $autologin) {
before the first line of that code, please insert this following code:
// Begin of check user whether activated or deactivated by Masino Sinaga, October 13, 2011 function IsDeactivated($usr) { global $conn, $Language; <!--## If bUserTable Then ##--> global $<!--##=sSecTblVar##-->; <!--## End If ##--> <!--## If bUserProfile Then ##--> global $UserProfile; <!--## End If ##--> $IsDeactivated = FALSE; $sFilter = str_replace("%u", ew_AdjustSql($usr), EW_USER_NAME_FILTER); <!--## If PROJ.SecRegisterActivate And PROJ.SecRegisterActivateFld <> "" Then Set FIELD = SECTABLE.Fields(PROJ.SecRegisterActivateFld) If FIELD Is Nothing Then Err.Raise -1, "PROJ.SecRegisterActivateFld", "Invalid User Activated Field" Else sFld = ew_FieldName sFldQuoteS = FIELD.FldQuoteS sFldQuoteE = FIELD.FldQuoteE sFldValue = ActivateFieldValue(FIELD) sFilter = "(" & sFld & " = " & sFldQuoteS & "0" & sFldQuoteE & ")" End If Else sFilter = "" End If ##--> $sFilter .= " AND <!--##=ew_Quote(sFilter)##--> "; $sSql = $<!--##=sSecTblVar##-->->GetSQL($sFilter, ""); if ($rs = $conn->Execute($sSql)) { if (!$rs->EOF) { $IsDeactivated = TRUE; } else { $IsDeactivated = FALSE; } $rs->Close(); } if ($IsDeactivated) $_SESSION[EW_SESSION_STATUS] = ""; // Clear login status return $IsDeactivated; } // End of check user whether activated or deactivated by Masino Sinaga, October 13, 2011
That code above will check whether the value of the activated field is 0 (zero) or not. If it is zero, it means that the user is currently being deactivated now.
-
Open your login.php file, and find this code:
if ($bValidate) { $bValidPwd = $Security->ValidateUser($this->Username, $sPassword, FALSE); // Manual login
then replace it with this following code:
if ($bValidate) { <!--## If PROJ.SecRegisterActivate And PROJ.SecRegisterActivateFld <> "" Then ##--> // Begin of check user whether activated or deactivated by Masino Sinaga, October 13, 2011 $IsUserDeactivated = $Security->IsDeactivated($this->Username); if ($IsUserDeactivated) { $this->setFailureMessage($Language->Phrase("UserDeactivated")); // If user still deactivated } // End of check user whether activated or deactivated by Masino Sinaga, October 13, 2011 <!--## End If ##--> $bValidPwd = $Security->ValidateUser($this->Username, $sPassword, FALSE); // Manual login
-
Open your C:\Program Files\PHPMaker 8\languages\english.xml, and find this code:
</global>
before that line, please insert this following code:
<phrase id="UserDeactivated" value="This user is currently being deactivated now."/>
-
Do the same way with your another .xml language file. For example, I am also using Indonesian language, so I add this following code into my C:\Program Files\PHPMaker 8\languages\indonesian.xml:
<phrase id="UserDeactivated" value="Pengguna ini sedang dinonaktifkan sekarang."/>
before this line:
</global>
- Re-generate your script files using PHPMaker as always.
[/hidepost]
[…] note that you have to apply this customization before implementing this customization, since there is some constants were added into the ewcfg.php […]