/**
  * Reset the given user's password.
  *
  * @param  \Illuminate\Contracts\Auth\CanResetPassword|User|ServiceUser $user
  * @param  string                                                       $password
  */
 protected function resetPassword($user, $password)
 {
     $user->password_text = bcrypt($password);
     $user->save();
     /** @noinspection PhpUndefinedMethodInspection */
     Auth::login($user);
 }
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array $data
  *
  * @return User
  */
 public function create(array $data)
 {
     return \DB::transaction(function () use($data) {
         $_user = User::create(['first_name_text' => $data['first_name_text'], 'last_name_text' => $data['last_name_text'], 'email_addr_text' => $data['email_addr_text'], 'nickname_text' => $data['nickname_text'], 'password_text' => bcrypt($data['password_text'])]);
         $_appKey = AppKey::create(array('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;
     });
 }
 /**
  * @param bool $createIfNull
  *
  * @return Filesystem
  */
 public function getStorage($createIfNull = true)
 {
     //  Use requested file system if one...
     if (null === ($_storage = $this->get('storage')) && $createIfNull) {
         $_instance = $this->getInstance();
         $_user = $_instance->user;
         if (empty($_user)) {
             try {
                 $_user = User::findOrFail($_instance->user_id);
             } catch (ModelNotFoundException $_ex) {
                 \Log::error('Attempt to create an instance for a non-existent user_id: ' . $_instance->user_id);
                 throw new \RuntimeException('Invalid user assigned to instance.');
             }
         }
         InstanceStorage::buildStorageMap($_user->storage_id_text);
         $_storage = $_instance->getStorageRootMount();
         $this->setStorage($_storage);
     }
     return $_storage;
 }
 /**
  * @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;
 }
 /**
  * @return array
  */
 protected function gatherDashboardStatistics()
 {
     $_stats = ['user' => User::count()];
     return $_stats;
     //  The new way
     //return $this->telemetry->make('dashboard')->getTelemetry();
 }
 /**
  * @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;
 }
 public function index()
 {
     $users_owners = new ServiceUser();
     $users_admins = new User();
     $_columns = ['id', 'first_name_text', 'last_name_text', 'nickname_text', 'email_addr_text', 'owner_id', 'active_ind'];
     $o_users = $users_owners->get($_columns);
     $a_users = $users_admins->get($_columns);
     $o_users_array = json_decode($o_users);
     $a_users_array = json_decode($a_users);
     array_walk($o_users_array, function (&$o_user_array) {
         $o_user_array->admin = true;
     });
     array_walk($a_users_array, function (&$a_user_array) {
         $a_user_array->admin = false;
     });
     $result = array_merge($o_users_array, $a_users_array);
     $result = array_map("unserialize", array_unique(array_map("serialize", $result)));
     sort($result);
     return $this->renderView('app.users', ['users' => $result]);
 }
 /**
  * @param int $userId
  *
  * @return User
  */
 protected static function _lookupUser($userId)
 {
     return User::findOrFail($userId);
 }
Example #9
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;
     }
 }
 /**
  * Create a new resource
  *
  * @param  \Illuminate\Http\Request $request
  *
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     return User::register($request);
 }