aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/Http
diff options
context:
space:
mode:
Diffstat (limited to 'app/Http')
-rw-r--r--app/Http/Controllers/PublicKeyController.php27
1 files changed, 21 insertions, 6 deletions
diff --git a/app/Http/Controllers/PublicKeyController.php b/app/Http/Controllers/PublicKeyController.php
index 4fbdd64..d17a6f2 100644
--- a/app/Http/Controllers/PublicKeyController.php
+++ b/app/Http/Controllers/PublicKeyController.php
@@ -2,16 +2,31 @@
namespace App\Http\Controllers;
-use Illuminate\Support\Facades\DB;
+use App\PublicKeys;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Validator;
class PublicKeyController extends Controller
{
public function getUsersKey($user_id)
{
- $public_key = DB::table('public_keys')
- ->where('user_id', $user_id)
- ->value('key');
- // TODO: Friends: do not allow to request every public key
- return $public_key ? $public_key : abort(404);
+ $public_key = PublicKeys::select('key')->where('user_id', $user_id)->first();
+ // TODO: Friends: do not allow to request every public key
+
+ return $public_key ? $public_key : abort(404, "This public key doesn't exist.");
+ }
+
+ public function setUsersKey(Request $request, $user_id)
+ {
+ $request->validate([
+ 'key' => 'required|max:4096',
+ ]);
+
+ $public_key = PublicKeys::firstOrNew(['user_id' => $user_id]);
+ $public_key->user_id = $user_id;
+ $public_key->key = $request->input('key');
+ $public_key->save();
+
+ return response()->json(['success' => 'Successfully inserted public key.']);
}
}