Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1781 - fix 405 error during twostep workflow from user settings page #1968

Merged
merged 1 commit into from
Oct 28, 2021

Conversation

glennforrest
Copy link
Contributor

Addresses the 405 error described in the following issue

@@ -317,6 +317,7 @@
Route::get('/{username}/settings/privacy{hash?}', [App\Http\Controllers\UserController::class, 'privacy'])->name('user_privacy');
Route::get('/{username}/settings/security{hash?}', [App\Http\Controllers\UserController::class, 'security'])->name('user_security');
Route::get('/{username}/settings/notification{hash?}', [App\Http\Controllers\UserController::class, 'notification'])->name('user_notification');
Route::get('/{username}/settings/change_twostep', [App\Http\Controllers\UserController::class, 'changeTwoStep']);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@glennforrest Im confused by this as its already defined

Route::post('/{username}/settings/change_twostep', [App\Http\Controllers\UserController::class, 'changeTwoStep'])->name('change_twostep');
and should be a POST.

Is used here

@if (config('auth.TwoStepEnabled') == true)
<div role="tabpanel" class="tab-pane" id="twostep">
<form role="form" method="POST"
action="{{ route('change_twostep', ['username' => $user->username]) }}">
@csrf
<div class="well">
<h2 class="text-bold">Two Step Authentication</h2>
<hr>
<label for="twostep" class="control-label">Use Two Step Auth?</label>
<div class="radio-inline">
<label><input type="radio" name="twostep" @if ($user->twostep == 1) checked @endif
value="1">@lang('common.yes')</label>
</div>
<div class="radio-inline">
<label><input type="radio" name="twostep" @if ($user->twostep == 0) checked
@endif value="0">@lang('common.no')</label>
</div>
<br>
</div>
<div class="well text-center">
<button type="submit" class="btn btn-primary">Save Changes</button>
</div>
</form>
</div>
</div>
@endif

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, so my idea about a fix for this was basically to just create a redirect to prevent the 405 method not allowed error by defining the GET route. So I just chucked this in the existing controller method, I figured this would be an easier fix than dealing with the whole nextURI set up.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

@@ -318,6 +318,10 @@ public function security(Request $request, $username): \Illuminate\Contracts\Vie
*/
protected function changeTwoStep(Request $request)
{
if ($request->getMethod() == 'GET') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this is done when its a POST route.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can define both in laravel routes, similar to how a PUT request to /posts/{post} typically resolves to an update request whereas a DELETE request to the same uri /posts/{post}` resolves to a destroy/delete method.

Can shift this to a completely separate method on the controller if you'd prefer?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No its fine.

@HDVinnie HDVinnie merged commit 510b373 into HDInnovations:master Oct 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Initially enabling 2-Step Auth will lead to Error 405: Method Not Allowed!
2 participants