controller refactoring part 24

This commit is contained in:
Peter Papp
2021-07-21 18:46:55 +02:00
parent 54f1f4c9a8
commit 6d8a7a429c
29 changed files with 561 additions and 209 deletions
@@ -0,0 +1,37 @@
<?php
namespace Domain\Sharing\Controllers;
use Exception;
use Illuminate\Http\Response;
use Domain\Sharing\Models\Share;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash;
use Domain\Sharing\Resources\ShareResource;
use Domain\Sharing\Requests\AuthenticateShareRequest;
class VisitorUnlockLockedShareController extends Controller
{
/**
* Check Password for protected item
*
* @throws Exception
*/
public function __invoke(
AuthenticateShareRequest $request,
Share $shared,
): Response {
// Check password
if (Hash::check($request->input('password'), $shared->password)) {
$cookie = json_encode([
'token' => $shared->token,
'authenticated' => true,
]);
// Return authorize token with shared options
return response(new ShareResource($shared), 200)
->cookie('share_session', $cookie, 43200);
}
return response(__t('incorrect_password'), 401);
}
}