X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/1b8a1644123e00ae9b8785886c63f20e1ee134da..refs/pull/1756/head:/app/Auth/User.php diff --git a/app/Auth/User.php b/app/Auth/User.php index e5a8a3931..bce418a74 100644 --- a/app/Auth/User.php +++ b/app/Auth/User.php @@ -3,6 +3,7 @@ use BookStack\Model; use BookStack\Notifications\ResetPassword; use BookStack\Uploads\Image; +use Carbon\Carbon; use Illuminate\Auth\Authenticatable; use Illuminate\Auth\Passwords\CanResetPassword; use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; @@ -10,6 +11,20 @@ use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Notifications\Notifiable; +/** + * Class User + * @package BookStack\Auth + * @property string $id + * @property string $name + * @property string $email + * @property string $password + * @property Carbon $created_at + * @property Carbon $updated_at + * @property bool $email_confirmed + * @property int $image_id + * @property string $external_auth_id + * @property string $system_name + */ class User extends Model implements AuthenticatableContract, CanResetPasswordContract { use Authenticatable, CanResetPassword, Notifiable; @@ -38,13 +53,24 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon */ protected $permissions; + /** + * This holds the default user when loaded. + * @var null|User + */ + protected static $defaultUser = null; + /** * Returns the default public user. * @return User */ public static function getDefault() { - return static::where('system_name', '=', 'public')->first(); + if (!is_null(static::$defaultUser)) { + return static::$defaultUser; + } + + static::$defaultUser = static::where('system_name', '=', 'public')->first(); + return static::$defaultUser; } /**