Reputation: 37
I use the framework laravel 4, at the moment I'm difficult to check whether the entered email is still active or has been removed by the email provider ..
Please help. Thank you
Upvotes: 1
Views: 62
Reputation: 1464
You need to add the ability for a user to verify their email address by clicking a link in an email sent to them.
This usually looks something like this:
Add a migration
class AddVerificationColumnsToUsersTable extends Migration {
public function up()
{
Schema::table('users', function(Blueprint $table)
{
$table->boolean('confirmed')->default(0);
$table->string('confirmation_code')->nullable();
});
}
public function down()
{
Schema::table('users', function(Blueprint $table)
{
$table->dropColumn('confirmed');
$table->dropColumn('confirmation_code');
});
}
}
Inside your signup logic you will need to set the confirmation code:
This is an example and will have to be modified depending on your signup implementation:
public function store()
{
// Logic that gets input and creates $user goes here
$user->confirmation_code = str_random(30);
$user->save();
Mail::send('emails.verification', ['user' => $user], function($message) use ($user)
{
$message->from('[email protected]', 'Yoursite');
$message->to($user->email);
});
}
You will need to create an email template:
// resources/views/emails/verification.blade.php
Hi {{ $user->name }},
Please click the following link to verify your account:
<a href="{{ route('users.verify') }}">{{ route('users.verify') }}</a>
And finally, you'll need the verification route:
// routes.php
Route::get('users/verify/{confirmation_code}', [
'as' => 'users.verify',
'uses' => function ($confirmation_code) {
$user = User::where('confirmation_code', $confirmation_code)->first();
$user->confirmed = true;
$user->save();
}
]
Upvotes: 1
Reputation: 197
That's just possible with A confirmation email send to the known email address. When do you need to check this - registration, newsletter or what? If you want to use the confirmation then you need to add a New column in your database that holds the assigned random token and A view/controller/route to check this token (confirm/1234567890) and then search for a user with this token and set a flag that this user is confirmed.
Upvotes: 0