/**
  * @param int $id
  * @param int $type
  *
  * @return \DreamFactory\Enterprise\Database\Models\Cluster|\DreamFactory\Enterprise\Database\Models\Instance|\DreamFactory\Enterprise\Database\Models\Server|\DreamFactory\Enterprise\Database\Models\User
  */
 protected static function findOwner($id, $type = OwnerTypes::USER)
 {
     try {
         $_owner = OwnerTypes::getOwner($id, $type);
     } catch (\Exception $_ex) {
         is_string($id) && ($_owner = User::byEmail($id)->first());
     } finally {
         if (empty($_owner)) {
             throw new ModelNotFoundException('The owner-id "' . $id . '" could not be found.');
         }
     }
     return $_owner;
 }
Пример #2
0
 /**
  * @param string      $subGuid
  * @param string|null $partnerEmail Partner registrant email address
  *
  * @return bool|\Illuminate\Http\RedirectResponse
  */
 protected function locateContactBySubmissionGuid($subGuid, $partnerEmail)
 {
     if ('false' !== $subGuid && empty($partnerEmail)) {
         $_url = 'https://api.hubapi.com/contacts/v1/lists/recently_updated/contacts/recent/?hapikey=' . config('marketing.hubspot.api-key') . '&count=50';
         if (false === ($_response = Curl::get($_url))) {
             \Log::debug('[auth.landing-page] recent contact pull failed.');
             return false;
         }
         if (empty($_response) || !$_response instanceof \stdClass || !isset($_response->contacts) || empty($_response->contacts)) {
             //  Methinks thine guid is bogus
             \Log::debug('[auth.landing-page] recent contacts empty or invalid.');
             \Log::debug('[auth.landing-page] * response: ' . print_r($_response, true));
             return false;
         }
         //  Mine for gold...
         $_email = null;
         /**
          * GHA 2015-06-16
          * This has to be the most ridiculous way to get a contact's email address that I've ever seen.
          */
         foreach ($_response->contacts as $_contact) {
             if (isset($_contact->{'form-submissions'})) {
                 foreach ($_contact->{'form-submissions'} as $_sub) {
                     if (isset($_sub->{'conversion-id'}) && $subGuid == $_sub->{'conversion-id'}) {
                         if (isset($_contact->{'identity-profiles'})) {
                             foreach ($_contact->{'identity-profiles'} as $_profile) {
                                 if (isset($_profile->identities)) {
                                     foreach ($_profile->identities as $_identity) {
                                         if (isset($_identity->type) && 'EMAIL' == $_identity->type && isset($_identity->value)) {
                                             $_email = $_identity->value;
                                             break 4;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         //  Didn't find this person out of the last 50? how could he just have been redirected??
         if (empty($_email)) {
             \Log::debug('[auth.landing-page] subGuid "' . $subGuid . '" not found in recents');
             return false;
         }
         \Log::debug('[auth.landing-page] subGuid "' . $subGuid . '" attached with email "' . $_email . '"');
     } else {
         //  Make sure it came from our domain...
         if (null === ($_referrer = \Request::server('HTTP_REFERER')) || false === stripos($_referrer, 'verizon.dreamfactory.com')) {
             \Log::debug('[auth.landing-page] bad referrer "' . $_referrer . '" in auto-login request.');
             return false;
         }
         $_email = $partnerEmail;
         \Log::debug('[auth.landing-page] using partner supplied email "' . $_email . '"');
     }
     //  Lookup email address
     try {
         $_user = User::byEmail($_email)->firstOrFail();
         \Log::debug('[auth.landing-page] subGuid "' . $subGuid . '"/"' . $_email . '" user id#' . $_user->id);
     } catch (ModelNotFoundException $_ex) {
         \Log::debug('[auth.landing-page] subGuid "' . $subGuid . '"/"' . $_email . '" no related user.');
         return false;
     }
     //  Ok, now we have a user, we need to log his ass in...
     /** @noinspection PhpParamsInspection */
     \Auth::login($_user);
     \Log::info('[auth.landing-page] auto-login user "' . $_email . '"');
     \Redirect::to('/auth/login');
     return true;
 }
Пример #3
0
 /**
  * Standardized user creation method
  *
  * @param \Illuminate\Http\Request $request
  * @param bool                     $validate If false, no validation is done.
  *
  * @return \DreamFactory\Enterprise\Common\Packets\ErrorPacket|\DreamFactory\Enterprise\Common\Packets\SuccessPacket
  */
 public static function register(Request $request, $validate = true)
 {
     $_email = $request->input('email', $request->input('email_addr_text'));
     $_first = $request->input('firstname', $request->input('first_name_text'));
     $_last = $request->input('lastname', $request->input('last_name_text'));
     $_password = $request->input('password', $request->input('password_text'));
     $_nickname = $request->input('nickname', $request->input('nickname_text', $_first));
     $_company = $request->input('company', $request->input('company_name_text'));
     $_phone = $request->input('phone', $request->input('phone_text'));
     if ($validate) {
         if (empty($_email) || empty($_password) || empty($_first) || empty($_last)) {
             /** @noinspection PhpUndefinedMethodInspection */
             Log::error('missing required fields from partner post', ['payload' => $request->input()]);
             throw new \InvalidArgumentException('Missing required fields');
         }
         if (false === filter_var($_email, FILTER_VALIDATE_EMAIL)) {
             /** @noinspection PhpUndefinedMethodInspection */
             Log::error('invalid email address "' . $_email . '"', ['payload' => $request->input()]);
             throw new \InvalidArgumentException('Email address invalid');
         }
     }
     //  See if we know this cat...
     if (null !== ($_user = User::byEmail($_email)->first())) {
         //  Existing user found, don't add to database...
         $_values = $_user->toArray();
         unset($_values['password_text'], $_values['external_password_text']);
         /** @noinspection PhpUndefinedMethodInspection */
         Log::info('existing user attempting registration through api', ['user' => $_values]);
         return $_user;
     }
     //  Create a user account
     try {
         /** @type User $_user */
         /** @noinspection PhpUndefinedMethodInspection */
         $_user = DB::transaction(function () use($request, $_first, $_last, $_email, $_password, $_nickname, $_phone, $_company) {
             /** @noinspection PhpUndefinedMethodInspection */
             $_user = User::create(['first_name_text' => $_first, 'last_name_text' => $_last, 'email_addr_text' => $_email, 'nickname_text' => $_nickname, 'password_text' => Hash::make($_password), 'phone_text' => $_phone, 'company_name_text' => $_company]);
             if (null === ($_appKey = AppKey::mine($_user->id, OwnerTypes::USER))) {
                 $_appKey = AppKey::create(['key_class_text' => AppKeyClasses::USER, 'owner_id' => $_user->id, 'owner_type_nbr' => OwnerTypes::USER, 'server_secret' => config('dfe.security.console-api-key')]);
             }
             //  Update the user with the key info and activate
             $_user->api_token_text = $_appKey->client_id;
             $_user->active_ind = 1;
             $_user->save();
             return $_user;
         });
         $_values = $_user->toArray();
         unset($_values['password_text'], $_values['external_password_text']);
         /** @noinspection PhpUndefinedMethodInspection */
         Log::info('new user registered', ['user' => $_values]);
         return $validate ? SuccessPacket::create($_user, Response::HTTP_CREATED) : $_user;
     } catch (\Exception $_ex) {
         if (false !== ($_pos = stripos($_message = $_ex->getMessage(), ' (sql: '))) {
             $_message = substr($_message, 0, $_pos);
         }
         /** @noinspection PhpUndefinedMethodInspection */
         Log::error('database error creating user from ops-resource post: ' . $_message);
         return $validate ? ErrorPacket::create(null, Response::HTTP_INTERNAL_SERVER_ERROR, $_message) : null;
     }
 }