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

Craft Auth scaffolding, remove registration #754

Open
1 task
funkywaddle opened this issue Jun 21, 2023 · 4 comments
Open
1 task

Craft Auth scaffolding, remove registration #754

funkywaddle opened this issue Jun 21, 2023 · 4 comments

Comments

@funkywaddle
Copy link

Is your feature request related to a problem?

I would like to have login, logout, password reset, etc functionality, but ability to remove registration for sites that I don't want registration open to the world.

What do we currently have to do now?

Not sure how to remove registration functionality.

Describe the solution you'd like

provide options to craft cli to scaffold the auth, but not include registration.

python craft auth --no-registration

This may require a create-user command to create a registered user since registration would be turned off, that asks for email, username, password, etc

python craft create-user

Describe alternatives you've considered

Alternatively, provide a way to turn off registration via configuration, so:

  • craft cli would do normal scaffolding.
  • I create the admin user,
  • Turn off registration via configuration

Would this be a breaking change ?

  • Yes

Anything else ?

No response

@MelonSmasher
Copy link

MelonSmasher commented Aug 10, 2023

@funkywaddle In the mean time did you figure out how to disable the registration routes? I'm coming from the Laravel world and this is something I need here as well.

This is defiantly a messy hack but I made my routes file look like this:

from masonite.routes import Route
from masonite.authentication import Auth

ROUTES = [Route.get("/", "WelcomeController@show")]
ROUTES += Auth.routes()

for route in ROUTES:
    if route.controller == 'auth.RegisterController@show':
        ROUTES.remove(route)

for route in ROUTES:
    if route.controller == 'auth.RegisterController@store':
        ROUTES.remove(route)

And the output of routes list:

python3 craft routes:list
+-------------------------+-----------------------+-----------+-----------------------------------------------------+---------------+
| URI                     | Name                  | Method(s) | Controller                                          | Middleware(s) |
+-------------------------+-----------------------+-----------+-----------------------------------------------------+---------------+
| /                       |                       | GET/HEAD  | WelcomeController@show                              | web           |
| /_exceptionite/actions  |                       | POST      | ExceptioniteController@run_action                   |               |
| /change_password/@token | change_password       | GET/HEAD  | auth.PasswordResetController@change_password        | web           |
| /change_password/@token | change_password.store | POST      | auth.PasswordResetController@store_changed_password | web           |
| /home                   | auth.home             | GET/HEAD  | auth.HomeController@show                            | web,auth      |
| /login                  | login                 | GET/HEAD  | auth.LoginController@show                           | web           |
| /login                  | login.store           | POST      | auth.LoginController@store                          | web           |
| /logout                 | logout                | GET/HEAD  | auth.LoginController@logout                         | web           |
| /password_reset         | password_reset        | GET/HEAD  | auth.PasswordResetController@show                   | web           |
| /password_reset         | password_reset.store  | POST      | auth.PasswordResetController@store                  | web           |
+-------------------------+-----------------------+-----------+-----------------------------------------------------+---------------+

So it seems to have removed the route but it defiantly is not efficient to run two for loops on the routes array to pull this off. There has to be a better way.

@funkywaddle
Copy link
Author

I come from the Land of Laravel myself, @MelonSmasher . That's one reason why I love this framework. It is so reminiscent/similar to how Laravel does things, and the directory structure, I feel at home.

As far as how to disable the registration routing, your way works.

Another way I found was to remove the call to Auth.routes(), go to the routes() method in masonite.authentication, copy the routes, paste them in your routes file, and remove the registration routes.

It's a more manual approach to yours, but I think slightly more concrete as it doesn't rely on matching strings. Just a pure copy/paste of needed routes.

@MelonSmasher
Copy link

MelonSmasher commented Aug 10, 2023

@funkywaddle I like your way much better. Thank you!

@ChristopherBrownie
Copy link

Yes, customizing auth routes and/or the registration controller can all be done manually in your code base.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

3 participants