public function pageBasedActions() { if (!is_admin()) { global $current_user; if (class_exists("MM_User")) { $user = new MM_User($current_user->ID); } // log access for logged in users if (MM_Utils::isLoggedIn()) { global $post; if (isset($post)) { $crntPostId = $post->ID; $params = array(); $params[MM_ActivityLog::$PARAM_PAGE_ID] = $crntPostId; MM_ActivityLog::log($user, MM_ActivityLog::$EVENT_TYPE_PAGE_ACCESS, $params); } } // clear session params MM_Session::clear(MM_Session::$KEY_LAST_USER_ID); MM_Session::clear(MM_Session::$KEY_LAST_ORDER_ID); } }
private static function getExpirationDate() { if (self::$MM_SESSION_TIMESTAMP === null) { self::sessionSetTimestamp(); } if (MM_Utils::isLoggedIn() || !self::probablyIsBot()) { return strftime("%Y-%m-%d %H:%M:%S", strtotime(self::$MM_SESSION_TIMESTAMP) + self::$MM_SESSION_LIFESPAN); } else { return strftime("%Y-%m-%d %H:%M:%S", strtotime(self::$MM_SESSION_TIMESTAMP) + self::$MM_SESSION_UNVERIFIED_LIFESPAN); } }
function processSignup($request, $provider) { //don't attempt to signup already logged in users if (MM_Utils::isLoggedIn()) { $loggedInUser = MM_Utils::getCurrentUser(); $redirectUrl = isset($request['redirect_url']) ? $request['redirect_url'] : MM_CorePageEngine::getUrl(MM_CorePageType::$MEMBER_HOME_PAGE, null, $loggedInUser); wp_redirect($redirectUrl); exit; } if (!$provider->allowsSignups()) { //configuration does not allow signups throw new Exception("Signups not allowed", "1001007"); } if (isset($request['membership_level'])) { $membershipLevel = trim($request['membership_level']); $membershipLevel = htmlentities($membershipLevel); if (!is_numeric($membershipLevel)) { //membership level was not passed as a valid id throw new Exception("Invalid Membership Level", "1001008"); } } else { $membershipLevel = $provider->getSignupMembershipLevel(); if (!is_numeric($membershipLevel) || $membershipLevel == 0) { //should never happen - default signup membership level is invalid throw new Exception("Invalid Default Membership Level", "1001009"); } } //ensure that if the chosen provider doesnt allow access to the email, and the provider is configured not to generate one, that one was supplied if ($provider->getEmailHandlingStrategy() == MM_AbstractSocialLoginExtension::$EMAIL_RETRIEVED_BY_POPUP && empty($request['email'])) { //email required but not supplied throw new Exception("No email supplied", "1001010"); } //Authenticate with the provider, and retrieve the remote user profile $authResponse = $provider->authenticate(); if (!MM_Response::isSuccess($authResponse)) { //error authenticating throw new Exception("Error authenticating with social network", "1001016"); } $profileResponse = $provider->getUserProfile(); if (!MM_Response::isSuccess($profileResponse)) { //retrievng profile failed throw new Exception("Unable to retrieve profile from social network", "1001011"); } $profile = $profileResponse->message; if (!isset($profile->identifier) || empty($profile->identifier)) { //invalid social network identifier returned throw new Exception("Invalid social network identifier", "1001012"); } //Populate memberinfo with the necessary member information, in the expected format $memberInfo = array(); $memberInfo["membership_level"] = $membershipLevel; if (isset($profile->firstName) && !empty($profile->firstName)) { $memberInfo['first_name'] = $profile->firstName; } if (isset($profile->lastName) && !empty($profile->lastName)) { $memberInfo['last_name'] = $profile->lastName; } $emailHandlingStrategy = $provider->getEmailHandlingStrategy(); if ($emailHandlingStrategy == MM_AbstractSocialLoginExtension::$EMAIL_RETRIEVED_BY_POPUP) { //TODO: sanitize email $memberInfo['email'] = $request['email']; } else { if ($emailHandlingStrategy == MM_AbstractSocialLoginExtension::$EMAIL_PROVIDED) { if (isset($profile->emailVerified) && !empty($profile->emailVerified)) { $memberInfo['email'] = $profile->emailVerified; } else { if (isset($profile->email) && !empty($profile->email)) { $memberInfo['email'] = $profile->email; } else { throw new Exception("Social Network provider was supposed to supply user email, but did not", "1001013"); } } } else { if ($emailHandlingStrategy == MM_AbstractSocialLoginExtension::$EMAIL_GENERATE_BOGUS_EMAIL) { $bogusUser = MM_Utils::createRandomString(8, true) . MM_Utils::createRandomString(24); //TODO: tag user portion of email with social network identifier $bogusDomain = "example.com"; $memberInfo['email'] = "{$bogusUser}@{$bogusDomain}"; } } } $socialSignupRequest = new MM_SocialLoginRequest($memberInfo); $response = $socialSignupRequest->submitRequest(); if (MM_Response::isSuccess($response)) { $newUser = $socialSignupRequest->getNewUser(); $provider->linkUserToSocialMediaAccount($newUser, $profile->identifier); $socialSignupRequest->completeSignup(); exit; } else { if (strpos($response->message, "already exists") !== false) { //the member signing up already exists, send them to login instead processLogin($request, $provider); exit; } throw new Exception($response->message, "1001014"); } //end signup block exit; }