Skip to content
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

fix: use named routes for redirects and form submission #883

Merged
merged 1 commit into from
Oct 9, 2023

Conversation

sammyskills
Copy link
Contributor

Description

  • Used named route for redirect in the src/Controllers/RegisterController.php file
  • Used named route for form action in src/Views/email_action_show.php file.

Fixes #879

Checklist:

  • Securely signed commits
  • [] Component(s) with PHPDoc blocks, only if necessary or adds value
  • [] Unit testing, with >80% coverage
  • [] User guide updated
  • Conforms to style guide

Copy link
Member

@kenjis kenjis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@datamweb datamweb added the docs needed Pull requests needing documentation write-ups and/or revisions. label Oct 8, 2023
@kenjis
Copy link
Member

kenjis commented Oct 8, 2023

@datamweb What is the docs?
I would like to merge this and release beta7 soon.

@sammyskills
Copy link
Contributor Author

I was also wondering why @datamweb added the docs label 🤷‍♂️

@datamweb
Copy link
Collaborator

datamweb commented Oct 8, 2023

Guys,
It was not possible to use this method before, I know that there are people looking for this feature in the forum and even in the Github discussion, so it is better to add how to use this feature in the documents.

But I have a question, why do I face page 404 after using the following address?

$routes->group('{locale}', static function($routes) {
service('auth')->routes($routes);
});

localhost::8080/ja/login (is ok)

localhost::8080/login (404)
I would expect it to load with the default language set if no language is specified, not a 404 page. It is probably related to the framework?

Outside of this I feel it needs more investigation, about how to use filters and more.

In any case,
I don't have access to a PC right now, if you think there is ok, continue.

@sammyskills
Copy link
Contributor Author

sammyskills commented Oct 9, 2023

@datamweb, this is not a new feature. It is just a fix to make Shield routes less fragile by using named routes all through the codebase. Please read the issue #879 if you haven't read it already.

localhost::8080/login (404)
I would expect it to load with the default language set if no language is specified, not a 404 page. It is probably related to the framework?

What you are saying here (I think) is related to how you set up your locale to be detected. From the docs:

There are two methods supported to detect the correct locale during the request. The first is a “set and forget” method that will automatically perform content negotiation for you to determine the correct locale to use. The second method allows you to specify a segment in your routes that will be used to set the locale.

If you have set the locale using routes, then the system should be expecting localhost:8080/en/login as the default route assuming that your default locale is en.

Please try running the php spark routes command to see the available routes.

@kenjis
Copy link
Member

kenjis commented Oct 9, 2023

@datamweb
{locale} in a route is just a wild card. It will be interpreted as the regex [^/]+.

$routes->group('{locale}', static function($routes) {
    service('auth')->routes($routes);
});
+--------+----------------------------------+--------------------+--------------------------------------------------------------------+----------------+---------------+
| Method | Route                            | Name               | Handler                                                            | Before Filters | After Filters |
+--------+----------------------------------+--------------------+--------------------------------------------------------------------+----------------+---------------+
| GET    | /                                | »                  | \App\Controllers\Home::index                                       | session        | toolbar       |
| GET    | {locale}/register                | register           | \CodeIgniter\Shield\Controllers\RegisterController::registerView   | session        | toolbar       |
| GET    | {locale}/login                   | login              | \CodeIgniter\Shield\Controllers\LoginController::loginView         | session        | toolbar       |
| GET    | {locale}/login/magic-link        | magic-link         | \CodeIgniter\Shield\Controllers\MagicLinkController::loginView     | session        | toolbar       |
| GET    | {locale}/login/verify-magic-link | verify-magic-link  | \CodeIgniter\Shield\Controllers\MagicLinkController::verify        | session        | toolbar       |
| GET    | {locale}/logout                  | logout             | \CodeIgniter\Shield\Controllers\LoginController::logoutAction      | session        | toolbar       |
| GET    | {locale}/auth/a/show             | auth-action-show   | \CodeIgniter\Shield\Controllers\ActionController::show             | session        | toolbar       |
| POST   | {locale}/register                | register           | \CodeIgniter\Shield\Controllers\RegisterController::registerAction | session        | toolbar       |
| POST   | {locale}/login                   | »                  | \CodeIgniter\Shield\Controllers\LoginController::loginAction       | session        | toolbar       |
| POST   | {locale}/login/magic-link        | »                  | \CodeIgniter\Shield\Controllers\MagicLinkController::loginAction   | session        | toolbar       |
| POST   | {locale}/auth/a/handle           | auth-action-handle | \CodeIgniter\Shield\Controllers\ActionController::handle           | session        | toolbar       |
| POST   | {locale}/auth/a/verify           | auth-action-verify | \CodeIgniter\Shield\Controllers\ActionController::verify           | session        | toolbar       |
+--------+----------------------------------+--------------------+--------------------------------------------------------------------+----------------+---------------+

@kenjis kenjis mentioned this pull request Oct 9, 2023
3 tasks
@kenjis
Copy link
Member

kenjis commented Oct 9, 2023

@datamweb I sent a PR for docs: #884

@datamweb
Copy link
Collaborator

datamweb commented Oct 9, 2023

@sammyskills and @kenjis thank you!

@kenjis kenjis removed the docs needed Pull requests needing documentation write-ups and/or revisions. label Oct 9, 2023
@kenjis kenjis merged commit a2a5b0d into codeigniter4:develop Oct 9, 2023
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Bad redirection in the registration process (auth/a/show and auth/a/verify)
3 participants