laravel 5.1 about Resetting Passwords - laravel

If I didn't log in , I can go to Route:http://localhost:8000/password/email,and show the view.
But, when I logged in,it go to Route:http://localhost:8000/home with an error
NotFoundHttpException in RouteCollection.php line 161:
I think it should also return view password.blade.php,but it did not
How to solve?

After a successful authentication the default action is to go to '/home', if there isn't the associated routes or views (controllers are provided by default) it causes the 'NotFoundHttpException' you mentioned.
If you haven't done already, you need to create the routes and views . The documentation mentions what you need to include.
If these exist already and you're wondering how to change the default behaviour of redirecting the user to '/home', you you can customize the post-authentication redirect location by defining a redirectPath property on the AuthController:
protected $redirectPath = '/dashboard';

Related

add routes after login page for user

I use backpack 4 for laravel(laravel 8)and can't write a route for the user page. After login user has to get /user/dashboard or /dashboard, but the user is redirected to /admin/dashboard. How can I solve this problem?
web.php
Route::get('/', function() {
return redirect()->route('backpack.auth.login');
});
Route::get('/user/dashboard', [DashboardUserController::class, 'index'])->middleware(['web','admin']);
If your users won't ever need to use Backpack and should only able to view the dashboard, you could add a new middleware to Backpack's set of middlewares that checks if your user is an admin or a normal user to redirect them if they are not an admin.
Because Backpack registers the login routes itself, you can't just add your middleware to the route on registration. Instead you'll need to add your middleware to Backpack's admin middleware group. That's the one that gets added to all admin routes.
Steps:
Create the new middleware:
php artisan make:middleware RedirectToDashboard
Open the new middleware at app/Http/Middleware/RedirectToDashboard.php
Change the handle method to look something like this:
public function handle(Request $request, Closure $next)
{
if($request->user()->isNormalUser()) { // You need to change this to the check if the user is a normal user, that's specific to your application
return redirect()->to('dashboard'); // 'dashboard' is the name of your route, you may need to change it.
}
return $next($request);
}
Add the new middleware to Backpack's default set of middlewares in config/backpack/base.php. Open the file and look for the middleware_class entry (most likely somewhere around line 220). Add \App\Http\Middleware\RedirectToDashboard::class to the array.
Log into Backpack as a normal user and check if you get redirected.
The /admin prefix comes from the file: config/backpack/base.php.
Remove route_prefix from the file.
Your users will be redirected to /dashboard.

Auth Middleware reroutes to a wrong signin page auth.signin

I am using laravel 5.1 and i have applied an Auth middleware to a route, it works except my auth page is: /signin Not what it reroutes to /Auth.signin
I had deleted the default Auth folder and recreated my own inside app/Http/Controllers
Ok i solved it by going to the /Http/Middleware/Authenticate.php and changed this part of the code:
return redirect()->guest('auth.signin');
To:
return redirect()->guest('signin');

Laravel - GET request download logout automaticlly

i have a download file link like this:
Download file
ROUTES
Route::group(['middleware' => ['web','auth','Admin','active'], 'prefix' => 'admin'], function(){
// USERS
Route::resource('user','UserController');
Route::post('user/permissions/update','UserController#update_permission')->name('update_user_permissions');
// MODULI
Route::resource('module','ModuleController');
// MODULISITICA
Route::resource('modulistica','ModulisticaController');
Route::post('modulistica_cliente','ModulisticaController#update_client_module')->name('modulistica_post_cliente');
Route::post('modulistica_prodotto','ModulisticaController#update_product_module')->name('modulistica_post_prodotto');
Route::get('modulistica/download/cliente/{file}','ModulisticaController#download_cliente')->name('modulistica_download_cliente');
Route::get('modulistica/download/{file}','ModulisticaController#download_module')->name('modulistica_download_module');
Route::get('modulistica/download/prodotto/{file}','ModulisticaController#download_prodotto')->name('modulistica_download_prodotto');
// UTILITY
Route::post('utility/become/client','UtilityController#become_client')->name('utility_become_client');
Route::resource('loan','LoanController');
Route::get('area_download/document/{file}', function ($file){
$path_file = storage_path().'/app/public/documents/'.$file;
return response()->download($path_file, $file);
})->name('download_document');
});
ERROR
Arrival at the "https://mysite.it/admin/loan" view without problems. When I click on the GET link it redirects me to the LOGIN, but being my user logged in by login redirects me to "https://mysite.it/home".
I did some tests getting the following information:
Request does not arrive at route "area_download / document / {file}"
The request does not arrive at the 'Admin', 'active' middlewares.
So my conclusions are that the problem is in the middleware "Web" or "Auth" but I can not understand why. Place the entire group of routes, if it can be useful. If you need more on the routes, I can attach screenshots!
I would appreciate your help thank you!
If you just allow downloading a file without any authentication then,
You can try this :
Blade File
Download file
From this user can directly download the file. Just need to add file path in href and download attribute.
or else remove the middleware AUTH if you don't want to Authenticate the user.
And you want to authenticate the user then need route:list and middleware details.
I found the solution! the problem was that my get request was made this way.
https://mysite.it/admin/area_download/document/example.pdf
the final PDF extension creates system error. Avoiding the final extension such as:
https://mysite.it/admin/area_download/document/example.pdf/go
Problem solved!

