getDefault() public static method

Returns the default public user.
public static getDefault ( ) : User
return User
Beispiel #1
0
 /**
  * Controller constructor.
  */
 public function __construct()
 {
     // Get a user instance for the current user
     $user = auth()->user();
     if (!$user) {
         $user = User::getDefault();
     }
     // Share variables with views
     view()->share('signedIn', auth()->check());
     view()->share('currentUser', $user);
     // Share variables with controllers
     $this->currentUser = $user;
     $this->signedIn = auth()->check();
 }
 public function test_public_page_creation()
 {
     $this->setSettings(['app-public' => 'true']);
     $publicRole = \BookStack\Role::getSystemRole('public');
     // Grant all permissions to public
     $publicRole->permissions()->detach();
     foreach (\BookStack\RolePermission::all() as $perm) {
         $publicRole->attachPermission($perm);
     }
     $this->app[\BookStack\Services\PermissionService::class]->buildJointPermissionForRole($publicRole);
     $chapter = \BookStack\Chapter::first();
     $this->visit($chapter->book->getUrl());
     $this->visit($chapter->getUrl())->click('New Page')->see('Create Page')->seePageIs($chapter->getUrl('/create-page'));
     $this->submitForm('Continue', ['name' => 'My guest page'])->seePageIs($chapter->book->getUrl('/page/my-guest-page/edit'));
     $user = \BookStack\User::getDefault();
     $this->seeInDatabase('pages', ['name' => 'My guest page', 'chapter_id' => $chapter->id, 'created_by' => $user->id, 'updated_by' => $user->id]);
 }
Beispiel #3
0
/**
 * Helper method to get the current User.
 * Defaults to public 'Guest' user if not logged in.
 * @return \BookStack\User
 */
function user()
{
    return auth()->user() ?: \BookStack\User::getDefault();
}