/** * Transform the User entity * * @param User $model * * @return array */ public function transform(User $model) { $primary_address = $model->flaggedAddress('primary'); $birth_date = $model->birth_date_carbon; if (!is_null($birth_date)) { $birth_date = $birth_date->format(trans('global.date_format')); } // NOTE :: key order is important ! $data = ['id' => (int) $model->id, 'civility' => trans('global.' . $model->civility), 'last_name' => $model->last_name, 'first_name' => $model->first_name, 'email' => $model->email, 'birth_date' => $birth_date]; /* * Roles list */ $roles = []; foreach ($model->roles as $role) { $roles[] = trans($role->display_name); } sort($roles); $data['roles'] = implode(',' . PHP_EOL, $roles); /* * Environments list */ $environments = []; if (cms_is_superadmin()) { foreach ($model->environments as $environment) { $environments[] = trans($environment->name); } sort($environments); $data['environments'] = implode(',' . PHP_EOL, $environments); } /* * Primary address */ if (!is_null($primary_address)) { switch ($primary_address->locator_type) { case 'CVEPDB\\Addresses\\Domain\\Addresses\\Countries\\Country': $data['addresses'] = $primary_address->street . (!is_null($primary_address->street_extra) ? ' ' . $primary_address->street_extra : '') . ' ' . $primary_address->city . ' ' . $primary_address->zip . ' ' . (!is_null($primary_address->locator) ? $primary_address->locator->name : ''); break; case 'CVEPDB\\Addresses\\Domain\\Addresses\\States\\State': $data['addresses'] = $primary_address->street . ' ' . $primary_address->street_extra . ' ' . $primary_address->city . ' ' . $primary_address->zip . ' ' . (!is_null($primary_address->locator) ? $primary_address->locator->name : '') . ' ' . (!is_null($primary_address->locator) ? $primary_address->locator->country->name : ''); break; case 'CVEPDB\\Addresses\\Domain\\Addresses\\SubStates\\SubState': $data['addresses'] = $primary_address->street . ' ' . $primary_address->street_extra . ' ' . $primary_address->city . ' ' . $primary_address->zip . ' ' . (!is_null($primary_address->locator) ? $primary_address->locator->state->name : '') . ' ' . (!is_null($primary_address->locator) ? $primary_address->locator->name : '') . ' ' . (!is_null($primary_address->locator) ? $primary_address->locator->state->country->name : ''); break; } } return $data; }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); $faker = Faker::create(); /* * Users */ $env = Environment::where(['reference' => EnvironmentsRepositoryEloquent::DEFAULT_ENVIRONMENT_REFERENCE])->firstOrFail(); foreach (range(1, 1000) as $index) { $user = User::create(['last_name' => $faker->lastName, 'first_name' => $faker->firstName, 'email' => $faker->email, 'password' => bcrypt('secret'), 'role' => User::ROLE_USER]); $user->environments()->detach(); $user->environments()->attach($env->id); } Model::reguard(); }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); $faker = Faker::create(); /* * Admin */ $user = User::create(['last_name' => 'Antoine', 'first_name' => 'Benevaut', 'email' => '*****@*****.**', 'password' => bcrypt('secret'), 'role' => User::ROLE_ADMIN]); $user->environments()->detach(); $envs = Environment::all(); foreach ($envs as $env) { $user->environments()->attach($env->id); } Model::reguard(); }
/** * @param $user * @param $password * @param StatefulGuard $guard */ public function resetUserPassword($user, $password, StatefulGuard $guard) { $user->password = bcrypt($password); $user->save(); /* * $user is instance of \cms\Domain\Users\Users\User * Here we need instance of \Modules\Users\Entities\User */ $event_user = User::findOrFail($user->id); event(new UserUpdatedEvent($event_user)); /* * Log user in */ Auth::guard($guard)->login($user); }
/** * @param User $user * * @return array */ public function transform(User $user) { $primary_address = $user->flaggedAddress('primary'); $data = ['id' => (int) $user->id, 'full_name' => $user->full_name, 'email' => $user->email, 'deleted_at' => $user->deleted_at]; return $data; }