One of the greatest features that I love in the web applications that generated by PHPMaker is the ability to provide two different main business process when users registering their user accounts. The first one is, users can activate their accounts by clicking on the link inside the email that sent by web applications after registering are successfully done. And the other is, users can directly automatically logged in to web application after they successfully registering their account (auto-login) without having to activate their user account. Even you can combine both of them; after clicking on the activation link, users will automatically be logged in!
Unfortunately, PHPMaker has not provided the ability to suspend the user accounts so that Administrator or the certain user level will approve or activate their user accounts. This feature actually is very useful if you want to review the new user accounts before approving them. It should be available too in PHPMaker.
Today, I successfully created and implemented this new business process into the web applications that generated by PHPMaker. You can decide whether to enable or disable this feature by simply adjusting the related constant in the configuration (ewcfg9.php) file.
This will be happened after you implementing this new feature:
- Users register their account via the Registration page.
- System send the email that contains registration information to the users. At this point, the status of the users account are being suspended.
- Admin reviews and approves the user accounts, the users account status are active, and system will send email to the users informing about the approval from Admin.
- Users are able to login to system.
In order to implement this feature properly, then make sure you have already given a checked mark at the Requires activation item, from Security tab -> Advanced -> User Login Options -> User Registration Page. In addition, make sure you have removed the checked mark at the Auto login after registration/activation item from the same location above.
Warning: This customization is related to the customization in the following articles:
- How to Use Email Template Based on the Selected Language in Websites that Created with PHPMaker 9.0.1
- How to Include Application Name in Email Templates of Websites that Generated with PHPMaker 9.0.2.
So, make sure you have also implemented the customizations in those articles before doing the customization below.
Updated on February 10, 2013: This customization has been implemented in PHPMaker version 9.2.0, it matches to each other, and as a result, it works properly.
Updated on June 17, 2013: The customization has been handled by using MasinoRegister and MasinoFixedWidthSite extensions. You don’t need to implement the customization below if you use my extensions together with the original PHPMaker Template and Extension files.
[hidepost]
-
Open your \Script\ewcfg.php file, and find this code:
// General
before that line, please insert the following code:
// Begin of modification Activate User Account by Admin, by Masino Sinaga, December 6, 2012 define("MS_SUSPEND_NEW_USER_ACCOUNT", TRUE, TRUE); // End of modification Activate User Account by Admin, by Masino Sinaga, December 6, 2012 -
Open your \Script\register.php file, and find this code (you will never find this code before implementing the customization in the article number two above):
// Begin of modification Email Template based on Selected Language, by Masino Sinaga, May 4, 2012 $Email->Load(str_replace('register.txt', 'register'.$GLOBALS["Language"]->LanguageId.'.txt', '<!--##=sFnRegisterTxt##-->')); // End of modification Email Template based on Selected Language, by Masino Sinaga, May 4, 2012then replace it with the following code:
// Begin of modification Activate User Account by Admin, by Masino Sinaga, December 6, 2012 if (MS_SUSPEND_NEW_USER_ACCOUNT==TRUE) { // Using the different email template if admin will activate user account $Email->Load(str_replace('register.txt', 'registerpending'.$GLOBALS["Language"]->LanguageId.'.txt', 'phptxt/registerpending.txt')); } else { // Begin of modification Email Template based on Selected Language, by Masino Sinaga, May 4, 2012 $Email->Load(str_replace('register.txt', 'register-'.$GLOBALS["Language"]->LanguageId.'.txt', '<!--##=sFnRegisterTxt##-->')); // End of modification Email Template based on Selected Language, by Masino Sinaga, May 4, 2012 } // End of modification Activate User Account by Admin, by Masino Sinaga, December 6, 2012 -
Still in that \Script\register.php file, find again this code:
$sActivateLink = ew_FullUrl() . "?action=confirm"; $sActivateLink .= "&email=" . $<!--##=sEmailFldObj##-->->CurrentValue; $sActivateLink .= "&code=" . TEAencrypt($<!--##=sEmailFldObj##-->->CurrentValue, EW_RANDOM_KEY); $Email->ReplaceContent("<!--ActivateLink-->", $sActivateLink);then replace it with the following code:
// Begin of modification Activate User Account by Admin, by Masino Sinaga, December 6, 2012 if (MS_SUSPEND_NEW_USER_ACCOUNT==TRUE) { // there is no activation link if admin will activate the user account } else { $sActivateLink = ew_FullUrl() . "?action=confirm"; $sActivateLink .= "&email=" . $<!--##=sEmailFldObj##-->->CurrentValue; $sActivateLink .= "&code=" . TEAencrypt($<!--##=sEmailFldObj##-->->CurrentValue, EW_RANDOM_KEY); $Email->ReplaceContent("<!--ActivateLink-->", $sActivateLink); } // End of modification Activate User Account by Admin, by Masino Sinaga, December 6, 2012 -
Still in that \Script\register.php file, find again this code:
if ($this->getSuccessMessage() == "") $this->setSuccessMessage($Language->Phrase("RegisterSuccessActivate")); // Activate successthen replace it with the following code:
// Begin of modification Activate User Account by Admin, by Masino Sinaga, December 6, 2012 if ($this->getSuccessMessage() == "") { if (MS_SUSPEND_NEW_USER_ACCOUNT==TRUE) { $this->setSuccessMessage($Language->Phrase("RegisterSuccessPending")); // Activate success } else { $this->setSuccessMessage($Language->Phrase("RegisterSuccessActivate")); // Activate success } } // End of modification Activate User Account by Admin, by Masino Sinaga, December 6, 2012 -
Open your C:\Program Files\PHPMaker 9\languages\english.xml file, and find this code:
</global>
before that line, please insert the following code:
<phrase id="RegisterSuccessPending" value="Registration succeeded. An email has been sent to your email address. Your account will be activated as soon as possible."/> <phrase id="AccountHasBeenActivated" value="Account %u has been activated."/> <phrase id="InvalidAccount" value="Invalid account or account has been activated already."/> <phrase id="SubjectAccountActivated" value="Your Account Has Been Activated"/>
Do the same way with your another .xml language file(s). For example, I am also using Indonesian, then I will add the similar code into my indonesian.xml file in the same directory above:
<phrase id="RegisterSuccessPending" value="Pendaftaran berhasil. Informasi pendaftaran sudah dikirim ke email Anda. Akun akan kami aktifkan sesegera mungkin."/> <phrase id="AccountHasBeenActivated" value="Akun %u sudah diaktifkan."/> <phrase id="InvalidAccount" value="Akun tidak valid atau akun sudah pernah diaktifkan."/> <phrase id="SubjectAccountActivated" value="Akun Anda sudah diaktifkan"/>
-
Open your \Script\control.xml file, and find this code:
<!-- Global configuration file All web site configuration settings are stored here -->
before the first line of that code, please insert the following code:
<!-- Begin of modification Activate User Account by Admin, by Masino Sinaga, December 6, 2012 --> <control id="registerpending.txt" type="other" ofolderid="_txt" ofile="registerpending" oext="txt" space="False" ifiles="registerpending.txt" cond="proj/SecRegisterPage/EQ/True,proj/SecType/EQ/Use Table|Both"> <session type="key" value="registeremail" /> </control> <control id="registerpendingen.txt" type="other" ofolderid="_txt" ofile="registerpendingen" oext="txt" space="False" ifiles="registerpendingen.txt" cond="proj/SecRegisterPage/EQ/True,proj/SecType/EQ/Use Table|Both"> <session type="key" value="registeremail" /> </control> <control id="registerpendingid.txt" type="other" ofolderid="_txt" ofile="registerpendingid" oext="txt" space="False" ifiles="registerpendingid.txt" cond="proj/SecRegisterPage/EQ/True,proj/SecType/EQ/Use Table|Both"> <session type="key" value="registeremail" /> </control> <control id="registerapproved.txt" type="other" ofolderid="_txt" ofile="registerapproved" oext="txt" space="False" ifiles="registerapproved.txt" cond="proj/SecRegisterPage/EQ/True,proj/SecType/EQ/Use Table|Both"> <session type="key" value="registeremail" /> </control> <control id="registerapproveden.txt" type="other" ofolderid="_txt" ofile="registerapproveden" oext="txt" space="False" ifiles="registerapproveden.txt" cond="proj/SecRegisterPage/EQ/True,proj/SecType/EQ/Use Table|Both"> <session type="key" value="registeremail" /> </control> <control id="registerapprovedid.txt" type="other" ofolderid="_txt" ofile="registerapprovedid" oext="txt" space="False" ifiles="registerapprovedid.txt" cond="proj/SecRegisterPage/EQ/True,proj/SecType/EQ/Use Table|Both"> <session type="key" value="registeremail" /> </control> <control id="activateaccount.php" type="copy" remark="Copy activateaccount.php" ifiles="activateaccount.php" /> <!-- End of modification Activate User Account by Admin, by Masino Sinaga, December 6, 2012 --> -
Create 6 (Six) text files as following below, and put them under \Script\ sub-folder of your unzip template files. Please note that in this step, since I am using English and Indonesian, then the prefix of the filename is en and id. So, adjust it with yours!
Filename: \Script\registerpending.txt
<!--##session registeremail##--> Subject: <!--$Subject--> From: <!--$From--> To: <!--$To--> Cc: Bcc: Format: TEXT Dear Sir/Madam, Thank you for registering with us. Your registration details with us is as follow: <!--## TABLE = DB.Tables(PROJ.SecTbl); for (var i = 1, cnt = TABLE.Fields.Count(); i <= cnt; i++) { FIELD = TABLE.Fields.Seq(i); if (FIELD.FldGenerate) { if (FIELD.FldRegister && FIELD.FldName != DB.SecUserLevelFld) { ##--> <!--FieldCaption_<!--##=FIELD.FldName##-->-->: <!--<!--##=FIELD.FldName##-->--> <!--## } } } // Field ##--> Your account is currently not active. We will activate it and let you know afterwards. Best Regards, Support <!--##/session##-->Filename: \Script\registerpendingen.txt
<!--##session registeremail##--> Subject: <!--$Subject--> From: <!--$From--> To: <!--$To--> Cc: Bcc: Format: TEXT Dear Sir/Madam, Thank you for registering with us. Your registration details with us is as follow: <!--## TABLE = DB.Tables(PROJ.SecTbl); for (var i = 1, cnt = TABLE.Fields.Count(); i <= cnt; i++) { FIELD = TABLE.Fields.Seq(i); if (FIELD.FldGenerate) { if (FIELD.FldRegister && FIELD.FldName != DB.SecUserLevelFld) { ##--> <!--FieldCaption_<!--##=FIELD.FldName##-->-->: <!--<!--##=FIELD.FldName##-->--> <!--## } } } // Field ##--> Your account is currently not active. We will activate it and let you know afterwards. Best Regards, Support <!--##/session##-->Filename: \Script\registerpendingid.txt
<!--##session registeremail##--> Subject: <!--$Subject--> From: <!--$From--> To: <!--$To--> Cc: Bcc: Format: TEXT Yth. Bapak/Ibu, Terima kasih telah mendaftar. Informasi akun Anda adalah sebagai berikut: <!--## TABLE = DB.Tables(PROJ.SecTbl); for (var i = 1, cnt = TABLE.Fields.Count(); i <= cnt; i++) { FIELD = TABLE.Fields.Seq(i); if (FIELD.FldGenerate) { if (FIELD.FldRegister && FIELD.FldName != DB.SecUserLevelFld) { ##--> <!--FieldCaption_<!--##=FIELD.FldName##-->-->: <!--<!--##=FIELD.FldName##-->--> <!--## } } } // Field ##--> Akun Anda saat ini belum diaktifkan. Segera setelah diaktifkan, kami akan memberitahukan Anda kembali. Salam, Administrator <!--##/session##-->Filename: \Script\registerapproved.txt
<!--##session registeremail##--> Subject: <!--$Subject--> From: <!--$From--> To: <!--$To--> Cc: Bcc: Format: TEXT Dear Sir/Madam, Congratulations, your account has been activated. User ID: <!--$UserName--> Password: (as we have previously sent to you via email) Best Regards, Support <!--##/session##-->
Filename: \Script\registerapproveden.txt
<!--##session registeremail##--> Subject: <!--$Subject--> From: <!--$From--> To: <!--$To--> Cc: Bcc: Format: TEXT Dear Sir/Madam, Congratulations, your account has been activated. User ID: <!--$UserName--> Password: (as we have previously sent to you via email) Best Regards, Support <!--##/session##-->
Filename: \Script\registerapprovedid.txt
<!--##session registeremail##--> Subject: <!--$Subject--> From: <!--$From--> To: <!--$To--> Cc: Bcc: Format: TEXT Yth. Bapak/Ibu, Selamat, akun Anda sudah kami aktifkan. ID Pengguna: <!--$UserName--> Kata Sandi: (sesuai dengan yang kami kirim di email sebelumnya) Salam, Administrator <!--##/session##-->
-
Create a new file, copy and paste the following code into it, and save it as \Script\activateaccount.php file:
<?php if (session_id() == "") session_start(); // Initialize Session data ob_start(); // Turn on output buffering ?> <?php include_once "ewcfg9.php" ?> <?php if (EW_IS_MYSQL) { include_once "ewmysql9.php"; } else if (EW_IS_MSSQL) { include_once "adodb5/adodb.inc.php"; } ?> <?php include_once "phpfn9.php" ?> <?php include_once "".MS_USER_TABLE_NAME."info.php" ?> <?php include_once "userfn9.php" ?> <?php // // Page class // $ActivateAccount = NULL; // Initialize page object first class cActivateAccount { // Page ID var $PageID = 'ActivateAccount'; var $sEmail = ''; // Added by Masino Sinaga, in order to prevent error undefined variable $sEmail, January 16, 2012 var $sSrchWhere = ''; // Added by Masino Sinaga, in order to prevent error undefined variable $sSrchWhere, January 16, 2012 var $sDisabled = ''; // Added by Masino Sinaga, in order to prevent error undefined variable $sDisabled, January 16, 2012 // Project ID var $ProjectID = "{D8EA9720-CB56-4EB8-B8E1-13D6CF449795}"; // <-- Don't forget to adjust your Project ID here !!! // Page object name var $PageObjName = 'ActivateAccount'; // Page name function PageName() { return ew_CurrentPage(); } // Page URL function PageUrl() { $PageUrl = ew_CurrentPage() . "?"; return $PageUrl; } // Message function getMessage() { return @$_SESSION[EW_SESSION_MESSAGE]; } function setMessage($v) { ew_AddMessage($_SESSION[EW_SESSION_MESSAGE], $v); } function getFailureMessage() { return @$_SESSION[EW_SESSION_FAILURE_MESSAGE]; } function setFailureMessage($v) { ew_AddMessage($_SESSION[EW_SESSION_FAILURE_MESSAGE], $v); } function getSuccessMessage() { return @$_SESSION[EW_SESSION_SUCCESS_MESSAGE]; } function setSuccessMessage($v) { ew_AddMessage($_SESSION[EW_SESSION_SUCCESS_MESSAGE], $v); } function getWarningMessage() { return @$_SESSION[EW_SESSION_WARNING_MESSAGE]; } function setWarningMessage($v) { ew_AddMessage($_SESSION[EW_SESSION_WARNING_MESSAGE], $v); } // Show message function ShowMessage() { $hidden = TRUE; $html = ""; // Message $sMessage = $this->getMessage(); $this->Message_Showing($sMessage, ""); if ($sMessage <> "") { // Message in Session, display $html .= "<p class=\"ewMessage\">" . $sMessage . "</p>"; $_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message in Session } // Warning message $sWarningMessage = $this->getWarningMessage(); $this->Message_Showing($sWarningMessage, "warning"); if ($sWarningMessage <> "") { // Message in Session, display $html .= "<table class=\"ewMessageTable\"><tr><td class=\"ewWarningIcon\"></td><td class=\"ewWarningMessage\">" . $sWarningMessage . "</td></tr></table>"; $_SESSION[EW_SESSION_WARNING_MESSAGE] = ""; // Clear message in Session } // Success message $sSuccessMessage = $this->getSuccessMessage(); $this->Message_Showing($sSuccessMessage, "success"); if ($sSuccessMessage <> "") { // Message in Session, display $html .= "<table class=\"ewMessageTable\"><tr><td class=\"ewSuccessIcon\"></td><td class=\"ewSuccessMessage\">" . $sSuccessMessage . "</td></tr></table>"; $_SESSION[EW_SESSION_SUCCESS_MESSAGE] = ""; // Clear message in Session } // Failure message $sErrorMessage = $this->getFailureMessage(); $this->Message_Showing($sErrorMessage, "failure"); if ($sErrorMessage <> "") { // Message in Session, display $html .= "<table class=\"ewMessageTable\"><tr><td class=\"ewErrorIcon\"></td><td class=\"ewErrorMessage\">" . $sErrorMessage . "</td></tr></table>"; $_SESSION[EW_SESSION_FAILURE_MESSAGE] = ""; // Clear message in Session } echo "<div class=\"ewMessageDialog\"" . (($hidden) ? " style=\"display: none;\"" : "") . ">" . $html . "</div>"; } // // Page class constructor // function __construct() { global $conn, $Language; $GLOBALS["Page"] = &$this; // Language object if (!isset($Language)) $Language = new cLanguage(); // User table object (MS_USER_TABLE_NAME) // if (!isset($GLOBALS["".MS_USER_TABLE_NAME.""])) $GLOBALS["".MS_USER_TABLE_NAME.""] = new cpengguna; // Page ID if (!defined("EW_PAGE_ID")) define("EW_PAGE_ID", 'ActivateAccount', TRUE); // Start timer if (!isset($GLOBALS["gTimer"])) $GLOBALS["gTimer"] = new cTimer(); // Open connection if (!isset($conn)) $conn = ew_Connect(); } // // Page_Init // function Page_Init() { global $gsExport, $gsExportFile, $UserProfile, $Language, $Security, $objForm, $conn; // User profile $UserProfile = new cUserProfile(); $UserProfile->LoadProfileFromDatabase(CurrentUserName()); // Security $Security = new cAdvancedSecurity(); // Uncomment codes below for security /* if (!$Security->IsLoggedIn()) $Security->AutoLogin(); if (!$Security->IsLoggedIn()) $this->Page_Terminate("login.php"); */ // Global Page Loading event (in userfn*.php) Page_Loading(); // Page Load event $this->Page_Load(); } // // Page_Terminate // function Page_Terminate($url = "") { global $conn; // Page Unload event $this->Page_Unload(); // Global Page Unloaded event (in userfn*.php) Page_Unloaded(); $this->Page_Redirecting($url); // Close connection $conn->Close(); // Go to URL if specified if ($url <> "") { if (!EW_DEBUG_ENABLED && ob_get_length()) ob_end_clean(); header("Location: " . $url); } exit(); } // // Page main // function Page_Main() { global $Security, $Language; //$this->setSuccessMessage("Welcome " . CurrentUserName()); // Put your custom codes here } // Page Load event function Page_Load() { //echo "Page Load"; } // Page Unload event function Page_Unload() { //echo "Page Unload"; } // Page Redirecting event function Page_Redirecting(&$url) { // Example: //$url = "your URL"; } // Message Showing event // $type = ''|'success'|'failure' function Message_Showing(&$msg, $type) { // Example: //if ($type == 'success') $msg = "your success message"; } } ?> <?php ew_Header(FALSE) ?> <?php // Create page object if (!isset($ActivateAccount)) $ActivateAccount = new cActivateAccount(); // Page init $ActivateAccount->Page_Init(); // Page main $ActivateAccount->Page_Main(); // Begin of modification Displaying Breadcrumb Links in All Pages, by Masino Sinaga, May 4, 2012 getCurrentPageTitle(ew_CurrentPage()); // End of modification Displaying Breadcrumb Links in All Pages, by Masino Sinaga, May 4, 2012 ?> <?php include_once "header.php" ?> <?php $ActivateAccount->ShowMessage(); ?> <!-- Put your custom html here --> <?php global $conn, $Language; if($_GET && (!empty($_GET['username']) )) { $username=trim($_GET['username']); } if($_GET && (!empty($_GET['email']) )) { $email=trim($_GET['email']); } $sqlActAcc= "SELECT ".MS_USER_NAME_PARAMETER.", email FROM ".EW_USER_TABLE." WHERE ".MS_USER_NAME_PARAMETER."='".$username."' AND ".str_replace('%e', $email, EW_USER_EMAIL_FILTER).""; $rsActAcc = $conn->Execute($sqlActAcc); if ($rsActAcc->RecordCount() > 0) { $user_email = $rsActAcc->fields('email'); $user_name = $rsActAcc->fields(''.MS_USER_NAME_PARAMETER.''); $bValidEmail = FALSE; $bEmailSent = FALSE; $Email = new cEmail(); $Email->Load(str_replace('registerapproved.txt', 'registerapproved'.$GLOBALS["Language"]->LanguageId.'.txt', 'phptxt/registerapproved.txt')); // Begin of modification Displaying Application Name in Email Template, by Masino Sinaga, June 5, 2012 $Email->ReplaceSubject($Language->Phrase("SubjectAccountActivated").' '.$Language->ProjectPhrase("BodyTitle")); // End of modification Displaying Application Name in Email Template, by Masino Sinaga, June 5, 2012 $Email->ReplaceSender(EW_SENDER_EMAIL); // Replace Sender $Email->ReplaceRecipient($user_email); // Replace Recipient $Email->ReplaceContent('<!--$UserName-->', $user_name); // $Email->ReplaceContent('<!--$Password-->', $real_new_password); $Email->Charset = EW_EMAIL_CHARSET; $bEmailSent = $Email->Send(); if ($bEmailSent) { // Begin of modification Displaying Application Name in Email Template, by Masino Sinaga, June 5, 2012 $setActivate = str_replace("(", "", EW_USER_ACTIVATE_FILTER); $setActivate = str_replace(")", "", $setActivate); $setWhereEmail = str_replace("%e", ew_AdjustSql($user_email), EW_USER_EMAIL_FILTER); $setWhereUsername = str_replace("%u", ew_AdjustSql($user_name), EW_USER_NAME_FILTER); $sql = "UPDATE ".EW_USER_TABLE." SET ".$setActivate." WHERE ".$setWhereUsername." AND ".$setWhereEmail.""; $conn->Execute($sql); $message_email_sent = str_replace("%u", ew_AdjustSql($user_name), $Language->Phrase("AccountHasBeenActivated")); $ActivateAccount->setSuccessMessage($message_email_sent); // Set success message // End of modification Displaying Application Name in Email Template, by Masino Sinaga, June 5, 2012 $ActivateAccount->Page_Terminate("login.php"); // Return to login page } elseif ($bValidEmail) { $ActivateAccount->setFailureMessage($Language->Phrase("FailedToSendMail")); // Set up error message } } else { $ActivateAccount->setFailureMessage($Language->Phrase("InvalidAccount")); // Invalid account! if (!$Security->IsLoggedIn()) { $ActivateAccount->Page_Terminate("login.php"); } } ?> <?php include_once "footer.php" ?> <?php $ActivateAccount->Page_Terminate(); ?> - Re-generate your script files using PHPMaker as always.
-
In order to activate the suspended user accounts, then you have to call the activateaccount.php file by supplying two variables in the URL. The first one is username and the second one is email.
For example:http://www.yourdomain.com/activateaccount.php?username=theusername&email=theuseremail@theemail.com
[/hidepost]
Leave a Reply
You must be logged in to post a comment.