datatable.directory codebase
https://datatable.directory/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.7 KiB
61 lines
1.7 KiB
<?php
|
|
|
|
|
|
namespace App\Http\Controllers\Auth;
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\EmailConfirmation;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Collection;
|
|
|
|
class ConfirmEmailController extends Controller
|
|
{
|
|
public function resendConfirmation()
|
|
{
|
|
$user = user();
|
|
/** @var EmailConfirmation[]|Collection $ec */
|
|
$ec = $user->emailConfirmations()->valid()->get();
|
|
$email = '';
|
|
|
|
if ($ec->count() == 0) {
|
|
user()->sendEmailConfirmationLink($email = $user->email);
|
|
} else {
|
|
user()->sendEmailConfirmationLink($email = $ec[0]->email);
|
|
}
|
|
|
|
flash()->success("A new confirmation link was sent to your e-mail $email"); // not important, will fade
|
|
|
|
return back();
|
|
}
|
|
|
|
public function confirmEmailAndLogin(Request $request)
|
|
{
|
|
$input = $this->validate($request, [
|
|
'token' => 'string|required',
|
|
]);
|
|
|
|
$ec = EmailConfirmation::where('token', $input->token)->valid()->first();
|
|
if (!$ec) abort(400, "Invalid or expired token.");
|
|
|
|
$u = $ec->user;
|
|
if (!$u) abort(400, "User account does not exist.");
|
|
|
|
if ($ec->email) $u->email = $ec->email;
|
|
$wasConfirmed = $u->confirmed;
|
|
$u->confirmed = true;
|
|
$u->save();
|
|
$ec->delete();
|
|
|
|
\Auth::login($u, true);
|
|
|
|
if ($wasConfirmed) {
|
|
// user just changed an e-mail
|
|
flash()->success("Your new e-mail $ec->email was confirmed!");
|
|
} else {
|
|
flash()->success("Your e-mail $ec->email was confirmed, your account is now active!");
|
|
}
|
|
|
|
return redirect(route('profile.view', $u->name));
|
|
}
|
|
}
|
|
|