/** * Creates a new account record, assigns * * @param $command */ public function handle($command) { // Create account $account = Account::create([]); $this->accountRepository->save($account); $language = $this->languageRepository->getByCode($command->defaultLanguageCode); $account->addLanguage($language); $account->addTranslation($language->code, 'name', $command->name); $account->addDomain($command->domain); $this->dispatcher->dispatch($account->releaseEvents()); }
/** * Handle switching account * * @param \Tectonic\Application\Commanding\Command $command * * @return string * @throws \Tectonic\Shift\Modules\Authentication\Exceptions\UserAccountAssociationException */ public function handle($command) { // 1. Make sure user is associated with account. if (!$this->accountUserExists($command->user->id)) { throw new UserAccountAssociationException(); } // 2. Create a DB record with unique token, account id and user id (if an existing record doesn't exist) $token = $this->createAccountSwitchRecord($command); $this->accountRepository->save($token); // 3. Release events $this->eventDispatcher->dispatch($token->releaseEvents()); // 4. Generate the URL for the account we're switching to (inclusive of token) $domainRecord = $this->domainRepository->getOneBy('account_id', $command->accountId); return $this->generateReturnUrl($domainRecord->domain, $token->token); }
/** * Handle the command. * * @param $command */ public function handle($command) { // Create account $account = Account::install(); // Add new user record and assign to account $user = User::install($command->email, $command->password); $this->users->save($user); $account->setOwner($user); $this->accountRepository->save($account); // Set the current account for the request. This is necessary for some other tasks CurrentAccount::set($account); $language = $this->addLanguage($account, $command->language); $account->addUser($user); $account->addTranslation($language->code, 'name', $command->name); $account->addDomain($command->host); // Dispatch all events associated with various objects $this->dispatcher->dispatch($account->releaseEvents()); $this->dispatcher->dispatch($user->releaseEvents()); }
protected function seedAccount() { $account = Account::install(); $this->accounts->save($account); $this->translationService->sync($account, ['name' => ['en_GB' => 'Tectonic']]); }
/** * Transfers an account's ownership to another user. * * @param Account $account * @param UserInterface $user * @returns Account */ public function transferOwnership(Account $account, User $user) { $account->setOwner($user); $this->accountRepository->save($account); $this->dispatcher->dispatch($account->releaseEvents()); }