-
Notifications
You must be signed in to change notification settings - Fork 142
feat: shield:setup does Email setup
#876
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
Merged
kenjis
merged 16 commits into
codeigniter4:develop
from
kenjis:feat-setup-command-email-setup
Oct 7, 2023
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
86fe095
feat: add Config\Email setup
kenjis 0ea6604
feat: add InputOutput::error() for testing
kenjis 2196278
refactor: use InputOutput::error()
kenjis 57986ba
refactor: extract BaseCommand
kenjis af9df72
docs: update docs
kenjis b92554d
docs: update sample code
kenjis c27ec88
refactor: remove unused property
kenjis 02188a7
fix: add null check
kenjis b788545
refactor: use config()
kenjis 41fb8c8
test: add test for EmailConfig is fine
kenjis 7eb6697
test: extract methods
kenjis fe0da3d
chore: add RecastingRemovalRector in skip()
kenjis a3f947d
fix: remove unneeded CITestStreamFilter removal
kenjis a7ad37e
fix: add missing CITestStreamFilter::addErrorFilter()
kenjis d03c793
fix: set InputOutput when constructing
kenjis f6c1a4d
test: add logic to normalize line break code
kenjis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,9 +54,12 @@ Require it with an explicit version constraint allowing its desired stability. | |
|
|
||
| ## Initial Setup | ||
|
|
||
| There are a few setup items to do before you can start using Shield in | ||
| your project. | ||
|
|
||
| ### Command Setup | ||
|
|
||
| 1. Run the following command. This command handles steps 1-5 of *Manual Setup* and runs the migrations. | ||
| 1. Run the following command. This command handles steps 1-6 of *Manual Setup*. | ||
|
|
||
| ```console | ||
| php spark shield:setup | ||
|
|
@@ -67,36 +70,8 @@ Require it with an explicit version constraint allowing its desired stability. | |
| If you want to customize table names, you must change the table names before running database migrations. | ||
| See [Customizing Table Names](../customization/table_names.md). | ||
|
|
||
| 2. Configure **app/Config/Email.php** to allow Shield to send emails with the [Email Class](https://codeigniter.com/user_guide/libraries/email.html). | ||
|
|
||
| ```php | ||
| <?php | ||
|
|
||
| namespace Config; | ||
|
|
||
| use CodeIgniter\Config\BaseConfig; | ||
|
|
||
| class Email extends BaseConfig | ||
| { | ||
| /** | ||
| * @var string | ||
| */ | ||
| public $fromEmail = '[email protected]'; | ||
|
|
||
| /** | ||
| * @var string | ||
| */ | ||
| public $fromName = 'your name'; | ||
|
|
||
| // ... | ||
| } | ||
| ``` | ||
|
|
||
| ### Manual Setup | ||
|
|
||
| There are a few setup items to do before you can start using Shield in | ||
| your project. | ||
|
|
||
| 1. Copy the **Auth.php**, **AuthGroups.php**, and **AuthToken.php** from **vendor/codeigniter4/shield/src/Config/** into your project's config folder and update the namespace to `Config`. You will also need to have these classes extend the original classes. See the example below. These files contain all the settings, group, and permission information for your application and will need to be modified to meet the needs of your site. | ||
|
|
||
| ```php | ||
|
|
@@ -138,7 +113,24 @@ your project. | |
|
|
||
| 4. **Security Setup** Set `Config\Security::$csrfProtection` to `'session'` for security reasons, if you use Session Authenticator. | ||
|
|
||
| 5. **Migration** Run the migrations. | ||
| 5. Configure **app/Config/Email.php** to allow Shield to send emails with the [Email Class](https://codeigniter.com/user_guide/libraries/email.html). | ||
|
|
||
| ```php | ||
| <?php | ||
|
|
||
| namespace Config; | ||
|
|
||
| use CodeIgniter\Config\BaseConfig; | ||
|
|
||
| class Email extends BaseConfig | ||
| { | ||
| public string $fromEmail = '[email protected]'; | ||
| public string $fromName = 'your name'; | ||
| // ... | ||
| } | ||
| ``` | ||
|
|
||
| 6. **Migration** Run the migrations. | ||
|
|
||
| !!! note | ||
|
|
||
|
|
@@ -155,28 +147,3 @@ your project. | |
|
|
||
| 1. Remove sample migration files in **tests/_support/Database/Migrations/** | ||
| 2. Or install `sqlite3` php extension | ||
|
|
||
| 6. Configure **app/Config/Email.php** to allow Shield to send emails. | ||
|
|
||
| ```php | ||
| <?php | ||
|
|
||
| namespace Config; | ||
|
|
||
| use CodeIgniter\Config\BaseConfig; | ||
|
|
||
| class Email extends BaseConfig | ||
| { | ||
| /** | ||
| * @var string | ||
| */ | ||
| public $fromEmail = '[email protected]'; | ||
|
|
||
| /** | ||
| * @var string | ||
| */ | ||
| public $fromName = 'your name'; | ||
|
|
||
| // ... | ||
| } | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace CodeIgniter\Shield\Commands; | ||
|
|
||
| use CodeIgniter\CLI\BaseCommand as FrameworkBaseCommand; | ||
| use CodeIgniter\CLI\Commands; | ||
| use CodeIgniter\Shield\Commands\Utils\InputOutput; | ||
| use Psr\Log\LoggerInterface; | ||
|
|
||
| abstract class BaseCommand extends FrameworkBaseCommand | ||
| { | ||
| protected static ?InputOutput $io = null; | ||
|
|
||
| /** | ||
| * The group the command is lumped under | ||
| * when listing commands. | ||
| * | ||
| * @var string | ||
| */ | ||
| protected $group = 'Shield'; | ||
|
|
||
| public function __construct(LoggerInterface $logger, Commands $commands) | ||
| { | ||
| parent::__construct($logger, $commands); | ||
|
|
||
| $this->ensureInputOutput(); | ||
| } | ||
|
|
||
| /** | ||
| * Asks the user for input. | ||
| * | ||
| * @param string $field Output "field" question | ||
| * @param array|string $options String to a default value, array to a list of options (the first option will be the default value) | ||
| * @param array|string $validation Validation rules | ||
| * | ||
| * @return string The user input | ||
| */ | ||
| protected function prompt(string $field, $options = null, $validation = null): string | ||
| { | ||
| return self::$io->prompt($field, $options, $validation); | ||
| } | ||
|
|
||
| /** | ||
| * Outputs a string to the cli on its own line. | ||
| */ | ||
| protected function write( | ||
| string $text = '', | ||
| ?string $foreground = null, | ||
| ?string $background = null | ||
| ): void { | ||
| self::$io->write($text, $foreground, $background); | ||
| } | ||
|
|
||
| /** | ||
| * Outputs an error to the CLI using STDERR instead of STDOUT | ||
| */ | ||
| protected function error( | ||
| string $text, | ||
| string $foreground = 'light_red', | ||
| ?string $background = null | ||
| ): void { | ||
| self::$io->error($text, $foreground, $background); | ||
| } | ||
|
|
||
| protected function ensureInputOutput(): void | ||
| { | ||
| if (self::$io === null) { | ||
| self::$io = new InputOutput(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @internal Testing purpose only | ||
| */ | ||
| public static function setInputOutput(InputOutput $io): void | ||
| { | ||
| self::$io = $io; | ||
| } | ||
|
|
||
| /** | ||
| * @internal Testing purpose only | ||
| */ | ||
| public static function resetInputOutput(): void | ||
| { | ||
| self::$io = null; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.