public function get_user_id() { try { // don't use $_REQUEST as it can do funny things escaping quotes etc. $request = array_merge($_GET, $_POST); // authenticate requesting website for this service. This can create a user, so need write // permission. $this->authenticate('write'); echo json_encode(user_identifier::get_user_id($request, $this->website_id)); } catch (Exception $e) { $this->handle_error($e); } }
public function register() { try { $this->authenticate('write'); self::string_validate_mandatory('email'); self::string_validate_mandatory('surname'); self::int_key_validate_mandatory('website_id'); self::boolean_validate('alert_on_entry'); self::boolean_validate('alert_on_verify'); self::int_key_validate('location_id'); if (!empty($_GET['user_id'])) { $userId = $_GET['user_id']; } else { // User was not logged in when subscribing, so use their details to find or create a warehouse user id. $emailIdentifierObject = new stdClass(); $emailIdentifierObject->type = "email"; $emailIdentifierObject->identifier = $_GET["email"]; $userIdentificationData['identifiers'] = json_encode(array($emailIdentifierObject)); //Also pass through these fields so if a new user is required then the system can fill in the database details $userIdentificationData['surname'] = $_GET["surname"]; $userIdentificationData['first_name'] = $_GET["first_name"]; //Call existing user identifier code that will either fetch an existing user for that email, or create a new one. $userDetails = user_identifier::get_user_id($userIdentificationData, $_GET["website_id"]); if (!empty($userDetails['userId'])) { $userId = $userDetails['userId']; } else { $userId = $userDetails['possibleMatches'][0]['user_id']; } } //Store the species alert for the user (which is either a new or existing user as determined by get_user_id) self::store_species_alert($userId); //Automatically register the user to receive email notifications if they have never had any settings at all try { $readAuth = data_entry_helper::get_read_auth(0 - $userId, kohana::config('indicia.private_key')); $freqSettingsData = data_entry_helper::get_report_data(array('dataSource' => 'library/user_email_notification_settings/user_email_notification_settings_inc_deleted', 'readAuth' => $readAuth, 'extraParams' => array('user_id' => $userId))); if (empty($freqSettingsData)) { self::store_user_email_notification_setting($userId); } } catch (exception $e) { kohana::log('debug', "Unable to register user " . $userId . " for email notifications, perhaps that module is not installed?."); } } catch (Exception $e) { $this->handle_error($e); } }