Skip to content
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
12 changes: 10 additions & 2 deletions src/Authentication/Actions/Email2FA.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use CodeIgniter\HTTP\IncomingRequest;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\Shield\Exceptions\RuntimeException;
use CodeIgniter\Shield\Models\UserIdentityModel;

/**
Expand Down Expand Up @@ -58,6 +59,10 @@ public function handle(IncomingRequest $request)
return redirect()->route('auth-action-show')->with('error', lang('Auth.invalidEmail'));
}

if ($user === null) {
throw new RuntimeException('Cannot get the User.');
}

/** @var UserIdentityModel $identityModel */
$identityModel = model(UserIdentityModel::class);

Expand All @@ -69,13 +74,16 @@ public function handle(IncomingRequest $request)

// Send the user an email with the code
helper('email');
$email = emailer();
$email->setFrom(setting('Email.fromEmail'), setting('Email.fromName') ?? '')
$return = emailer()->setFrom(setting('Email.fromEmail'), setting('Email.fromName') ?? '')
->setTo($user->getAuthEmail())
->setSubject(lang('Auth.email2FASubject'))
->setMessage(view(setting('Auth.views')['action_email_2fa_email'], ['code' => $identity->secret]))
->send();

if ($return === false) {
throw new RuntimeException('Cannot send email for user: ' . $user->getAuthEmail());
}

return view(setting('Auth.views')['action_email_2fa_verify']);
}

Expand Down
12 changes: 10 additions & 2 deletions src/Authentication/Actions/EmailActivator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use CodeIgniter\Exceptions\PageNotFoundException;
use CodeIgniter\HTTP\IncomingRequest;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\Shield\Exceptions\RuntimeException;
use CodeIgniter\Shield\Models\UserIdentityModel;

class EmailActivator implements ActionInterface
Expand All @@ -18,6 +19,10 @@ public function show(): string
{
$user = auth()->user();

if ($user === null) {
throw new RuntimeException('Cannot get the User.');
}

/** @var UserIdentityModel $identityModel */
$identityModel = model(UserIdentityModel::class);

Expand All @@ -38,13 +43,16 @@ public function show(): string

// Send the email
helper('email');
$email = emailer();
$email->setFrom(setting('Email.fromEmail'), setting('Email.fromName') ?? '')
$return = emailer()->setFrom(setting('Email.fromEmail'), setting('Email.fromName') ?? '')
->setTo($user->getAuthEmail())
->setSubject(lang('Auth.emailActivateSubject'))
->setMessage(view(setting('Auth.views')['action_email_activate_email'], ['code' => $code]))
->send();

if ($return === false) {
throw new RuntimeException('Cannot send email for user: ' . $user->getAuthEmail());
}

// Display the info page
return view(setting('Auth.views')['action_email_activate_show'], ['user' => $user]);
}
Expand Down
7 changes: 7 additions & 0 deletions src/Exceptions/LogicException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace CodeIgniter\Shield\Exceptions;

class LogicException extends \LogicException
{
}
7 changes: 7 additions & 0 deletions src/Exceptions/RuntimeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace CodeIgniter\Shield\Exceptions;

class RuntimeException extends \RuntimeException
{
}