X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/d336ba687460d2bca898e86c12a26224fc36f071..refs/pull/2023/head:/app/Auth/User.php diff --git a/app/Auth/User.php b/app/Auth/User.php index 69f424cac..a581d9993 100644 --- a/app/Auth/User.php +++ b/app/Auth/User.php @@ -47,7 +47,10 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon * The attributes excluded from the model's JSON form. * @var array */ - protected $hidden = ['password', 'remember_token']; + protected $hidden = [ + 'password', 'remember_token', 'system_name', 'email_confirmed', 'external_auth_id', 'email', + 'created_at', 'updated_at', + ]; /** * This holds the user's permissions when loaded. @@ -116,6 +119,17 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon return $this->roles->pluck('system_name')->contains($role); } + /** + * Attach the default system role to this user. + */ + public function attachDefaultRole(): void + { + $roleId = setting('registration-role'); + if ($roleId && $this->roles()->where('id', '=', $roleId)->count() === 0) { + $this->roles()->attach($roleId); + } + } + /** * Get all permissions belonging to a the current user. * @param bool $cache @@ -153,16 +167,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon */ public function attachRole(Role $role) { - $this->attachRoleId($role->id); - } - - /** - * Attach a role id to this user. - * @param $id - */ - public function attachRoleId($id) - { - $this->roles()->attach($id); + $this->roles()->attach($role->id); } /**