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

Move email confirmation to POST request #3038

Merged
merged 2 commits into from
Aug 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions locale/core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,11 @@ core:

# Translations in this namespace are used in views other than Flarum's normal JS client.
views:
# Translations in this namespace are displayed by the Confirm Email interface.
confirm_email:
submit_button: => core.ref.confirm_email
text: Click the button below to confirm your account's email.
title: => core.ref.confirm_email

# Translations in this namespace are displayed by the basic HTML content loader.
content:
Expand Down Expand Up @@ -656,6 +661,7 @@ core:
change_password: Change Password
color: Color # Referenced by flarum-tags.yml
confirm_password: Confirm Password
confirm_email: Confirm Email
confirmation_email_sent: "We've sent a confirmation email to {email}. If it doesn't arrive soon, check your spam folder."
custom_footer_text: Add HTML to be displayed at the very bottom of the page.
custom_footer_title: Edit Custom Footer
Expand Down
46 changes: 46 additions & 0 deletions src/Forum/Controller/ConfirmEmailViewController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/

namespace Flarum\Forum\Controller;

use Flarum\Http\Controller\AbstractHtmlController;
use Flarum\User\EmailToken;
use Illuminate\Contracts\View\Factory;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface as Request;

class ConfirmEmailViewController extends AbstractHtmlController
{
/**
* @var Factory
*/
protected $view;

/**
* @param Factory $view
*/
public function __construct(Factory $view)
{
$this->view = $view;
}

/**
* @param Request $request
* @return \Illuminate\Contracts\View\View
*/
public function render(Request $request)
{
$token = Arr::get($request->getQueryParams(), 'token');

$token = EmailToken::validOrFail($token);

return $this->view->make('flarum.forum::confirm-email')
->with('csrfToken', $request->getAttribute('session')->token());
}
}
8 changes: 7 additions & 1 deletion src/Forum/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@
$map->get(
'/confirm/{token}',
'confirmEmail',
$route->toController(Controller\ConfirmEmailController::class)
$route->toController(Controller\ConfirmEmailViewController::class),
);

$map->post(
'/confirm/{token}',
'confirmEmail.submit',
$route->toController(Controller\ConfirmEmailController::class),
);

$map->get(
Expand Down
25 changes: 25 additions & 0 deletions views/confirm-email.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@extends('flarum.forum::layouts.basic')

@section('title', $translator->trans('core.views.confirm_email.title'))

@section('content')
@if ($errors->any())
<div class="errors">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif

<form class="form" method="POST" action="">
<input type="hidden" name="csrfToken" value="{{ $csrfToken }}" />

<p>{{ $translator->trans('core.views.confirm_email.text') }}</p>

<p class="form-group">
<button type="submit" class="button">{{ $translator->trans('core.views.confirm_email.submit_button') }}</button>
</p>
</form>
@endsection