ref_page: ref_page
},
dataType: 'html',
- success: function(){
+ success: function(count){
+ updateList(count);
button.data('view', '1');
button.find('.trip-alt-text').removeClass('add_trip1');
button.find('.trip-alt-text').addClass('view_trip1');
window.location.href = load_page;
}
});
-
-jQuery('.glm-itinerary-delete').on('click', function(e){
- e.preventDefault();
- var member_id = jQuery(this).data('id');
- var base_url = jQuery(this).data('baseurl');
- var button = jQuery(this);
- if ( member_id ) {
- jQuery.ajax({
- url: base_url + '/wp-admin/admin-ajax.php',
- cache: false,
- data: {
- action: 'glm_members_admin_ajax',
- glm_action: 'itineraryList',
- member_id: member_id,
- del: true
- },
- success: function(){
- button.parent('.glm-itinerary-list-item').remove();
- }
- });
+function updateList(listCount){
+ if(listCount > 0) {
+ $(".trip-list-count").html(listCount + " item(s) in your trip planner");
+ } else {
+ $(".trip-list-count").html("Make the most of your getaway!");
}
- return false;
-});
+}
jQuery('.glm-itinerary-request-delete').on('click', function(e){
e.preventDefault();
var member_id = jQuery(this).data('id');
$userLoggedIn = false;
$loginFailed = false;
$createSuccess = false;
+ $email = false;
+ $token = false;
$members = array();
$membersWithEmails = array();
$memberEmails = array();
case 'forgot':
$view = 'forgot.html';
break;
+ case 'emailReset':
+ $email = filter_var( $_REQUEST['email'], FILTER_VALIDATE_EMAIL );
+ $token = filter_var( $_REQUEST['token'], FILTER_SANITIZE_STRING );
+ if ( $email ) {
+ $emailFound = $this->wpdb->get_row(
+ $this->wpdb->prepare(
+ "SELECT id,reset_token
+ FROM " . GLM_MEMBERS_ITINERARY_PLUGIN_DB_PREFIX . "user
+ WHERE email = %s",
+ $email
+ ),
+ ARRAY_A
+ );
+ if ( isset( $emailFound ) && isset( $emailFound['reset_token'] ) ) {
+ // See if the resetToken matches
+ if ( $emailFound['reset_token'] == $token ) {
+ // echo '<pre>$token (matches): ' . print_r( $token, true ) . '</pre>';
+ $view = 'passwordResetForm.html';
+ if ( isset( $_REQUEST['new_pass'] ) && $newPassword = filter_var( $_REQUEST['new_pass'], FILTER_SANITIZE_STRING ) ) {
+ // echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
+ // empty the reset_token and update password
+ $this->wpdb->update(
+ GLM_MEMBERS_ITINERARY_PLUGIN_DB_PREFIX . 'user',
+ array( 'reset_token' => '', 'password' => md5( $newPassword ) ),
+ array( 'id' => $emailFound['id'] ),
+ array( '%s', '%s' ),
+ array( '%d' )
+ );
+ $createSuccess = true;
+ }
+ } else {
+ $formErrors['user'] = true;
+ // echo '<pre>$token (NOT A MATCH): ' . print_r( $token, true ) . '</pre>';
+ $view = 'forgot.html';
+ }
+
+ }
+ }
+ // $view = 'passwordResetForm.html';
+ break;
case 'reset':
// Search for the email.
// If not found then say something about not finding the account and link to the new account form.
// If found then send the email reset.
- $email = filter_var( $_REQUEST['username'], FILTER_VALIDATE_EMAIL );
+ $email = filter_var( $_REQUEST['email'], FILTER_VALIDATE_EMAIL );
+ // echo '<pre>$email: ' . print_r( $email, true ) . '</pre>';
if ( $email ) {
$emailFound = $this->wpdb->get_var(
$this->wpdb->prepare(
$email
)
);
+ // echo '<pre>$emailFound: ' . print_r( $emailFound, true ) . '</pre>';
if ( $emailFound ) {
// Setup the email message.
// Create the md5 reset token.
+ $resetToken = md5( $email . time() );
+ $this->wpdb->update(
+ GLM_MEMBERS_ITINERARY_PLUGIN_DB_PREFIX . 'user',
+ array( 'reset_token' => $resetToken ),
+ array( 'id' => $emailFound ),
+ array( '%s' ),
+ array( '%d' )
+ );
// Send email.
+ // echo '<pre>$resetToken: ' . print_r( $resetToken, true ) . '</pre>';
+ $this->sendResetEmail( $email, $resetToken );
+ } else {
+ $formErrors['user'] = true;
}
} else {
// No email given
+ $formErrors['user'] = true;
}
+ // Show message about email.
+ $view = 'passwordReset.html';
break;
case 'moreinfo':
// Need to create two list one with emails and one without.
'formErrors' => $formErrors,
'createSuccess' => $createSuccess,
'userInfo' => $userInfo,
+ 'email' => $email,
+ 'token' => $token,
);
error_reporting(E_ALL ^ E_NOTICE);
'data' => $templateData,
);
}
+
+ /**
+ * Send password reset link.
+ *
+ * @param string $email Email To:
+ * @param string $resetToken Reset token
+ *
+ * @return void
+ */
+ public function sendResetEmail( $email, $resetToken )
+ {
+ $subject = 'Your password reset instructions';
+ $from_header = 'Test Server <dev@gaslightmedia.com>';
+ $smarty = new smartyTemplateSupport();
+ $viewPath = GLM_MEMBERS_ITINERARY_PLUGIN_PATH . '/views';
+ $smarty->template->setTemplateDir( $viewPath );
+ $viewFile = 'front/itinerary/passwordResetEmail.html';
+
+ $smarty->templateAssign( 'title', $subject );
+ $smarty->templateAssign( 'email', $email );
+ $smarty->templateAssign( 'resetToken', $resetToken );
+ $smarty->templateAssign( 'tripPage', get_permalink( $this->config['settings']['itinerary_page'] ) );
+
+ // Generate output from model data and view
+ $htmlMessage = $smarty->template->fetch( $viewFile );
+
+ // change the default wordpress from name when sending mail
+ add_filter(
+ 'wp_mail_from_name',
+ function ( $name ) {
+ $siteName = get_bloginfo( 'name' );
+ return $siteName;
+ }
+ );
+ // Send confirmation email, set the content type to allow html by using this filter
+ add_filter( 'wp_mail_content_type', array( $this, 'set_content_type' ) );
+
+ $message = $htmlMessage;
+ $header[] = 'From:' . $from_header;
+ if ( $replyto ) {
+ $header[] = 'Reply-To:' . $replyto;
+ }
+
+ wp_mail( $email, $subject, $message, $header );
+
+ // remove the filter to avoid conflicts
+ remove_filter( 'wp_mail_content_type', array( $this, 'set_content_type' ) );
+ }
+
+ /**
+ * Set content type of the email.
+ *
+ * Used as filter for the wp_mail_content_type
+ */
+ function set_content_type()
+ {
+ return "text/html";
+ }
}
<h2>Password Recovery</h2>
-<div class="glm_row">
+{if isset($formErrors) && !empty($formErrors)}
+ <p>There was an error.</p>
+ <p><a href="{$thisUrl}">Go to Trip Planner</a></p>
+{else}
+ <div class="glm_row">
- <form action="{$thisUrl}" method="post">
- <p>Enter your email address.</p>
- <input type="hidden" name="option" value="reset" />
- <div class="glm-columns glm-small-12 glm-medium-4">
- <label for="email" class="glm-required"> Email </label>
- <input type="email" id="email" name="email" />
- <input type="submit" value="Password Recovery" class="button" />
- </div>
- </form>
+ <form action="{$thisUrl}" method="post">
+ <p>Enter your email address.</p>
+ <input type="hidden" name="option" value="reset" />
+ <div class="glm-columns glm-small-12 glm-medium-4">
+ <label for="email" class="glm-required"> Email </label>
+ <input type="email" id="email" name="email" />
+ <input type="submit" value="Password Recovery" class="button" />
+ </div>
+ </form>
-</div>
+ </div>
+{/if}