/** * Increment the user's Mission Control subscription by the given number of seconds if they are a * Mission Control subscriber. * * This method has safeguards to prevent users with higher roles (charter subscribers, admins) from * being awarded extra time on a nonexistent subscription. * * @param User $user The user to award * @param Award $award The award for which we can calculate the subscription length */ public function incrementSubscription(User $user, Award $award) { if ($user->role_id == UserRole::Subscriber) { // Calculate the seconds to extend by $seconds = (new DeltaVCalculator())->toSeconds($award->value); // Fetch the current subscription/trial end $endDate = is_null($user->getTrialEndDate()) ? $user->getSubscriptionEndDate() : $user->getTrialEndDate(); // Calculate the new end date $newEndDate = $endDate->addSeconds($seconds); // Extend trial to that date $user->subscription($this->currentPlan)->noProrate()->trialFor($newEndDate)->swap(); // Update the database $user->trial_ends_at = $user->subsription()->getTrialEndDate(); $user->save(); } }
/** * Execute the console command. * * @return mixed */ public function handle() { $user = new User(); $user->username = $this->argument('username'); $user->email = $this->argument('username') . '@spacexstats.com'; $user->password = $this->argument('password'); // Hashed as a mutator on the User model $user->key = str_random(32); $user->role_id = UserRole::fromString($this->argument('role')); if ($this->option('launchctl')) { $user->launch_controller_flag = true; } DB::transaction(function () use($user) { $user->save(); // Associate a profile $profile = new Profile(); $profile->user()->associate($user)->save(); }); }
/** * Create a new user instance after a valid registration, also send them a welcome email. * * @param array $data * @return User */ protected function create(array $data) { $user = new User(); $user->username = $data['username']; $user->email = $data['email']; $user->password = $data['password']; // Hashed as a mutator on the User model $user->key = str_random(32); $user->role_id = UserRole::Unauthenticated; DB::transaction(function () use($user) { $user->save(); // Associate a profile $profile = new Profile(); $profile->user()->associate($user)->save(); }); // Add a welcome email to the queue $this->mailer->welcome($user); return $user; }