/** * Called on successful user login * If they are not in stormpath lets add them * * @param type $event * @param type $type * @param type $user */ function event_user_login($event, $type, $user) { $access_status = access_get_show_hidden_status(); access_show_hidden_entities(TRUE); if ($user instanceof ElggUser && !$user->isEnabled() && !$user->validated) { // send new validation email uservalidationbyemail_request_validation($user->getGUID()); // restore hidden entities settings access_show_hidden_entities($access_status); // throw error so we get a nice error message throw new LoginException(elgg_echo('uservalidationbyemail:login:fail')); } access_show_hidden_entities($access_status); if ($user->__stormpath_user) { return true; } // search stormpath for a matching account // may be in stormpath by manual addition, or from another application // with shared login $application = get_application(); if ($application) { $accts = $application->getAccounts(array('email' => $user->email)); foreach ($accts as $a) { $user->__stormpath_user = $a->href; return true; } $password = get_input('password'); if ($password) { add_to_stormpath($user, $password); } } return true; }
/** * Request email validation. */ function uservalidationbyemail_email_validation($event, $object_type, $object) { if ($object && $object instanceof ElggUser) { uservalidationbyemail_request_validation($object->guid); } return true; }
/** * Prevent a manual code login with login(). * * @param string $event * @param string $type * @param ElggUser $user * @return bool * * @throws LoginException */ function uservalidationbyemail_check_manual_login($event, $type, $user) { $access_status = access_get_show_hidden_status(); access_show_hidden_entities(TRUE); if ($user instanceof ElggUser && !$user->isEnabled() && !$user->validated) { // send new validation email uservalidationbyemail_request_validation($user->getGUID()); // restore hidden entities settings access_show_hidden_entities($access_status); // throw error so we get a nice error message throw new LoginException(elgg_echo('uservalidationbyemail:login:fail')); } access_show_hidden_entities($access_status); }
$error = FALSE; if (!$user_guids) { register_error(elgg_echo('uservalidationbyemail:errors:unknown_users')); forward(REFERRER); } $access = access_get_show_hidden_status(); access_show_hidden_entities(TRUE); foreach ($user_guids as $guid) { $user = get_entity($guid); if (!$user instanceof ElggUser) { $error = TRUE; continue; } // don't resend emails to validated users $is_validated = elgg_get_user_validation_status($guid); if ($is_validated !== FALSE || !uservalidationbyemail_request_validation($guid)) { $error = TRUE; continue; } } access_show_hidden_entities($access); if (count($user_guids) == 1) { $message_txt = elgg_echo('uservalidationbyemail:messages:resent_validation'); $error_txt = elgg_echo('uservalidationbyemail:errors:could_not_resend_validation'); } else { $message_txt = elgg_echo('uservalidationbyemail:messages:resent_validations'); $error_txt = elgg_echo('uservalidationbyemail:errors:could_not_resend_validations'); } if ($error) { register_error($error_txt); } else {
/** * Checks if an account is validated * * @params array $credentials The username and password * @return bool */ function uservalidationbyemail_check_auth_attempt($credentials) { if (!isset($credentials['username'])) { return; } $username = $credentials['username']; // See if the user exists and isn't validated $access_status = access_get_show_hidden_status(); access_show_hidden_entities(TRUE); $user = get_user_by_username($username); if ($user && isset($user->validated) && !$user->validated) { // show an error and resend validation email uservalidationbyemail_request_validation($user->guid); access_show_hidden_entities($access_status); throw new LoginException(elgg_echo('uservalidationbyemail:login:fail')); } access_show_hidden_entities($access_status); }
// Set access status to perform needed operation $access_status = access_get_show_hidden_status(); access_show_hidden_entities(true); // Get user guid $user_guid = (int) get_input('user_guid'); $new_email = get_input('new_email'); // Check if user guid is provided if (!empty($user_guid) && !empty($new_email)) { $user = get_entity($user_guid); // Check if user exists if (elgg_instanceof($user, 'user')) { // Check if provided email address is valid if (validate_email_address($new_email)) { elgg_set_ignore_access(true); elgg_override_permissions(true); // Change user email $user->email = $new_email; $user->save(); system_message(elgg_echo('welcome:user_email_changed_to', array($user->name, $new_email))); uservalidationbyemail_request_validation($user->guid); } else { register_error(elgg_echo('welcome:email_address_invalid', array($new_email))); } } else { register_error(elgg_echo('welcome:no_user_guid_provided')); } } else { register_error(elgg_echo('welcome:no_user_guid_provided')); } access_show_hidden_entities($access_status); forward($_SERVER['HTTP_REFERER']);