/** * Listen to the join site event * * @param string $event the name of the event * @param string $type the type of the event * @param mixed $object supplied object * * @return void */ function theme_haarlem_intranet_site_join_event($event, $type, $object) { if (empty($object) || !$object instanceof ElggRelationship) { return; } $user_guid = (int) $object->guid_one; // enable site notifications for the new user set_user_notification_setting($user_guid, 'site', true); // enable mentions notifications for the new user elgg_set_plugin_user_setting('notify', '1', $user_guid, 'mentions'); }
/** * This function checks and if necessary sets the email notifications to disabled the first time a user logs in * @param String $event * @param String $object_type * @param Object $object */ function set_no_notifications_clear_user_meta($event, $object_type, $object) { // check if the user should be considered if (elgg_get_plugin_setting('setNoNotif_time', 'set_no_notifications') < $object->time_created) { if ($event == 'login:after' && $object_type == 'user' && $object instanceof ElggUser) { $time = elgg_get_plugin_setting('setNoNotif_time', 'set_no_notifications'); if (!$object->set_no_notifications && $object->time_created > $time) { $method = array('email' => 'no'); $result = false; foreach ($method as $k => $v) { $result = set_user_notification_setting($object['user']->guid, $k, $v == 'yes' ? true : false); if (!$result) { $object->set_no_notifications = false; } else { $object->set_no_notifications = true; } } } } } return true; }
function update_user_personal_notifications_settings($guid, $metodos) { switch ($metodos) { case 'email': set_user_notification_setting($guid, 'site', false); set_user_notification_setting($guid, 'email', true); break; case 'site': set_user_notification_setting($guid, 'site', true); set_user_notification_setting($guid, 'email', false); break; case 'todos': set_user_notification_setting($guid, 'site', true); set_user_notification_setting($guid, 'email', true); break; case 'ninguno': set_user_notification_setting($guid, 'site', false); set_user_notification_setting($guid, 'email', false); default: // (metodo = nocambiar) break; } }
/** * Registers a user, returning false if the username already exists * * @param string $username The username of the new user * @param string $password The password * @param string $name The user's display name * @param string $email Their email address * @param bool $allow_multiple_emails Allow the same email address to be registered multiple times? * @param int $friend_guid Optionally, GUID of a user this user will friend once fully registered * @return int|false The new user's GUID; false on failure */ function register_user($username, $password, $name, $email, $allow_multiple_emails = false, $friend_guid = 0, $invitecode = '') { // Load the configuration global $CONFIG; $username = trim($username); $password = trim($password); $name = trim($name); $email = trim($email); // A little sanity checking if (empty($username) || empty($password) || empty($name) || empty($email)) { return false; } // See if it exists and is disabled $access_status = access_get_show_hidden_status(); access_show_hidden_entities(true); // Validate email address if (!validate_email_address($email)) { throw new RegistrationException(elgg_echo('registration:emailnotvalid')); } // Validate password if (!validate_password($password)) { throw new RegistrationException(elgg_echo('registration:passwordnotvalid')); } // Validate the username if (!validate_username($username)) { throw new RegistrationException(elgg_echo('registration:usernamenotvalid')); } // Check to see if $username exists already if ($user = get_user_by_username($username)) { //return false; throw new RegistrationException(elgg_echo('registration:userexists')); } // If we're not allowed multiple emails then see if this address has been used before if (!$allow_multiple_emails && get_user_by_email($email)) { throw new RegistrationException(elgg_echo('registration:dupeemail')); } access_show_hidden_entities($access_status); // Check to see if we've registered the first admin yet. // If not, this is the first admin user! $admin = datalist_get('admin_registered'); // Otherwise ... $user = new ElggUser(); $user->username = $username; $user->email = $email; $user->name = $name; $user->access_id = ACCESS_PUBLIC; $user->salt = generate_random_cleartext_password(); // Note salt generated before password! $user->password = generate_user_password($user, $password); $user->owner_guid = 0; // Users aren't owned by anyone, even if they are admin created. $user->container_guid = 0; // Users aren't contained by anyone, even if they are admin created. $user->save(); // If $friend_guid has been set, make mutual friends if ($friend_guid) { if ($friend_user = get_user($friend_guid)) { if ($invitecode == generate_invite_code($friend_user->username)) { $user->addFriend($friend_guid); $friend_user->addFriend($user->guid); } } } global $registering_admin; if (!$admin) { $user->admin = true; datalist_set('admin_registered', 1); $registering_admin = true; } else { $registering_admin = false; } // Turn on email notifications by default set_user_notification_setting($user->getGUID(), 'email', true); return $user->getGUID(); }
/** * Registers a user, returning false if the username already exists * * @param string $username The username of the new user * @param string $password The password * @param string $name The user's display name * @param string $email Their email address * @param bool $allow_multiple_emails Allow the same email address to be * registered multiple times? * @param int $friend_guid GUID of a user to friend once fully registered * @param string $invitecode An invite code from a friend * * @return int|false The new user's GUID; false on failure */ function register_user($username, $password, $name, $email, $allow_multiple_emails = false, $friend_guid = 0, $invitecode = '') { // Load the configuration global $CONFIG; // no need to trim password. $username = trim($username); $name = trim(strip_tags($name)); $email = trim($email); // A little sanity checking if (empty($username) || empty($password) || empty($name) || empty($email)) { return false; } // Make sure a user with conflicting details hasn't registered and been disabled $access_status = access_get_show_hidden_status(); access_show_hidden_entities(true); if (!validate_email_address($email)) { throw new RegistrationException(elgg_echo('registration:emailnotvalid')); } if (!validate_password($password)) { throw new RegistrationException(elgg_echo('registration:passwordnotvalid')); } if (!validate_username($username)) { throw new RegistrationException(elgg_echo('registration:usernamenotvalid')); } if ($user = get_user_by_username($username)) { throw new RegistrationException(elgg_echo('registration:userexists')); } if (!$allow_multiple_emails && get_user_by_email($email)) { throw new RegistrationException(elgg_echo('registration:dupeemail')); } access_show_hidden_entities($access_status); // Create user $user = new ElggUser(); $user->username = $username; $user->email = $email; $user->name = $name; $user->access_id = ACCESS_PUBLIC; $user->salt = generate_random_cleartext_password(); // Note salt generated before password! $user->password = generate_user_password($user, $password); $user->owner_guid = 0; // Users aren't owned by anyone, even if they are admin created. $user->container_guid = 0; // Users aren't contained by anyone, even if they are admin created. $user->language = get_current_language(); $user->save(); // If $friend_guid has been set, make mutual friends if ($friend_guid) { if ($friend_user = get_user($friend_guid)) { if ($invitecode == generate_invite_code($friend_user->username)) { $user->addFriend($friend_guid); $friend_user->addFriend($user->guid); // @todo Should this be in addFriend? add_to_river('river/relationship/friend/create', 'friend', $user->getGUID(), $friend_guid); add_to_river('river/relationship/friend/create', 'friend', $friend_guid, $user->getGUID()); } } } // Turn on email notifications by default set_user_notification_setting($user->getGUID(), 'email', true); return $user->getGUID(); }
<?php /** * Reset all mentions settings to enable notifications */ // may take a while set_time_limit(0); $options = array('type' => 'user', 'limit' => false, 'relationship' => 'member_of_site', 'relationship_guid' => elgg_get_site_entity()->getGUID(), 'inverse_relationship' => true); $counter = 0; $users = new ElggBatch('elgg_get_entities_from_relationship', $options); foreach ($users as $user) { $counter++; elgg_set_plugin_user_setting('notify', '1', $user->getGUID(), 'mentions'); set_user_notification_setting($user->getGUID(), 'site', true); } system_message(elgg_echo('theme_haarlem_intranet:action:mentions:reset', array($counter))); forward(REFERER);
<?php /** * Elgg notifications user preference save acion. * * @package Elgg * @subpackage Core * @author Curverider Ltd * @link http://elgg.org/ */ // Method $method = get_input('method'); gatekeeper(); $result = false; foreach ($method as $k => $v) { $result = set_user_notification_setting($_SESSION['user']->guid, $k, $v == 'yes' ? true : false); if (!$result) { register_error(elgg_echo('notifications:usersettings:save:fail')); } } if ($result) { system_message(elgg_echo('notifications:usersettings:save:ok')); } else { register_error(elgg_echo('notifications:usersettings:save:fail')); }
/** * Save personal notification settings - input comes from request * * @return void * @access private */ function _elgg_save_notification_user_settings() { $method = get_input('method'); $current_settings = get_user_notification_settings(); $result = false; foreach ($method as $k => $v) { // check if setting has changed and skip if not if ($current_settings->{$k} == ($v == 'yes')) { continue; } $result = set_user_notification_setting(elgg_get_logged_in_user_guid(), $k, $v == 'yes' ? true : false); if (!$result) { register_error(elgg_echo('notifications:usersettings:save:fail')); } } if ($result) { system_message(elgg_echo('notifications:usersettings:save:ok')); } }
<?php /** * Elgg notifications * * @package ElggNotifications */ $user = elgg_get_logged_in_user_entity(); $result = false; $changed = false; $old_settings = get_user_notification_settings($user->guid); global $NOTIFICATION_HANDLERS; foreach ($NOTIFICATION_HANDLERS as $method => $foo) { $personal[$method] = get_input($method . 'personal'); if ($old_settings->{$method} && $personal[$method] == '1' || !$old_settings->{$method} && $personal[$method] != '1') { continue; } $result = set_user_notification_setting($user->guid, $method, $personal[$method] == '1' ? true : false); if (!$result) { register_error(elgg_echo('notifications:usersettings:save:fail') . elgg_echo("zhaohu:sorry")); elgg_log("ZHError , error calling set_user_notification_setting, user id " . $user->guid, "ERROR"); forward(REFERER); } else { $changed = true; } } if ($changed) { system_message(elgg_echo('notifications:subscriptions:success')); }
/** * Registers a user, returning false if the username already exists * * @param string $username The username of the new user * @param string $password The password * @param string $name The user's display name * @param string $email The user's email address * @param bool $allow_multiple_emails Allow the same email address to be * registered multiple times? * * @return int|false The new user's GUID; false on failure * @throws \RegistrationException */ function register($username, $password, $name, $email, $allow_multiple_emails = false) { // no need to trim password. $username = trim($username); $name = trim(strip_tags($name)); $email = trim($email); // A little sanity checking if (empty($username) || empty($password) || empty($name) || empty($email)) { return false; } // Make sure a user with conflicting details hasn't registered and been disabled $access_status = access_get_show_hidden_status(); access_show_hidden_entities(true); if (!validate_email_address($email)) { throw new \RegistrationException(_elgg_services()->translator->translate('registration:emailnotvalid')); } if (!validate_password($password)) { throw new \RegistrationException(_elgg_services()->translator->translate('registration:passwordnotvalid')); } if (!validate_username($username)) { throw new \RegistrationException(_elgg_services()->translator->translate('registration:usernamenotvalid')); } if ($user = get_user_by_username($username)) { throw new \RegistrationException(_elgg_services()->translator->translate('registration:userexists')); } if (!$allow_multiple_emails && get_user_by_email($email)) { throw new \RegistrationException(_elgg_services()->translator->translate('registration:dupeemail')); } access_show_hidden_entities($access_status); // Create user $user = new \ElggUser(); $user->username = $username; $user->email = $email; $user->name = $name; $user->access_id = ACCESS_PUBLIC; $user->setPassword($password); $user->owner_guid = 0; // Users aren't owned by anyone, even if they are admin created. $user->container_guid = 0; // Users aren't contained by anyone, even if they are admin created. $user->language = _elgg_services()->translator->getCurrentLanguage(); if ($user->save() === false) { return false; } // Turn on email notifications by default set_user_notification_setting($user->getGUID(), 'email', true); return $user->getGUID(); }
function social_connect_handle_authentication($user_profile, $provider) { global $CONFIG; global $HA_SOCIAL_CONNECT_PROVIDERS_CONFIG; $ignore_access = elgg_get_ignore_access(); $provider_name = $HA_SOCIAL_CONNECT_PROVIDERS_CONFIG[$provider]['provider_name']; $user_uid = $user_profile->identifier; // establish the value for the proceeding hook $default_proceed = elgg_get_plugin_setting("ha_settings_{$provider}_hook1_default", 'social_connect'); if (!$default_proceed || $default_proceed == 'global') { $default_proceed = elgg_get_plugin_setting('ha_settings_hook1_default', 'social_connect'); } if (!$default_proceed) { $default_proceed = SOCIAL_CONNECT_DEFAULT_PROCEED; } else { if ($default_proceed == 'true') { $default_proceed = true; } else { if ($default_proceed == 'false') { $default_proceed = false; } } } // the arguments for social connect events and hooks $args = array('mode' => null, 'userid' => $user_uid, 'provider' => $HA_SOCIAL_CONNECT_PROVIDERS_CONFIG[$provider], 'user' => null, 'profile' => $user_profile); // look for users that have already connected via this plugin $options = array('type' => 'user', 'plugin_id' => 'social_connect', 'plugin_user_setting_name_value_pairs' => array("{$provider}/uid" => $user_uid), 'plugin_user_setting_name_value_pairs_operator' => 'AND', 'limit' => 0); $users = elgg_get_entities_from_plugin_user_settings($options); if (!$users) { // user has not connected with plugin before $args['mode'] = 'connect'; elgg_set_ignore_access(true); $proceed = elgg_trigger_plugin_hook('social_connect', 'user', $args, $default_proceed); elgg_set_ignore_access($ignore_access); if ($proceed === false) { // hook prevented social connection return; } else { if ($proceed === 'email' || $proceed === 'emailOnly') { // hook wants to try and connect via email address // check whether the user already exists with the email provided $useremail = $user_profile->email; if ($useremail && ($users = get_user_by_email($useremail))) { social_connect_user($user_uid, $users[0], $user_profile, $provider); system_message(sprintf(elgg_echo('social_connect:connect:ok'), $provider_name)); $args['mode'] = 'email'; $args['user'] = $users[0]; elgg_set_ignore_access(true); elgg_trigger_event('social_connect', 'user', $args); elgg_set_ignore_access($ignore_access); return; } if ($proceed === 'emailOnly') { // hook wants only email address connection or failure register_error(sprintf(elgg_echo('social_connect:connect:emailnotfound'), $proceed)); return; } } } // email connection not required or failed, so register a new user $userlogin = str_replace(' ', '', $user_profile->displayName); if (!$userlogin) { $userlogin = $provider . '_user_' . rand(1000, 9999); } $org_userlogin = $userlogin; while (get_user_by_username($userlogin)) { $userlogin = $org_userlogin . '_' . rand(1000, 9999); } unset($org_userlogin); $password = generate_random_cleartext_password(); $username = $user_profile->displayName; $user = new ElggUser(); $user->username = $userlogin; $user->name = $username; $user->email = $user_profile->email; $user->access_id = ACCESS_PUBLIC; $user->salt = generate_random_cleartext_password(); $user->password = generate_user_password($user, $password); $user->owner_guid = 0; $user->container_guid = 0; if ($user->save()) { if ($user->email && elgg_get_plugin_setting('notify_new_user', 'social_connect')) { $email = elgg_echo('email:social_connect:body', array($userlogin, $password)); set_user_notification_setting($user->getGUID(), 'email', true); notify_user($user->guid, $CONFIG->site->guid, elgg_echo('email:social_connect:subject', array($provider_name)), $email, NULL, 'email'); } } else { register_error(sprintf(elgg_echo('social_connect:register:bad'), $provider_name) . elgg_echo("zhaohu:sorry")); elgg_log("ZHError social_connect:register:bad , userlogin {$userlogin}", "ERROR"); return; } system_message(sprintf(elgg_echo('social_connect:register:ok'), $provider_name)); social_connect_user($user_uid, $user, $user_profile, $provider); $args['mode'] = 'register'; $args['user'] = $user; elgg_set_ignore_access(true); elgg_trigger_event('social_connect', 'user', $args); elgg_set_ignore_access($ignore_access); } elseif (count($users) == 1) { // one user has already been registered on Elgg with this provider $args['mode'] = 'login'; $args['user'] = $users[0]; elgg_set_ignore_access(true); if (elgg_trigger_plugin_hook('social_connect', 'user', $args, (bool) $default_proceed)) { // if not, hook prevented social connection login($users[0]); system_message(sprintf(elgg_echo('social_connect:login:ok'), $provider_name)); } elgg_set_ignore_access($ignore_access); } else { throw new Exception(sprintf(elgg_echo('social_connect:login:bad'), $provider_name)); } }
} if ($avatar_error) { foreach ($files as $file) { $file->delete(); } } else { $user->x1 = 0; $user->x2 = 0; $user->y1 = 0; $user->y2 = 0; $user->icontime = time(); elgg_create_river_item(array('view' => 'river/user/default/profileiconupdate', 'action_type' => 'update', 'subject_guid' => $user->guid, 'object_guid' => $user->guid)); } $filehandler->delete(); } elgg_set_user_validation_status($user->guid, true, 'FAKER'); if ($user->save()) { $success++; set_user_notification_setting($user->guid, 'email', false); set_user_notification_setting($user->guid, 'site', true); } else { $error++; } } } if ($errors) { system_message(elgg_echo('faker:gen_users:error', array($success, $error, implode('<br />', $exceptions)))); } else { system_message(elgg_echo('faker:gen_users:success', array($success))); } forward(REFERER);
* Elgg notifications * * @package ElggNotifications * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 * @author Curverider Ltd * @copyright Curverider Ltd 2008-2009 * @link http://elgg.com/ */ // Restrict to logged in users gatekeeper(); global $SESSION; global $NOTIFICATION_HANDLERS; foreach ($NOTIFICATION_HANDLERS as $method => $foo) { $subscriptions[$method] = get_input($method . 'subscriptions'); $personal[$method] = get_input($method . 'personal'); $collections[$method] = get_input($method . 'collections'); $metaname = 'collections_notifications_preferences_' . $method; $_SESSION['user']->{$metaname} = $collections[$method]; set_user_notification_setting($_SESSION['user']->guid, $method, $personal[$method] == '1' ? true : false); remove_entity_relationships($SESSION['user']->guid, 'notify' . $method, false, 'user'); } // Add new ones foreach ($subscriptions as $key => $subscription) { if (is_array($subscription) && !empty($subscription)) { foreach ($subscription as $subscriptionperson) { add_entity_relationship($_SESSION['user']->guid, 'notify' . $key, $subscriptionperson); } } } system_message(elgg_echo('notifications:subscriptions:success')); forward($_SERVER['HTTP_REFERER']);
elgg_set_context($context); // we have no local users, create a new one $user = new \ElggUser(); $user->username = preg_replace("/[^a-zA-Z0-9]/", "", $account->username); $user->email = $account->email; $user->name = $account->fullName; $user->access_id = ACCESS_PUBLIC; $user->salt = _elgg_generate_password_salt(); // set invalid PW that will never work for local login. This can be changed by the user later // but won't leave a secondary local login by accident $user->password = _elgg_generate_password_salt(); $user->owner_guid = 0; // Users aren't owned by anyone, even if they are admin created. $user->container_guid = 0; // Users aren't contained by anyone, even if they are admin created. $user->language = get_current_language(); $user->save(); $user->__stormpath_user = $account->href; elgg_set_user_validation_status($user->guid, TRUE, 'stormpath'); // Turn on email notifications by default set_user_notification_setting($user->getGUID(), 'email', true); // done with our extra permissions elgg_pop_context(); login($user, true); if ($user[0]->language) { $message = elgg_echo('loginok', array(), $user[0]->language); } else { $message = elgg_echo('loginok'); } system_message($message); forward($login_forward);
<?php /** * Elgg notifications user preference save acion. * * @package Elgg * @subpackage Core */ $method = get_input('method'); $current_settings = get_user_notification_settings(); $result = false; foreach ($method as $k => $v) { // check if setting has changed and skip if not if ($current_settings->{$k} == ($v == 'yes')) { continue; } $result = set_user_notification_setting(elgg_get_logged_in_user_guid(), $k, $v == 'yes' ? true : false); if (!$result) { register_error(elgg_echo('notifications:usersettings:save:fail')); } } if ($result) { system_message(elgg_echo('notifications:usersettings:save:ok')); }
/** * Can we allow the user with the credentials to log in? * Check stormpath, create the user if they can log in and don't exist * Enable the user if they can log in but were waiting for email verification * * @param type $credentials * @return boolean */ function pam_handler($credentials) { // try to authenticate first $application = get_application(); $authResult = $application->authenticate($credentials['username'], $credentials['password']); $account = $authResult->account; if (!$account || strtolower($account->status) != 'enabled') { return false; } // we need to search hidden users too // in case of email confirmation disabling $show_hidden = access_get_show_hidden_status(); access_show_hidden_entities(true); // we have an account and it's enabled // see if we have a matching account here // check if logging in with email address if (strpos($credentials['username'], '@') !== false) { $users = get_user_by_email($credentials['username']); $user = $users[0]; } else { $user = get_user_by_username($credentials['username']); } // custom context gives us permission to do this elgg_push_context('stormpath_validate_user'); // if we don't have a user we need to create one if (!$user) { $user = new \ElggUser(); $user->username = preg_replace("/[^a-zA-Z0-9]/", "", $account->username); $user->email = $account->email; $user->name = $account->fullName; $user->access_id = ACCESS_PUBLIC; $user->salt = _elgg_generate_password_salt(); $user->password = generate_user_password($user, $credentials['password']); $user->owner_guid = 0; // Users aren't owned by anyone, even if they are admin created. $user->container_guid = 0; // Users aren't contained by anyone, even if they are admin created. $user->language = get_current_language(); $user->save(); $user->__stormpath_user = $account->href; elgg_set_user_validation_status($user->guid, TRUE, 'stormpath'); // Turn on email notifications by default set_user_notification_setting($user->getGUID(), 'email', true); } // see if we need to enable/verify the user if (!$user->isEnabled() && in_array($user->disable_reason, array('stormpath_new_user', 'uservalidationbyemail_new_user'))) { $user->enable(); $user->__stormpath_user = $account->href; elgg_set_user_validation_status($user->guid, TRUE, 'stormpath'); } elgg_pop_context(); access_show_hidden_entities($show_hidden); if ($user && $user->isEnabled()) { return true; } return false; }