public static function boot() { parent::boot(); // assign a guid for each model static::creating(function ($tournamentQuizmaster) { $tournamentQuizmaster->guid = Uuid::uuid4(); return true; }); // Make sure the user has the quizmaster role // Using a saved event since the user could be assigned // after the initial creation static::saved(function ($tournamentQuizmaster) { $user = $tournamentQuizmaster->user; // if no user is linked, try to find one if (is_null($user)) { $user = User::where('email', $tournamentQuizmaster->email)->first(); } if (!is_null($user)) { // label the user as a quizmaster if ($user->isNotA(Role::QUIZMASTER)) { $role = Role::where('name', Role::QUIZMASTER)->firstOrFail(); $user->assign($role); } // associate the user with the quizmaster if ($tournamentQuizmaster->user_id == null) { $tournamentQuizmaster->update(['user_id' => $user->id]); } } }); }
public function setupAsHeadCoach() { $this->headCoach = User::where('email', DatabaseSeeder::HEAD_COACH_EMAIL)->first(); $this->group = Group::where('name', DatabaseSeeder::GROUP_NAME)->first(); $this->season = Season::orderBy('id', 'DESC')->first(); $this->actingAs($this->headCoach)->withSession([SessionManager::GROUP => $this->group->toArray(), SessionManager::SEASON => $this->season->toArray()]); }
/** * @test */ public function canRemoveUsers() { $guardian = User::where('email', DatabaseSeeder::GUARDIAN_EMAIL)->first(); $this->setupAsHeadCoach(); $this->group()->addHeadCoach($guardian); $this->visit('/group/' . $this->group()->id . '/settings/users')->see($guardian->full_name)->click('Remove')->see('User has been removed'); $this->assertEquals(1, $this->group()->users()->count()); }
/** * Execute the console command. * * @return mixed */ public function fire() { $orphanedFor = Carbon::now()->subDays($this->cleanupAfter); $orphanUsers = User::where('status', User::STATUS_UNCONFIRMED)->where('created_at', '>', $orphanedFor)->get(); foreach ($orphanUsers as $user) { $user->notify(new AccountDeleted()); $user->delete(); } }
/** @test */ public function onlyDeletesUnconfirmedAccounts() { $userCount = User::count(); $shouldBeDeletedCount = User::where('status', User::STATUS_UNCONFIRMED)->count(); $this->assertGreaterThan(0, $shouldBeDeletedCount); $this->artisan(\BibleBowl\Users\CleanupOrphanAccounts::COMMAND); $this->assertEquals(0, User::where('status', User::STATUS_UNCONFIRMED)->count()); $this->assertEquals($userCount - $shouldBeDeletedCount, User::count()); }
/** * @test */ public function canTransferOwnership() { $guardian = User::where('email', DatabaseSeeder::GUARDIAN_EMAIL)->firstOrFail(); $this->assertTrue($guardian->isNotAn(Role::HEAD_COACH)); $this->assertTrue($this->group->owner->isAn(Role::HEAD_COACH)); $this->visit('/admin/groups/' . $this->group->id)->click('Transfer Ownership')->see('Transfer Ownership: ' . $this->group->name)->select($guardian->id, 'user_id')->press('Transfer')->see('Ownership has been transferred'); Bouncer::refresh(); $this->assertTrue($guardian->isAn(Role::HEAD_COACH)); $this->assertTrue(Group::findOrFail($this->group->id)->isOwner($guardian)); }
public function register(Tournament $tournament, array $attributes = null, User $user = null, Group $group = null) : Spectator { $adult = app(Spectator::class, [['tournament_id' => $tournament->id, 'group_id' => $group == null ? null : $group->id, 'shirt_size' => $attributes['shirt_size']]]); if ($user != null) { $adult->user_id = $user->id; } else { // attempt to look up the user by email address if (isset($attributes['email'])) { $user = User::where('email', $attributes['email'])->first(); if ($user != null && $user->exists()) { $adult->user_id = $user->id; } } if (isset($attributes['address_one'])) { $address = app(Address::class, [['address_one' => $attributes['address_one'], 'address_two' => $attributes['address_two'], 'zip_code' => $attributes['zip_code']]]); $address->save(); $adult->address_id = $address->id; } } // fields are set by head coaches when they register for adults if (isset($attributes['first_name'])) { $adult->first_name = $attributes['first_name']; } if (isset($attributes['last_name'])) { $adult->last_name = $attributes['last_name']; } if (isset($attributes['email'])) { $adult->email = $attributes['email']; } if (isset($attributes['gender'])) { $adult->gender = $attributes['gender']; } // spouse data if (isset($attributes['spouse_first_name']) && !empty($attributes['spouse_first_name'])) { $adult->spouse_first_name = $attributes['spouse_first_name']; $adult->spouse_gender = $attributes['spouse_gender']; $adult->spouse_shirt_size = $attributes['spouse_shirt_size']; } $adult->save(); // attach minors if (isset($attributes['minor'])) { $minors = []; foreach ($attributes['minor'] as $minor) { if (strlen($minor['first_name']) > 0) { $minors[] = app(Minor::class, [['name' => $minor['first_name'], 'age' => $minor['age'], 'shirt_size' => $minor['shirt_size'], 'gender' => $minor['gender']]]); } } if (count($minors) > 0) { $adult->minors()->saveMany($minors); } } return $adult; }
/** * @test */ public function associateWithExistingUserIfEmailAddressMatches() { $firstName = 'Jane'; $lastName = 'Lork'; //allow GUID to be set User::unguard(); User::create(['guid' => md5(uniqid() . microtime()), 'email' => $this->providerUser->getEmail(), 'first_name' => $firstName, 'last_name' => $lastName, 'primary_address_id' => Address::firstOrFail()->id]); User::reguard(); $this->call('GET', '/login/' . ThirdPartyAuthenticator::PROVIDER_GOOGLE, ['code' => uniqid()]); // logged in as pre-existing user $this->followRedirects()->see($firstName . ' ' . $lastName); //assert user was not created $name = explode(' ', $this->providerUser->getName()); $createdUser = User::where('first_name', $name[0])->where('last_name', $name[1])->where('email', $this->providerUser->getEmail())->where('avatar', $this->providerUser->getAvatar())->count() > 0; $this->assertFalse($createdUser); }
/** * @test */ public function canRegisterANewAccountWithSurvey() { $email = 'actest' . time() . '@testerson.com'; $this->visit('/register')->type($email, 'email')->type($this->password, 'password')->type($this->password, 'password_confirmation')->press('Register')->seePageIs('/login')->see('Please follow the link in the confirmation email we just sent you.'); // skip the email confirmation step User::where('email', $email)->update(['status' => User::STATUS_CONFIRMED]); $this->login($email, $this->password)->type('Johnson', 'first_name')->type('Johnson', 'last_name')->type('1234567890', 'phone')->type('123 Test Street', 'address_one')->type('Apt 1', 'address_two')->type('40241', 'zip_code'); $answerId = 4; $otherText = uniqid(); $this->check('answer[1][' . $answerId . ']')->check('answer[1][7]')->type($otherText, 'other[1]')->press('Save')->seePageIs('/dashboard'); $user = User::where('email', $email)->first(); $otherAnswer = RegistrationSurveyAnswer::where('question_id', 1)->where('answer', 'Other')->first(); $userSurvey = $user->surveys->get(2); $this->assertEquals($answerId, $user->surveys->first()->answer_id); $this->assertEquals($otherAnswer->id, $userSurvey->answer_id); $this->assertEquals($otherText, $userSurvey->other); }
public function register(Tournament $tournament, array $attributes = null, User $user = null, Group $group = null) : TournamentQuizmaster { $tournamentQuizmaster = app(TournamentQuizmaster::class, [['tournament_id' => $tournament->id, 'group_id' => $group == null ? null : $group->id]]); if ($user != null) { $tournamentQuizmaster->user_id = $user->id; } elseif (isset($attributes['email'])) { // attempt to look up the user by email address $user = User::where('email', $attributes['email'])->first(); if ($user != null && $user->exists()) { $tournamentQuizmaster->user_id = $user->id; } } // fields are set by head coaches when they register for quizmasters if (isset($attributes['first_name'])) { $tournamentQuizmaster->first_name = $attributes['first_name']; } if (isset($attributes['last_name'])) { $tournamentQuizmaster->last_name = $attributes['last_name']; } if (isset($attributes['email'])) { $tournamentQuizmaster->email = $attributes['email']; } if (isset($attributes['gender'])) { $tournamentQuizmaster->gender = $attributes['gender']; } $tournamentQuizmaster->shirt_size = $attributes['shirt_size']; /** @var QuizzingPreferences $quizzingPreferences */ $quizzingPreferences = $tournamentQuizmaster->quizzing_preferences; // if we have one, assume we have them all $hasQuizzingPreferences = isset($attributes['quizzed_at_tournament']); if ($hasQuizzingPreferences) { $quizzingPreferences->setQuizzedAtThisTournamentBefore($attributes['quizzed_at_tournament']); $quizzingPreferences->setTimesQuizzedAtThisTournament($attributes['times_quizzed_at_tournament']); $quizzingPreferences->setGamesQuizzedThisSeason($attributes['games_quizzed_this_season']); $quizzingPreferences->setQuizzingInterest($attributes['quizzing_interest']); } $tournamentQuizmaster->quizzing_preferences = $quizzingPreferences; $tournamentQuizmaster->save(); // if we didn't get preferences, email them for them if ($hasQuizzingPreferences == false) { Mail::queue('emails.quizmaster-request-quizzing-preferences', ['tournament' => $tournament, 'group' => $group, 'tournamentQuizmaster' => $tournamentQuizmaster], function (Message $message) use($tournament, $tournamentQuizmaster) { $message->to($tournamentQuizmaster->email, $tournamentQuizmaster->full_name)->subject($tournament->name . ' Quizzing Preferences'); }); } return $tournamentQuizmaster; }
public function sendUserInvite(UserInviteRequest $request) { $group = Group::findOrFail($request->route('group')); $user = User::where('email', $request->get('email'))->first(); DB::beginTransaction(); $recipientName = null; if (is_null($user)) { $recipientEmail = $request->get('email'); } else { $recipientEmail = $user->email; $recipientName = $user->full_name; } $invitation = Invitation::create(['type' => Invitation::TYPE_MANAGE_GROUP, 'email' => is_null($user) ? $request->get('email') : null, 'user_id' => is_null($user) ? null : $user->id, 'inviter_id' => Auth::user()->id, 'group_id' => $group->id]); Mail::queue('emails.group-user-invitation', ['invitation' => $invitation, 'header' => 'Group Management Invitation', 'invitationText' => '<strong>' . Auth::user()->full_name . '</strong> has invited you to help manage the ' . $group->program->abbreviation . ' <strong>' . $group->name . '</strong> group.'], function (Message $message) use($recipientEmail, $recipientName) { $message->to($recipientEmail, $recipientName)->subject('Bible Bowl Group Management Invitation'); }); DB::commit(); return redirect('/group/' . $group->id . '/settings/users')->withFlashSuccess('Invitation has been sent'); }
/** * Find the existing user or create a new one for this account. * * @param $provider * * @throws EmailAlreadyInUse * * @return User */ public function findOrCreateUser($provider) : User { /** @var \Laravel\Socialite\Two\User $providerUser */ $providerUser = $this->socialite->driver($provider)->user(); $user = User::byProvider($provider, $providerUser->id)->first(); if (is_null($user)) { $user = User::where('email', $providerUser->getEmail())->first(); // If provider isn't associated with user, do that now if (is_null($user)) { return $this->registrar->create($provider, $providerUser); } $userProvider = app(UserProvider::class, [['provider' => $provider, 'provider_id' => $providerUser->getId()]]); $user->providers()->save($userProvider); return $user; } // update the avatar if it has changed if (!is_null($providerUser->getAvatar()) && $user->avatar != $providerUser->getAvatar()) { $user->update(['avatar' => $providerUser->getAvatar()]); } return $user; }
private function seedTournament($director) { $tournamentName = 'My Test Tournament'; $tournament = Tournament::create(['program_id' => Program::TEEN, 'slug' => $this->season->name . ' ' . $tournamentName, 'season_id' => $this->season->id, 'name' => $tournamentName, 'start' => Carbon::now()->addMonths(5)->format('m/d/Y'), 'end' => Carbon::now()->addMonths(7)->format('m/d/Y'), 'registration_start' => Carbon::now()->subMonths(3)->format('m/d/Y'), 'registration_end' => Carbon::now()->addDays(4)->format('m/d/Y'), 'creator_id' => $director->id, 'details' => '<h3>Nearby Hotels</h3><p>There are a few nearby:</p><ul><li>Option #1</li></ul>', 'max_teams' => 64, 'lock_teams' => Carbon::now()->addMonths(3)->addWeeks(2)->format('m/d/Y'), 'earlybird_ends' => Carbon::now()->addMonths(3)->format('m/d/Y')]); $tournament->events()->create(['event_type_id' => EventType::ROUND_ROBIN, 'price_per_participant' => '25.00']); $tournament->events()->create(['event_type_id' => EventType::DOUBLE_ELIMINATION, 'price_per_participant' => '35.00']); $tournament->participantFees()->create(['participant_type_id' => ParticipantType::PLAYER, 'requires_registration' => 1, 'fee' => '15.00']); $tournament->participantFees()->create(['participant_type_id' => ParticipantType::TEAM, 'requires_registration' => 1, 'earlybird_fee' => '50.00', 'fee' => '75.00']); $tournament->participantFees()->create(['participant_type_id' => ParticipantType::QUIZMASTER, 'requires_registration' => 1, 'fee' => '30.00', 'onsite_fee' => '40.00']); $tournament->participantFees()->create(['participant_type_id' => ParticipantType::ADULT, 'requires_registration' => 1, 'fee' => '30.00', 'onsite_fee' => '40.00']); $tournament->participantFees()->create(['participant_type_id' => ParticipantType::FAMILY, 'requires_registration' => 1, 'fee' => '60.00', 'onsite_fee' => '75.00']); $groupId = 2; $tournament->tournamentQuizmasters()->create(['group_id' => $groupId, 'first_name' => 'Keith', 'last_name' => 'Webb', 'email' => '*****@*****.**', 'gender' => 'M']); $user = User::where('email', self::QUIZMASTER_EMAIL)->first(); $receipt = $this->seedReceipt($user); $tournament->tournamentQuizmasters()->create(['group_id' => $groupId, 'receipt_id' => $receipt->id, 'first_name' => 'Warner', 'last_name' => 'Jackson', 'email' => '*****@*****.**', 'gender' => 'F']); // guest spectators $director = User::where('email', self::DIRECTOR_EMAIL)->first(); $tournament->spectators()->create(['group_id' => $groupId, 'receipt_id' => $receipt->id, 'first_name' => 'Sarah', 'last_name' => 'Jones', 'shirt_size' => 'L', 'email' => '*****@*****.**', 'gender' => 'F', 'address_id' => $director->primary_address_id]); $tournament->spectators()->create(['group_id' => $groupId, 'first_name' => 'Jonathan', 'last_name' => 'Wicker', 'shirt_size' => 'L', 'email' => '*****@*****.**', 'gender' => 'M', 'address_id' => $director->primary_address_id]); // family spectators $tournament->spectators()->create(['group_id' => $groupId, 'user_id' => $director->id, 'receipt_id' => $receipt->id, 'spouse_first_name' => 'Michelle', 'spouse_gender' => 'F', 'spouse_shirt_size' => 'M']); $spectator = $tournament->spectators()->create(['group_id' => $groupId, 'first_name' => 'Clark', 'last_name' => 'Larkson', 'shirt_size' => 'XL', 'email' => '*****@*****.**', 'gender' => 'M', 'spouse_first_name' => 'Lucy', 'spouse_gender' => 'F', 'spouse_shirt_size' => 'M']); $spectator->minors()->create(['name' => 'Jonathan', 'age' => '6', 'shirt_size' => 'YS', 'gender' => 'M']); $spectator->minors()->create(['name' => 'Christine', 'age' => '12', 'shirt_size' => 'YM', 'gender' => 'F']); }
| Here you may define all of your model factories. Model factories give | you a convenient way to create models for testing and seeding your | database. Just tell the factory how a default model should look. | */ $factory->define(User::class, function (Generator $faker) { return ['status' => User::STATUS_CONFIRMED, 'first_name' => $faker->firstName, 'last_name' => $faker->lastName, 'email' => $faker->email, 'phone' => $faker->phoneNumber, 'password' => str_random(10), 'remember_token' => str_random(10)]; }); $factory->define(Player::class, function (Generator $faker) { return ['first_name' => $faker->firstName, 'last_name' => $faker->lastName, 'gender' => rand(0, 1) ? 'M' : 'F', 'birthday' => $faker->dateTimeBetween('-18 years', '-9 years')->format('m/d/Y')]; }); $factory->define(Address::class, function (Generator $faker) { return ['name' => 'Home', 'address_one' => $faker->buildingNumber . ' ' . $faker->streetName . ' ' . $faker->streetSuffix, 'address_two' => rand(0, 5) ? $faker->secondaryAddress : null, 'latitude' => $faker->latitude, 'longitude' => $faker->longitude, 'city' => $faker->city, 'state' => $faker->stateAbbr, 'zip_code' => $faker->postcode]; }); $factory->define(Tournament::class, function (Generator $faker) { return ['name' => $faker->word, 'program_id' => Program::TEEN, 'season_id' => Season::current()->id, 'start' => Carbon::now()->addMonth(1), 'end' => Carbon::now()->addDays(14), 'registration_start' => Carbon::now()->subMonth(1), 'registration_end' => Carbon::now()->subDays(14), 'creator_id' => User::where('email', DatabaseSeeder::DIRECTOR_EMAIL)->first()->id]; }); /** * @return User */ function seedGuardian($attrs = [], $addressAttrs = []) { $address = factory(Address::class)->create($addressAttrs); $attrs['primary_address_id'] = $address->id; $user = factory(User::class)->create($attrs); $address->user_id = $user->id; $address->save(); $role = Role::where('name', Role::GUARDIAN)->firstOrFail(); $user->assign($role); return $user; }
public function setupAsQuizmaster() { $this->quizmaster = User::where('email', DatabaseSeeder::QUIZMASTER_EMAIL)->first(); $this->actingAs($this->quizmaster); }
public function setupAsGuardian() { $this->guardian = User::where('email', DatabaseSeeder::GUARDIAN_EMAIL)->first(); $this->season = Season::orderBy('id', 'DESC')->first(); $this->actingAs($this->guardian)->withSession([SessionManager::SEASON => $this->season->toArray()]); }
public function index() { $users = User::where('first_name', 'LIKE', '%' . Input::get('q') . '%')->orWhere('last_name', 'LIKE', '%' . Input::get('q') . '%')->orWhere('email', 'LIKE', '%' . Input::get('q') . '%')->with('primaryAddress')->orderBy('last_name', 'ASC')->orderBy('first_name', 'ASC')->paginate(25); return view('/admin/users/index', ['users' => $users->appends(Input::only('q'))]); }
public function setupAsDirector() { $this->director = User::where('email', DatabaseSeeder::DIRECTOR_EMAIL)->first(); $this->season = Season::orderBy('id', 'DESC')->first(); $this->actingAs($this->director)->withSession([SessionManager::SEASON => $this->season->toArray()]); }
/** * Landing page for a user confirming their email addres. * * @param string $guid * * @return mixed */ public function getConfirm($guid) { User::where('guid', $guid)->update(['status' => User::STATUS_CONFIRMED]); return redirect()->back()->withFlashSuccess('Your email address has been confirmed, you may now login'); }