mirror of https://github.com/pixelfed/pixelfed
Add Email Verification
parent
faec46069b
commit
a415b421cb
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class EmailVerification extends Model
|
||||||
|
{
|
||||||
|
public function url()
|
||||||
|
{
|
||||||
|
$base = config('app.url');
|
||||||
|
$path = '/i/confirm-email/' . $this->user_token . '/' . $this->random_token;
|
||||||
|
return "{$base}{$path}";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Auth, Closure;
|
||||||
|
|
||||||
|
class EmailVerificationCheck
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle an incoming request.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param \Closure $next
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle($request, Closure $next)
|
||||||
|
{
|
||||||
|
if($request->user() &&
|
||||||
|
config('pixelfed.enforce_email_verification') &&
|
||||||
|
is_null($request->user()->email_verified_at) &&
|
||||||
|
!$request->is('i/verify-email') && !$request->is('login') &&
|
||||||
|
!$request->is('i/confirm-email/*')
|
||||||
|
) {
|
||||||
|
return redirect('/i/verify-email');
|
||||||
|
}
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Mail;
|
||||||
|
|
||||||
|
use App\EmailVerification;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Mail\Mailable;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
|
||||||
|
class ConfirmEmail extends Mailable
|
||||||
|
{
|
||||||
|
use Queueable, SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new message instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(EmailVerification $verify)
|
||||||
|
{
|
||||||
|
$this->verify = $verify;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build the message.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function build()
|
||||||
|
{
|
||||||
|
return $this->markdown('emails.confirm_email')->with(['verify'=>$this->verify]);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class CreateEmailVerificationsTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('email_verifications', function (Blueprint $table) {
|
||||||
|
$table->bigIncrements('id');
|
||||||
|
$table->bigInteger('user_id')->unsigned();
|
||||||
|
$table->string('email')->nullable();
|
||||||
|
$table->string('user_token')->index();
|
||||||
|
$table->string('random_token')->index();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('email_verifications');
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
@extends('layouts.app')
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<div class="container mt-4">
|
||||||
|
<div class="col-12 col-md-8 offset-md-2">
|
||||||
|
@if (session('status'))
|
||||||
|
<div class="alert alert-success">
|
||||||
|
{{ session('status') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header font-weight-bold bg-white">Confirm Email Address</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<p class="lead">You need to confirm your email address (<span class="font-weight-bold">{{Auth::user()->email}}</span>) before you can proceed.</p>
|
||||||
|
<hr>
|
||||||
|
<form method="post">
|
||||||
|
@csrf
|
||||||
|
<button type="submit" class="btn btn-primary btn-block py-1 font-weight-bold">Send Confirmation Email</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endsection
|
@ -0,0 +1,12 @@
|
|||||||
|
@component('mail::message')
|
||||||
|
# Email Confirmation
|
||||||
|
|
||||||
|
Please confirm your email address.
|
||||||
|
|
||||||
|
@component('mail::button', ['url' => $verify->url()])
|
||||||
|
Confirm Email
|
||||||
|
@endcomponent
|
||||||
|
|
||||||
|
Thanks,<br>
|
||||||
|
{{ config('app.name') }}
|
||||||
|
@endcomponent
|
Loading…
Reference in New Issue