/** * Returns the language object that the consumer has preferred, otherwise, * the default language. This can be used even if the consumer is not currently * logged-in yet. * * @return Language */ public function language() { if ($this->guest()) { return CurrentAccount::get()->defaultLanguage(); } return $this->consumer->language(); }
/** * Custom method to define required validations for translatable fields. * * @param string $fieldName */ protected function requiredTranslation($fieldName) { $languages = CurrentAccount::get()->languages->lists('code'); foreach ($languages as $code) { $this->rules["translated.{$fieldName}.{$code}"] = 'required'; } }
/** * Apply the given search filter to an Eloquent query. * * @param $query * @return Query */ public function applyToEloquent($query) { if (!array_get($this->input, 'relax')) { $accountId = CurrentAccount::get()->id; $query->join('account_user', 'account_user.user_id', '=', 'users.id'); $query->where('account_user.account_id', '=', $accountId); } return $query; }
public function testOnSuccessfulLogin() { // Arrange $observer = m::spy(AuthenticationResponderInterface::class); // Create a new user. $user = $this->createTempUser(); // Associate user with this account. $currentAccount = CurrentAccount::get(); DB::table('account_user')->insert(['account_id' => $currentAccount->id, 'user_id' => $user->id]); // Act (User not associated with current account, so it should cause a UserAccountAssociation exception) $this->service->login(['email' => '*****@*****.**', 'password' => 'password', 'remember' => false], $observer); // Assert. $this->assertSame(1, (int) $user->id); $observer->shouldHaveReceived('onSuccess')->once(); }
/** * Handle the command. * * @param $command * * @throws \Tectonic\Shift\Modules\Authentication\Exceptions\InvalidAuthenticationCredentialsException * @throws \Tectonic\Shift\Modules\Authentication\Exceptions\UserAccountAssociationException * @return \Illuminate\Auth\UserInterface|null */ public function handle($command) { // First check to see if the users credentials are valid. $userCredentialsAreValid = $this->authenticate->validate(['email' => $command->email, 'password' => $command->password]); // If user credential are invalid, throw exception. if (!$userCredentialsAreValid) { throw new InvalidAuthenticationCredentialsException(); } // Find out if user has an account id with the current account $accountUser = $this->userRepository->getByEmailAndAccount($command->email, CurrentAccount::get()); // If an account user is found, login and return user if ($accountUser) { $this->authenticate->login($accountUser, $command->remember); $user = $this->authenticate->getUser(); // Raise an event, and dispatch $this->raise(new UserHasAuthenticated($user)); $this->eventDispatcher->dispatch($this->releaseEvents()); return $user; } // Login failed, throw exception throw new UserAccountAssociationException(); }
/** * Returns a collection of translations based on the locale, the resource (such as ui) and the group. * The group represents a like query. Say for example you want all translations for roles, then the group * would be "roles", but the query created would be: WHERE field LIKE "roles.%" * * @param $locale * @param $resource * @param $group * @return mixed */ public function getByGroup($locale, $resource, $group) { return $this->getQuery()->whereAccountId(CurrentAccount::get()->id)->whereLanguage($locale)->whereResource($resource)->where('field', 'LIKE', "{$group}.%")->get(); }
/** * Create a new AccountSwitch record * * @param \Tectonic\Application\Commanding\Command $command * * @return mixed */ protected function createAccountSwitchRecord(Command $command) { $generator = new AccountSwitcherTokenGenerator(); $generator->setData($command->accountId, CurrentAccount::get(), $command->user->id); return Token::createToken($generator); }
/** * Returns the language that the consumer prefers. * * @return Language */ public function language() { // @TODO: Add support of user-preferred language return CurrentAccount::get()->defaultLanguage(); }