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 | |
parent | 82fa40442ad56f7de3cb6984bfb187e429476c76 (diff) |
Added public/private key generation & insertion
Diffstat (limited to 'app/Http/Controllers')
-rw-r--r-- | app/Http/Controllers/Auth/LoginController.php | 10 | ||||
-rw-r--r-- | app/Http/Controllers/Auth/RegisterController.php | 2 | ||||
-rw-r--r-- | app/Http/Controllers/PublicKeyController.php | 23 |
3 files changed, 29 insertions, 6 deletions
diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 191b2b6..87f66d5 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\AuthenticatesUsers; +use Illuminate\Http\Request; class LoginController extends Controller { @@ -16,16 +17,21 @@ class LoginController extends Controller | redirecting them to your home screen. The controller uses a trait | to conveniently provide its functionality to your applications. | - */ + */ use AuthenticatesUsers; + protected function authenticated(Request $request, $user) + { + return redirect('/keys/cookie/public'); + } + /** * Where to redirect users after login. * * @var string */ - protected $redirectTo = '/'; + protected $redirectTo = '/keys/cookie/public'; /** * Create a new controller instance. diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index be65e85..fb7a4c1 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -28,7 +28,7 @@ class RegisterController extends Controller * * @var string */ - protected $redirectTo = '/'; + protected $redirectTo = '/keys/cookie/public'; /** * Create a new controller instance. 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."); + } } } |