You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
174 lines
5.1 KiB
174 lines
5.1 KiB
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Traits\Authorizable;
|
|
use App\Models\Passport\Client;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Laravel\Passport\Http\Controllers\ClientController as PassportClientController;
|
|
class ClientController extends PassportClientController
|
|
{
|
|
// use Authorizable;
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index(Request $request)
|
|
{
|
|
// $result = Client::latest()->paginate();
|
|
$me = Auth::user();
|
|
|
|
if($request->get('clientId')) {
|
|
if( $me->hasRole('Admin') || $me->hasRole('Super Admin') ) {
|
|
$result = Client::findOrFail($request->get('clientId'))->paginate();
|
|
} else {
|
|
$result = $me->clients()->findOrFail($request->get('clientId'))->paginate();
|
|
}
|
|
}
|
|
else {
|
|
if( $me->hasRole('Admin') || $me->hasRole('Super Admin') ) {
|
|
$result = Client::latest()->paginate();
|
|
} else {
|
|
$result = $me->clients()->paginate();
|
|
}
|
|
}
|
|
|
|
return view('client.index', compact('result'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
return view('client.new');
|
|
}
|
|
|
|
/**
|
|
* Store a new client.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Laravel\Passport\Client|array
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$this->validation->make($request->all(), [
|
|
'name' => 'required|max:191',
|
|
'redirect' => ['required', $this->redirectRule],
|
|
'confidential' => 'boolean',
|
|
])->validate();
|
|
|
|
$client = $this->clients->create(
|
|
$request->user()->getAuthIdentifier(), $request->name, $request->redirect,
|
|
$request->provider, $request->personal_access_client ?? 0, $request->password_client, (bool) $request->input('confidential', true)
|
|
);
|
|
|
|
flash('ClientID: ' . $client->id . PHP_EOL . 'Secret Key: ' .$client->plainSecret . PHP_EOL . 'Warning: This Key show only one. You need remember it.' );
|
|
return view('client.show', compact('client'));
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param \App\Client $post
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function show(Client $client)
|
|
{
|
|
return view('client.show', compact('client'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param \App\Client $post
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
$me = Auth::user();
|
|
|
|
if( $me->hasRole('Admin') || $me->hasRole('Super Admin') ) {
|
|
$client = Client::findOrFail($id);
|
|
} else {
|
|
$client = $me->clients()->findOrFail($id);
|
|
}
|
|
|
|
if (! $client) {
|
|
// return new Response('', 404);
|
|
flash()->success('Permissions diened!');
|
|
return redirect()->route('clients.index');
|
|
}
|
|
return view('client.edit', compact('client'));
|
|
}
|
|
|
|
/**
|
|
* Update the given client.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param string $clientId
|
|
* @return \Illuminate\Http\Response|\Laravel\Passport\Client
|
|
*/
|
|
public function update(Request $request, $id)
|
|
{
|
|
$me = Auth::user();
|
|
|
|
if( $me->hasRole('Admin') || $me->hasRole('Super Admin') ) {
|
|
$client = Client::findOrFail($id);
|
|
} else {
|
|
$client = $me->clients()->findOrFail($id);
|
|
}
|
|
|
|
if (! $client) {
|
|
// return new Response('', 404);
|
|
flash()->success('Permissions diened!');
|
|
return redirect()->route('clients.index');
|
|
}
|
|
|
|
$this->validation->make($request->all(), [
|
|
'name' => 'required|max:191',
|
|
'redirect' => ['required', $this->redirectRule],
|
|
])->validate();
|
|
$client->name = $request->name;
|
|
$client->redirect = $request->redirect;
|
|
$client->provider = $request->provider;
|
|
$client->personal_access_client = $request->personal_access_client ?? 0;
|
|
$client->password_client = $request->password_client ?? 0;
|
|
$client->save();
|
|
// $this->clients->update(
|
|
// $client, $request->name, $request->redirect
|
|
// );
|
|
flash()->success('Client has been updated.');
|
|
return redirect()->route('clients.index');
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param \App\Client $post
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy(Request $request, $id)
|
|
{
|
|
$me = Auth::user();
|
|
|
|
if( $me->hasRole('Admin') || $me->hasRole('Super Admin') ) {
|
|
$post = Client::findOrFail($id);
|
|
} else {
|
|
$post = $me->clients()->findOrFail($id);
|
|
}
|
|
|
|
$post->delete();
|
|
|
|
flash()->success('Client has been deleted.');
|
|
|
|
return redirect()->route('clients.index');
|
|
}
|
|
}
|
|
|