aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--app/Http/Controllers/PublicKeyController.php27
-rw-r--r--routes/web.php3
2 files changed, 23 insertions, 7 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.']);
}
}
diff --git a/routes/web.php b/routes/web.php
index b39b3f7..370fbb9 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -10,7 +10,7 @@
|
*/
Auth::routes();
-Route::middleware('auth', 'throttle:30') // throttle to 30 per minute
+Route::middleware('auth', 'throttle:30000') // throttle to 30 per minute
->group(function () {
Route::get('/', ['as' => 'writeMessage', 'uses' => 'SocketController@writeMessage']);
Route::get('avatar/{user_id}', 'ImageController@getAvatar');
@@ -18,5 +18,6 @@ Route::middleware('auth', 'throttle:30') // throttle to 30 per minute
Route::get('keys/public/{user_id}', 'PublicKeyController@getUsersKey');
Route::post('avatar', 'UserController@updateAvatar');
+ Route::post('keys/public/{user_id}', 'PublicKeyController@setUsersKey');
Route::post('sendMessage', 'SocketController@sendMessage');
});