diff options
-rw-r--r-- | app/Http/Controllers/PublicKeyController.php | 17 | ||||
-rw-r--r-- | app/User.php | 7 | ||||
-rw-r--r-- | routes/web.php | 5 |
3 files changed, 25 insertions, 4 deletions
diff --git a/app/Http/Controllers/PublicKeyController.php b/app/Http/Controllers/PublicKeyController.php new file mode 100644 index 0000000..4fbdd64 --- /dev/null +++ b/app/Http/Controllers/PublicKeyController.php @@ -0,0 +1,17 @@ +<?php + +namespace App\Http\Controllers; + +use Illuminate\Support\Facades\DB; + +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); + } +} diff --git a/app/User.php b/app/User.php index 870d27c..4d6d0ee 100644 --- a/app/User.php +++ b/app/User.php @@ -1,7 +1,9 @@ <?php namespace App; -use Illuminate\Notifications\Notifiable; + use Illuminate\Foundation\Auth\User as Authenticatable; +use Illuminate\Notifications\Notifiable; + class User extends Authenticatable { use Notifiable; @@ -13,6 +15,7 @@ class User extends Authenticatable protected $fillable = [ 'name', 'email', 'password', ]; + /** * The attributes that should be hidden for arrays. * @@ -21,4 +24,4 @@ class User extends Authenticatable protected $hidden = [ 'password', 'remember_token', ]; -}
\ No newline at end of file +} diff --git a/routes/web.php b/routes/web.php index 851834e..b39b3f7 100644 --- a/routes/web.php +++ b/routes/web.php @@ -12,9 +12,10 @@ Auth::routes(); Route::middleware('auth', 'throttle:30') // throttle to 30 per minute ->group(function () { - Route::get('profile', 'UserController@Profile'); - Route::get('avatar/{user_id}', 'ImageController@getAvatar'); Route::get('/', ['as' => 'writeMessage', 'uses' => 'SocketController@writeMessage']); + Route::get('avatar/{user_id}', 'ImageController@getAvatar'); + Route::get('profile', 'UserController@Profile'); + Route::get('keys/public/{user_id}', 'PublicKeyController@getUsersKey'); Route::post('avatar', 'UserController@updateAvatar'); Route::post('sendMessage', 'SocketController@sendMessage'); |