If you have enabled the user activation in the Register page in website that created with PHPMaker, then the user that has been just registered will get an email from the system that contains registration information with a link inside to activate his/her account. Unfortunately, when that user's email is changed by himself/herself via the user's profile, there is no the ability provided by the system to validate that new email address.
This following modification below will add the ability of user activation after email is changed in website that created with PHPMaker 8.0.3. On the change of email address event, there will be a new process being done. System will automatically detect whether the email has been successfully changed and that current user does that change, not by someone else. If this conditions are met, then the user's account will be disabled at the moment, and system will automatically force logout the current user immediately.
The next step is, the system will send an email to the new user's email. The user has to check his/her new email in order to reactivate his/her account by clicking the activation link inside that new email. All of them are behind the screen! After this reactivation process, then that user will be able to access the site as usual. This will prevent the user which has the invalid email address registered in your website.
[hidepost]
- Open your .pmp file using PHPMaker application.
- Click on the Database menu, then select your table that holds the user data of your website.
-
Click on Server Events/Client Scripts tab, and expand the following: Server Events -> Table-Specific -> Common -> Row_Updating, and copy-paste this following code (Please note that in this case, I am using the demo project that provided by PHPMaker, thus the employee table is being used. Adjust it with yours according to your own user table in your PHPMaker project):
// Row Updating event function Row_Updating($rsold, &$rsnew) { // Enter your code here // To cancel, set return value to FALSE global $conn; global $employees; global $Languages; include_once "phpfn8.php"; $currentUserID = CurrentUserID(); if ( ($rsold["Email"] != $rsnew["Email"]) && ($rsold["EmployeeID"] == $currentUserID) ) { $rsnew["Activated"] = "N"; $sEmail = $rsnew["Email"]; $sReceiverEmail = $sEmail; // Load user email if ($sReceiverEmail == "") { // Send to recipient directly $sReceiverEmail = EW_RECIPIENT_EMAIL; $sBccEmail = ""; } else { // Bcc recipient $sBccEmail = EW_RECIPIENT_EMAIL; } // Set up email content if ($sReceiverEmail <> "") { $Email = new cEmail; $Email->Load("phptxt/register.txt"); $Email->ReplaceSender(EW_SENDER_EMAIL); // Replace Sender $Email->ReplaceRecipient($sReceiverEmail); // Replace Recipient if ($sBccEmail <> "") $Email->AddBcc($sBccEmail); // Add Bcc $Email->ReplaceContent('<!--FieldCaption_Username-->', $employees->Username->FldCaption()); $Email->ReplaceContent('<!--Username-->', strval($employees->Username->FormValue)); $Email->ReplaceContent('<!--FieldCaption_LastName-->', $employees->LastName->FldCaption()); $Email->ReplaceContent('<!--LastName-->', strval($employees->LastName->FormValue)); $Email->ReplaceContent('<!--FieldCaption_FirstName-->', $employees->FirstName->FldCaption()); $Email->ReplaceContent('<!--FirstName-->', strval($employees->FirstName->FormValue)); $Email->ReplaceContent('<!--FieldCaption_Password-->', $employees->Password->FldCaption()); $Email->ReplaceContent('<!--Password-->', strval($employees->Password->FormValue)); $Email->ReplaceContent('<!--FieldCaption_Email-->', $employees->zEmail->FldCaption()); $Email->ReplaceContent('<!--Email-->', strval($sEmail)); $sActivateLink = "http://localhost/demo8/register.php?action=confirm"; // original: ew_FullUrl() . // << adjust that URL with yours! $sActivateLink .= "&email=" . $sEmail; $sActivateLink .= "&code=" . TEAencrypt($sEmail, EW_RANDOM_KEY); $Email->ReplaceContent("<!--ActivateLink-->", $sActivateLink); setcookie(EW_PROJECT_NAME . '[Username]', TEAencrypt($employees->Username->CurrentValue, EW_RANDOM_KEY), EW_COOKIE_EXPIRY_TIME); // Set up user name cookies setcookie(EW_PROJECT_NAME . '[Password]', TEAencrypt($employees->Password->FormValue, EW_RANDOM_KEY), EW_COOKIE_EXPIRY_TIME); // Set up password cookies $Email->Charset = EW_EMAIL_CHARSET; // Get new recordset $sSql = "SELECT * FROM ".EW_USER_TABLE." WHERE EmployeeID = " .CurrentUserID(). ""; $rsupdate = $conn->Execute($sSql); $Args = array(); $Args["rs"] =& $rsupdate; $bEmailSent = FALSE; if ($this->Email_Sending($Email, $Args)) $bEmailSent = $Email->Send(); // Send email failed if (!$bEmailSent) $this->setFailureMessage($Email->SendErrDescription); } } return TRUE; } -
Click on Server Events/Client Scripts tab, and expand the following: Server Events -> Table-Specific -> Common -> Row_Updated, and copy-paste this following code (Please note that in this case, I am using the demo project that provided by PHPMaker, thus the employee table is being used. Adjust it with yours according to your own user table in your PHPMaker project):
// Row Updated event function Row_Updated($rsold, &$rsnew) { //echo "Page Load"; global $conn; $currentUserID = CurrentUserID(); if ( ($rsold["Email"] != $rsnew["Email"]) && ($rsold["EmployeeID"] == $currentUserID) ) { $sSql = "SELECT * FROM ".EW_USER_TABLE." WHERE EmployeeID = '" .CurrentUserID(). "'"; $rs = $conn->Execute($sSql); if ( ($rs->RecordCount()>0) && ($rs->fields("Activated")=="N") ) { header("Location: logout.php"); return FALSE; } } }
[/hidepost]
Leave a Reply
You must be logged in to post a comment.