aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/Http/Controllers/PublicKeyController.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Http/Controllers/PublicKeyController.php')
-rw-r--r--app/Http/Controllers/PublicKeyController.php23
1 files changed, 20 insertions, 3 deletions
diff --git a/app/Http/Controllers/PublicKeyController.php b/app/Http/Controllers/PublicKeyController.php
index d17a6f2..3257646 100644
--- a/app/Http/Controllers/PublicKeyController.php
+++ b/app/Http/Controllers/PublicKeyController.php
@@ -3,8 +3,10 @@
namespace App\Http\Controllers;
use App\PublicKeys;
+use Auth;
+use Cookie;
+use Illuminate\Foundation\Auth\User;
use Illuminate\Http\Request;
-use Illuminate\Support\Facades\Validator;
class PublicKeyController extends Controller
{
@@ -16,7 +18,7 @@ class PublicKeyController extends Controller
return $public_key ? $public_key : abort(404, "This public key doesn't exist.");
}
- public function setUsersKey(Request $request, $user_id)
+ public function setUsersKey(Request $request)
{
$request->validate([
'key' => 'required|max:4096',
@@ -27,6 +29,21 @@ class PublicKeyController extends Controller
$public_key->key = $request->input('key');
$public_key->save();
- return response()->json(['success' => 'Successfully inserted public key.']);
+ return response()->json(['message' => 'Successfully inserted public key.']);
+ }
+
+ public function setUsersKeyCookie(Request $request)
+ {
+ if ($_COOKIE['publickey'] !== null) {
+ $user = Auth::user();
+ $public_key = PublicKeys::firstOrNew(['user_id' => $user->id]);
+ $public_key->user_id = $user->id;
+ $public_key->key = $_COOKIE['publickey'];
+ $public_key->save();
+
+ return redirect('/');
+ } else {
+ abort(400, "Public key is malformed.");
+ }
}
}