How to change /home after login in a laravel project

I am new in laravel framework. I install the Auth Class in my project. So when I login in my project it goes to dashboard but url is ('/home'). I want to change this path and after login I want that it goes ('/dashboard'). For that jobs, which file I want to change? I have find 4 file where /home is decleared. Thats are web.php, LoginController.php, HomeController.php, RedirectIfAuthenticated.php. Which file I will change? or any more file there?
Web.php file
homeController.php file
loginController.php file
redirectIfAuthenticated.php file
There's now an easier way to do this in Laravel 6.X.
Simply change the constant in theapp/Providers/RouteServiceProvider.php file.
/**
* The path to the "home" route for your application.
*
* #var string
*/
public const HOME = '/new-url';
After that, change your route in your routes/web.php file.
Route::get('/new-url', 'Controller#method');
// If you don't want to use the HomeController, be sure to include the auth middleware.
Route::get('/new-url', 'Controller#method')->middleware('auth');
You can delete the HomeController if you're not using it in your route, won't cause any issues.
You have to add the redirectTo property to the LoginController, RegisterController, and ResetPasswordController files:
protected $redirectTo = '/';
It is well explained in the Laravel documentation:
https://laravel.com/docs/5.5/authentication#authentication-quickstart
I have come across this before... change the protected
$redirecto = /home to / in the login controller, then got to routes->web and change the Route::get('/home') to Route::get('/')->name('dashboard')
or you can just change $redirecto = "/dashboard" in the login controller and make sure that you create/update a path in the routes.
Hope it helps.

Laravel 4 - changing resource root routing path

In a Laravel 4 installation, Using Jeffrey Way's Laravel 4 Generators, I set up a 'tweet' resource, using the scaffolding command from his example:
php artisan generate:scaffold tweet --fields="author:string, body:text"
This generated the model, view, controller, migration and routing information for the tweet type. After migrating the database, visiting http://localhost:8000/tweets works fine, and shows the expected content.
The contents of the routes.php file at this point is:
Route::resource('tweets', 'TweetsController');
Now I would like to move the url for tweets up one level into admin/tweets, so the above url should become: http://localhost:8000/admin/tweets. Please note that I am not treating 'Admin' as a resource, but instead just want to add it for hypothetical organizational purposes.
Changing the routes.php file to:
Route::resource('admin/tweets', 'TweetsController');
Does not work, and displays the following error:
Unable to generate a URL for the named route "tweets.create" as such route does not exist.
Similarly when using the following:
Route::group(array('prefix' => 'admin'), function() {
Route::resource('tweets', 'TweetsController');
});
As was suggested in this stackoverflow question.
Using php artisan routes reveals that the named routes also now have admin prefixed to them, turning tweets.create into admin.tweets.create.
Why is the error saying that it cannot find tweets.create? shouldn't that automatically be resolved (judging by the routes table), to use admin.tweets.create?
How can I change my routing so that this error no longer occurs?
I just tested with new resource controller and it works fine for me.
The problem is not with the Route, its with the named routes used in your application.
check your view files there are link to route like link_to_route('tweets.create', 'Add new tweet'), this is creating the error because when you add admin as prefix tweets.create doesn't exists so change it to admin.tweets.create every where, in your controller also where ever named route is used.

Resources