コード例 #1
1
ファイル: AccountMiddleware.php プロジェクト: kamaroly/shift
 /**
  * Handle an incoming request.
  *
  * The following filter simply retrieves the current account based on the request information
  * and then sets this value for future retrieval. If no account can be found for the request,
  * then two things need to happen:
  *
  * 1. Check to see if ANY accounts have been configured if no accounts exist then
  * 2. Ask the user if they'd like to setup the default (first) account. This is required
  *    for new installations.
  * 3. If an account does exist but does not match the domain, then we throw an account
  *    not found exception and deal with that later.
  *
  * @throws AccountNotFoundException
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $account = CurrentAccount::determine($request->getHttpHost());
     if (!$account) {
         $count = $this->accountService->totalNumberOfAccounts();
         if ($count === 0) {
             return redirect()->route('install');
         }
         throw new AccountNotFoundException();
     }
     CurrentAccount::set($account);
     return $next($request);
 }
コード例 #2
0
 /**
  * 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';
     }
 }
コード例 #3
0
 public function testCurrentAccountIsSet()
 {
     $view = m::mock(ViewStub::class)->makePartial();
     $composer = new ApplicationComposer();
     $composer->compose($view);
     $view->shouldHaveReceived('with')->once()->withArgs(['account', CurrentAccount::translated()]);
 }
コード例 #4
0
ファイル: ConsumerManager.php プロジェクト: kamaroly/shift
 /**
  * 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();
 }
コード例 #5
0
 public function testGuestLanguage()
 {
     $mockAccount = m::mock('account');
     $mockAccount->shouldReceive('defaultLanguage')->andReturn('code');
     CurrentAccount::shouldReceive('get')->andReturn($mockAccount);
     $this->assertEquals('code', $this->consumerManager->language());
 }
コード例 #6
0
ファイル: UserAccountFilter.php プロジェクト: kamaroly/shift
 /**
  * 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;
 }
コード例 #7
0
 public function testCreationOfValidationRules()
 {
     $languages = m::mock('languagerepository');
     $languages->languages = $languages;
     $languages->shouldReceive('lists')->once()->andReturn(['en_GB', 'en_US']);
     CurrentAccount::shouldReceive('get')->once()->andReturn($languages);
     $validations = (new TranslatableValidationsStub())->required('name');
     $this->assertcount(2, $validations);
     $this->assertArrayHasKey('translated.name.en_GB', $validations);
     $this->assertArrayHasKey('translated.name.en_US', $validations);
 }
コード例 #8
0
 public function init()
 {
     $english = new stdClass();
     $english->code = 'en_GB';
     $japanese = new stdClass();
     $japanese->code = 'ja_JP';
     $account = new stdClass();
     $account->languages = [$english, $japanese];
     CurrentAccount::shouldReceive('get')->andReturn($account);
     $this->formBuilder = new MultiLingualFormBuilder();
 }
コード例 #9
0
 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();
 }
コード例 #10
0
 /**
  * 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();
 }
コード例 #11
0
 /**
  * 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();
 }
コード例 #12
0
 public function compose($view)
 {
     $view->with('account', CurrentAccount::translated());
 }
コード例 #13
0
 /**
  * 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);
 }
コード例 #14
0
ファイル: UserConsumer.php プロジェクト: kamaroly/shift
 /**
  * Returns the language that the consumer prefers.
  *
  * @return Language
  */
 public function language()
 {
     // @TODO: Add support of user-preferred language
     return CurrentAccount::get()->defaultLanguage();
 }