WLPE Snippet Call:
[!WebLoginPE? &type=`profile` &tableCheck=`0` &successTpl=`wlpe_profile_tpl` &profileTpl=`wlpe_profile_tpl`!]
wlpe_profile_tpl Chunk:
[+wlpe.message+]
<div id="wlpeUser">
<form enctype="multipart/form-data" id="wlpeUserProfileForm" action="[~[*id*]~]" method="POST">
<fieldset id="wlpeUserProfileInput">
<div id="wlpeUserInfo">
<h3 id="wlpeProfileWelcome">Hello [+user.fullname+] ([+user.username+])!</h3>
<p id="wlpeProfileInfo" class="info">Use this form to update your profile information</p>
</div>
<legend>Your User Profile</legend>
<label for="wlpeUserProfileEmail">Email
<input id="wlpeUserProfileEmail" type="text" name="email" value="[+user.email+]" />
</label>
<input style="display:none" id="wlpeUserProfilePhoto" type="file" name="photo" value="" />
<fieldset id="wlpeNewPasswordArea">
<legend id="wlpeNewPasswordAreaLegend">Change your password</legend>
<p id="wlpeNewPasswordInfo">Change your password <br /><span class="info">(leave blank if you do not want a new password).</span></p>
<label for="wlpeUserProfilePassword">New Password
<input id="wlpeUserProfilePassword" type="password" name="password" value="" />
</label>
<label for="wlpeUserProfilePasswordConfirm">New Password (confirm)
<input id="wlpeUserProfilePasswordConfirm" type="password" name="password.confirm" value="" />
</label>
</fieldset>
</fieldset>
<fieldset id="wlpeUserProfileButtons">
<button type="submit" id="wlpeSaveProfileButton" name="service" value="saveprofile">Save</button>
<button type="submit" id="wlpeProfileDoneButton" name="service" value="cancel">Done</button>
</fieldset>
</form>
</div>
Bug # 1
I wanted a simple "
Change Email/Password" form on a site...
BUG: Duplicate web user email potential via Profile Edit
After a successful test of updating my email, I quickly found that I could update to ANY email address I wanted...regardless if it already existed for a previously defined user! Further, out of the box there did not seem to be any kind of data validation on the email field. I was able to enter the word:
test and it was accepted as my new email address...
Are WLPE users required to build out all validation rules?
Bug # 2
If I enter a BLANK value for the email field, I am thrown a
database error:
UPDATE `modx`.`modx_web_user_attributes` SET WHERE `internalkey` = ’123’
It appears as if the SQL is run regardless of whether or not any fields are present to be updated...
Solution # 2
Find the following code in
webloginpe.class.php:
$saveMyProfile = $modx->db->query($generalElementsSQL);
and replace it with:
if( count($generalElementsUpdate) > 0 ) $saveMyProfile = $modx->db->query($generalElementsSQL);
This will prevent the SQL from running if there is nothing to update.
Bug # 3
Also, the following System Events don’t seem to execute as one might expect:
OnBeforeWebSaveUser
OnWebChangePassword
Although, this System Event seems to be running correctly:
OnWebSaveUser
Looking into the documentation, this is what I found:
OnBeforeWebSaveUser
Invoked BEFORE user attributes are saved to the DB. This is invoked in both Register() AND SaveUserProfile(). Parameters are ’Attributes’ and ’ExtendedFields’, so... all the users info.
OnWebChangePassword
Invoked AFTER a user changes their password. This is invoked in ActivateUser() (when a user forgot their password, gets it reset and sets a new one.), and in SaveUserProfile() IF the user’s password is changed. Parameters are ’internalKey’, ’username’, and ’password’ (the NEW password).
However, reviewing the code I found that OnWebChangePassword is invoked ONLY in
ActivateUser() (~Line #1696)
and that OnBeforeWebSaveUser is invoked in
SaveUserProfile() ONLY if $this->CustomFields is not blank, not to mention AFTER the OnWebChangePassword event...this should be "Invoked BEFORE user attributes are saved to the DB."
Solution # 3a
Invoke the method inside of SaveUserProfile() ...add code to approx Line #829
// EVENT: OnWebChangePassword
$this->OnWebChangePassword( $internalKey, $currentWebUser['username'], $_POST['password'] ); // pixelchutes
Solution # 3b
OnBeforeWebSaveUser solution coming soon...
In the meantime, change the following code in the
SaveUserProfile() function:
From this:
if (!empty($_POST['password']) && isset($_POST['password']) && isset($_POST['passwordconfirm']))
To this:
// EVENT: OnBeforeWebSaveUser
$this->OnBeforeWebSaveUser(array(), array()); // pixelchutes
if ( !empty($this->Report) ) return; // pixelchutes
if (!empty($_POST['password']) && isset($_POST['password']) && isset($_POST['password_confirm'])) // pixelchutes
NOTE: This solution should be considered temporary. It simply enables the invocation of the OnBeforeWebSaveUser system event at the proper time. Note, invoked in the manner provided above, this function will send empty arrays as its arguments until the official solution is rolled out. In the meantime, you can access the generalElements and extendedFields via PHP’s $_REQUEST scope.
Bug # 4
NOTE: If you have already applied the solution #3b above, then a portion of Bug #4’s solution will already have been applied.
In
SaveUserProfile() the Confirm Password logic appears to be invalid:
if (!empty($_POST['password']) && isset($_POST['password']) && isset($_POST['passwordconfirm']))
{
if ($_POST['password'] === $_POST['passwordconfirm'])
It should be looking for "password_confirm":
Solution # 4
if (!empty($_POST['password']) && isset($_POST['password']) && isset($_POST['password_confirm'])) // pixelchutes
{
if ($_POST['password'] === $_POST['password_confirm']) // pixelchutes
Bug # 5
I have tracked down other "_confirm" issues, specifically Internet Explorer and "Reset Password" not working...this is because the default TPL for Activation outputs the password confirmation as:
newpassword.confirm and in the Class PHP file, it references:
$newPasswordConfirm = $modx->db->escape($_POST['newpasswordconfirm']);
but should be:
Solution # 5
$newPasswordConfirm = $modx->db->escape($_POST['newpassword_confirm']);
and don’t forget to update to
newpassword_confirm in the form for your templates.
Note to Scotty: Documentation/Templates should be globally updated to account for "_confirm" logic.
Bug # 6
Pressing "Enter" to submit your email on the "Forgot Password" form does not seem to work in Internet Explorer...it simply takes back to the main login page. Enter in FireFox works, and it works in IE if I
click on the button.....this is related to the "ieButtonFix.js"
Since the fix is applied via
onclick events tied to the submit buttons, the fix
does not get applied when a user submits the form via the Enter key.
Solution # 6
The solution here is to either
A.) See if you can trigger the onclick event of the first <button> upon pressing Enter,
B.) Disable "Enter" key form submission in IE
* Please see attached file, updated ieButtonFix.js (remove .txt extension)
The attached file has been tested/confirmed to work in IE 6 and 7, and should work with multiple Forms, too (as long as each WLPE form has a unique ID). This enables the ability for IE users to submit the form via "Enter" key, and have it activate the ieButtonFix functions.
Bug # 7
Invoking
OnWebChangePassword() event inside of
ActivateUser() was throwing an error...when an actual "OnWebChangePassword" System Event is defined.... This is because the
OnWebChangePassword() function is missing global $modx:
Solution # 7