diff options
author | Marvin Borner | 2018-07-07 16:13:20 +0200 |
---|---|---|
committer | Marvin Borner | 2018-07-07 16:13:20 +0200 |
commit | 84e758a59cea20508bad93a129acbad5d4474c5d (patch) | |
tree | 5e73aa7aa903e4e68ef40c681004bdc3bd979ae0 /app/Http/Controllers/PublicKeyController.php | |
parent | 82fa40442ad56f7de3cb6984bfb187e429476c76 (diff) |
Added public/private key generation & insertion
Diffstat (limited to 'app/Http/Controllers/PublicKeyController.php')
-rw-r--r-- | app/Http/Controllers/PublicKeyController.php | 23 |
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."); + } } } |