My anonymous test email keeps getting saved search results sent to it every day without the ability to manage it. How do I allow anonymous users to remove themselves from the search result mailing list?

Here is the email with the unprocessed token.

Anonymous,

There are new results for your saved search on Marine Jobs:

New results for search "Saved search":
This is best job ever
(http://examplejobs.com/united-states/florida/customer-service-agent/best-job-ever-22)

You can configure your saved searches at the following address:
[user:search-api-saved-searches-url]

--  Marine Jobs team

Comments

Adam S’s picture

Status: Active » Fixed

I read it once then read it again and found this token [search-api-saved-search:delete-url]. That should do the job.

Adam S’s picture

I'm opening this again because this token should either be added to the default or added to documentation somewhere so it is more intuitive.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

drunken monkey’s picture

Title: How are Anonymous users supposed to manage saved searches? » Fix token handling for anonymous users
Status: Closed (fixed) » Needs review

Would the attached patch be suitable in your opinion?

Adam S’s picture

Which patch?

drunken monkey’s picture

fangel’s picture

I'd say the patch is a step in the right direction. But now the standard email for anonymous users, would be

---
You can configure your saved searches at the following address:

---

Which is kinda un-intuitive, as it says "at this address", and then doesn't list one.

How about substituting the [user:search-api-saved-searches-url]-token with "You need to have a user account to edit your saved searches", or something to that effect?

Regards
Morten

RAWDESK’s picture

Issue summary: View changes
StatusFileSize
new30.65 KB

Hi,

I've been testing this saved search module also recently and would like to share my comments on its usability for anonymous users.
In attachment you can find my implemented save searches block.
This is the place most users would return to if they'd like to alter or re-execute their search manually.
Therefore the token [user:search-api-saved-searches-url] is part of my description and guideline to earlier performed searches.
I think it is essential at e-mail activation that an anonymous user is informed about the fact an account will be created automatically by confirming his first search action.
So rather then providing a delete link inside the search notification emails, it would be better to facilitate customer (re-)engagement by means of a login.
Hence, one could even attach a reduction coupon to this first engagement effort.. to drive more sales.

Technically, what would be needed to have the account creation implemented behind a first saved search ?

RAWDESK’s picture

Hi,

I just answered my own last question by adding this code into the search_api_saved_searches_save_form_submit() function of search_api_saved_searches module.

New code starts from the comment line // If user is still unknown...

  $uid = $user->uid;
  if (!$uid && ($users = user_load_multiple(FALSE, array('mail' => $values['mail'], 'status' => 1)))) {
    $uid = key($users);
  }
  // If user is still unknown to the users list, create a new user account and send account activation mail
  if (!$uid) {
	$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_-=+;:,.?";
	$password = substr(str_shuffle($chars), 0, 12);
	$username = substr($values['mail'], 0, strpos($values['mail'], '@'));

	$new_user = array(
	  'name' => $username,
	  'mail' => $values['mail'],
	  'pass' => $password,
	  'status' => 1,
	  'access' => REQUEST_TIME,
	  'roles' => array(), // No other roles than Authenticated
	);
	$account = user_save(NULL, $new_user);
	$user = $account;
	$uid = $user->uid;
	$op = 'register_admin_created';
   	_user_mail_notify($op, $account);
  }

The anonymous user now receives 2 emails :
-first : the user registration confirmation, which holds a one-time login link to (re)set the password
-second : confirmation of the saved search and invitation to enable the email update subscription.

drunken monkey’s picture

Since the issue is bumped already, here is a re-roll of the patch, as well as a version without the message default change.
If no-one complains, I guess I'll commit the fix-only version, since it still appears to be relevant.

rksadit’s picture

Im using search_api_saved_search block. i want to redirect my page to login page for anonymous users, when they click on save button.can anyone help me to achieve this?

  • drunken monkey committed e9057c1 on 7.x-1.x
    Issue #1306622 by drunken monkey: Fixed token handling for anonymous...
drunken monkey’s picture

Status: Needs review » Fixed

OK, committed the fix-only version. Please re-open, or open a new issue, if you have good suggestions on how to improve this further.

@rksadit: You probably need to implement hook_form_search_api_saved_searches_save_form_alter() and add a fitting $form_state['#redirect'] either there or, probably, in a submit handler.
However, please create a new issue for such questions next time, it doesn't really have anything to do with this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.