How to disable registration new users in Laravel

后端 未结 27 2787
鱼传尺愫
鱼传尺愫 2020-12-07 10:34

I\'m using Laravel (v5).

I need one user and I\'ve already registered that. Now I want to disable registration for new users. Of course, I need the login form to wor

相关标签:
27条回答
  • 2020-12-07 11:19

    I found this to be the easiest solution in laravel 5.6! It redirects anyone who tries to go to yoursite.com/register to yoursite.com

    routes/web.php

    // redirect from register page to home page
    Route::get('/register', function () {
        return redirect('/');
    });
    
    0 讨论(0)
  • 2020-12-07 11:19

    add

    use \Redirect;
    

    at the top of the file

    0 讨论(0)
  • 2020-12-07 11:21

    Overwriting the getRegister and postRegister is tricky - if you are using git there is a high possibility that .gitignore is set to ignore framework files which will lead to the outcome that registration will still be possible in your production environment (if laravel is installed via composer for example)

    Another possibility is using routes.php and adding this line:

    Route::any('/auth/register','HomeController@index');
    

    This way the framework files are left alone and any request will still be redirected away from the Frameworks register module.

    0 讨论(0)
  • 2020-12-07 11:21

    In Laravel 5.5 is very simple, if you are using CRUD route system.

    Go to app/http/controllers/RegisterController there is namespace: Illuminate\Foundation\Auth\RegistersUser

    You need to go to the RegistersUser: Illuminate\Foundation\Auth\RegistersUser

    There is the method call showRegistrationForm change this: return view('auth.login'); for this: return redirect()->route('auth.login'); and remove from you blade page route call register. It may look like that:

     <li role="presentation">
         <a class="nav-link" href="{{ route('register') }}">Register</a>
     </li> 
    
    0 讨论(0)
  • 2020-12-07 11:22

    In laravel 5.3, you should override the default showRegistrationForm() by including the code below into the RegisterController.php file in app\Http\Controllers\Auth

        /**
         * Show the application registration form.
         *
         * @return \Illuminate\Http\Response
         */
        public function showRegistrationForm()
        {
            //return view('auth.register');
             abort(404);  //this will throw a page not found exception
        }
    

    since you don't want to allow registration, it's better to just throw 404 error so the intruder knows he is lost. And when you are ready for registraation in your app, uncomment //return view('auth.register'); then comment abort(404);

    \\\\\\\\\\\\\\\\\\\\JUST AN FYI///////////////////////////////

    If you need to use multiple authentication like create auth for users, members, students, admin, etc. then i advise you checkout this hesto/multi-auth its an awesome package for unlimited auths in L5 apps.

    You can read more abouth the Auth methodology and its associated file in this writeup.

    0 讨论(0)
  • 2020-12-07 11:23

    LAravel 5.6

    Auth::routes([
        'register' => false, // Registration Routes...
        'reset' => false, // Password Reset Routes...
        'verify' => false, // Email Verification Routes...
    ]);
    
    0 讨论(0)
提交回复
热议问题