php js css php js css

Changes

Changes to Page: lost_password


System
Change
Can't Undo: The change does not exist
393531
Oct 4 4:12pm
System
Deleted page
Can't Undo: The page /community/lost_password/ already exists.
Title:
Lost Password
Accept Child 404:
0
Search Description:

														
													
													
													
												
Search Keywords:

														
													
													
													
												
Search Noindex:
1
Search Nofollow:
0
Is Offline:
0
Security New:
1
Contact Id:
1
Design Id:

														
													
													
													
												
Search Title:

														
													
													
													
												
Security Contact Mode:

														
													
													
													
												
Security Contact Squeeze Viewlimit:

														
													
													
													
												
Security Heading:

														
													
													
													
												
Security Description:

														
													
													
													
												
Id:
/community/lost_password/
Parent Id:
/community/
Content:
<ss:templates:section>
<h1>Lost / Forgot Password</h1>
<p>Fill out the following form to reset your password.</p>

<ss:forms:form id="forgot_password_form" onsubmitprerenderserver="lostPassword($forgot_password_form)" onsubmitredirect="'/community/lost_password/success/?contact_email=' + $forgot_contact_email.value" parse="onsubmitredirect">

<ss:forms:row description="Enter the e-mail address that you registered with." label="E-mail Address">
<ss:forms:editbox id="forgot_contact_email" value="$_GET['contact_email']" parsenow="value" />
</ss:forms:row>

<ss:forms:row type="one_column" description="Type the characters you see in the picture on the left into the box on the right. Case insensitive." label="Enter the Code Below">
<ss:forms:captcha id="captcha" />
</ss:forms:row>

<ss:forms:row type="one_column" align="center">
<ss:forms:submitbutton value="Next &gt;" />
</ss:forms:row>
</ss:forms:form>
</ss:templates:section>
Php Source:
<?php

function sendToContact($arrContact)
{
// Generate new recovery token
$arrContact['contact_password_lost'] = \Framework\Random::randomString(10, true, true, false);
\Components\Customers\Contacts::$m_bIsSecurityDisabled = true;
\Components\Customers\Contacts::saveColumn($arrContact['contact_id'], 'contact_password_lost', $arrContact['contact_password_lost']);
\Components\Customers\Contacts::$m_bIsSecurityDisabled = false;

// Register variables
\Framework\DOM\CurrentContext::setVariable('contact', $arrContact);

// Send the email
$strSiteTitle = \Components\Settings\ConfigurationItems::getValue('\Components\Settings\MyAccount', 'account_title');

$pEmail = new \Framework\Mail\Message();
$pEmail->setTo($arrContact['contact_email']);
$pEmail->setFrom('noreply@' . \Components\Settings\Domains::getPrimary());
$pEmail->setFromName($strSiteTitle);
$pEmail->setSubject($strSiteTitle . ' - Lost Password');
$pEmail->setContentHTMLBodyFromPage('/community/lost_password/email/');
$pEmail->send();
}

function lostPassword($pForm)
{
$strEmail = $pForm->getFormItem('forgot_contact_email')->getValue();

if(!$strEmail)
{
$pException = new \Framework\Exceptions\Validation();
$pException->setTitle('Please fill in this field');
throw $pException;
}

$arrFilter = array();
$arrFilter[] = array('contact_email', '=', $strEmail);
$arrFilter[] = 'OR';
$arrFilter[] = array('contact_username', '=', $strEmail);

$arrProperties = array();
$arrProperties['filter'] = $arrFilter;
$arrContacts = \Components\Customers\Contacts::getAll($arrProperties);

$bSent = false;

// Try to find a contact that does have a password set
foreach($arrContacts as $arrContact)
{
// If the password was not set, skip
if(!\Components\Customers\Contacts\Passwords::getIsSetForContact($arrContact['contact_id']))
{
continue;
}

sendToContact($arrContact);
$bSent = true;
}

// Fall back to a contact that does not have a password
if(!$bSent && count($arrContacts))
{
sendToContact($arrContacts[0]);
$bSent = true;
}

// If we didnt send an email, throw a validation error
if(!$bSent)
{
$pException = new \Framework\Exceptions\Validation();
$pException->setTitle('Sorry, we do not recognise that e-mail address or username');
throw $pException;
}
}

?>