mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-28 17:02:04 +03:00
Started work on API token controls
- Added access-api permission. - Started user profile UI work. - Created database table and model for tokens. - Fixed incorrect templates down migration :(
This commit is contained in:
9
app/Api/ApiToken.php
Normal file
9
app/Api/ApiToken.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php namespace BookStack\Api;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ApiToken extends Model
|
||||
{
|
||||
protected $fillable = ['name', 'expires_at'];
|
||||
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
<?php namespace BookStack\Auth;
|
||||
|
||||
use BookStack\Api\ApiToken;
|
||||
use BookStack\Model;
|
||||
use BookStack\Notifications\ResetPassword;
|
||||
use BookStack\Uploads\Image;
|
||||
@ -9,6 +10,7 @@ use Illuminate\Auth\Passwords\CanResetPassword;
|
||||
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
|
||||
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
/**
|
||||
@ -218,19 +220,26 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the url for editing this user.
|
||||
* @return string
|
||||
* Get the API tokens assigned to this user.
|
||||
*/
|
||||
public function getEditUrl()
|
||||
public function apiTokens(): HasMany
|
||||
{
|
||||
return url('/settings/users/' . $this->id);
|
||||
return $this->hasMany(ApiToken::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the url for editing this user.
|
||||
*/
|
||||
public function getEditUrl(string $path = ''): string
|
||||
{
|
||||
$uri = '/settings/users/' . $this->id . '/' . trim($path, '/');
|
||||
return url(rtrim($uri, '/'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the url that links to this user's profile.
|
||||
* @return mixed
|
||||
*/
|
||||
public function getProfileUrl()
|
||||
public function getProfileUrl(): string
|
||||
{
|
||||
return url('/user/' . $this->id);
|
||||
}
|
||||
|
20
app/Http/Controllers/UserApiTokenController.php
Normal file
20
app/Http/Controllers/UserApiTokenController.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php namespace BookStack\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UserApiTokenController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* Show the form to create a new API token.
|
||||
*/
|
||||
public function create(int $userId)
|
||||
{
|
||||
$this->checkPermission('access-api');
|
||||
|
||||
// TODO - Form
|
||||
return 'test';
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -116,22 +116,24 @@ class UserController extends Controller
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified user.
|
||||
* @param int $id
|
||||
* @param \BookStack\Auth\Access\SocialAuthService $socialAuthService
|
||||
* @return Response
|
||||
*/
|
||||
public function edit($id, SocialAuthService $socialAuthService)
|
||||
public function edit(int $id, SocialAuthService $socialAuthService)
|
||||
{
|
||||
$this->checkPermissionOrCurrentUser('users-manage', $id);
|
||||
|
||||
$user = $this->user->findOrFail($id);
|
||||
$user = $this->user->newQuery()->with(['apiTokens'])->findOrFail($id);
|
||||
|
||||
$authMethod = ($user->system_name) ? 'system' : config('auth.method');
|
||||
|
||||
$activeSocialDrivers = $socialAuthService->getActiveDrivers();
|
||||
$this->setPageTitle(trans('settings.user_profile'));
|
||||
$roles = $this->userRepo->getAllRoles();
|
||||
return view('users.edit', ['user' => $user, 'activeSocialDrivers' => $activeSocialDrivers, 'authMethod' => $authMethod, 'roles' => $roles]);
|
||||
return view('users.edit', [
|
||||
'user' => $user,
|
||||
'activeSocialDrivers' => $activeSocialDrivers,
|
||||
'authMethod' => $authMethod,
|
||||
'roles' => $roles
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user