Hello,
I have been for hours on this and cannot find any logic to it....
I have created a registration activation link sent by email, when the user clicks on it he should be redirected to the home page with a success message.
Each time I go to the activation url, I get sent to the /home page.
Here is my code:
web.php
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Auth::routes();
Route::get('/', function () { return view('home'); });
//INDIVIDUAL PAGES
Route::get('beforeafter', function () { return view('beforeafter'); });
Route::get('contactus', function () { return view('contactus'); });
Route::get('dirtyzones', function () { return view('dirtyzones'); });
Route::get('joinus', function () { return view('joinus'); });
Route::get('videos', function () { return view('videos'); });
//INDIVIDUAL PAGES
Route::get('home', 'HomeController@index')->name('home');
Route::get('auth.register', 'auth.RegisterController@showRegistrationForm');
//ACTIVATE USER
Route::get('activate', 'ActivateUserController@userActivation');
actviateUserController.php
<?php
namespace App\Http\Controllers;
use App\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Http\RedirectResponse;
class ActivateUserController extends Controller
{
public function userActivation(Request $request)
{
$email = $request->input('email');
$activationtoken = $request->input('activationtoken');
$findUser = \App\User::where('email', $email)
->where('activationtoken', $activationtoken)
->get();
$alreadyActivatedUser = \App\User::where('email', $email)
->where('isactivated', 1)
->get();
if(count($findUser) > 0) {
$updateUser = \App\User::where('activationtoken',$activationtoken)
->where('email', $email)
->update(['isactivated' => 1, 'activationtoken' => null]);
return redirect()->route('home')->with('success', 'Your account is now activated!');
}else{
return redirect()->route('home')->with('errors', 'Your account has already been activated!');
}
}
}
url to click http://mywebsite.dev/activate?email=xxxxxxxxx@gmail.com&activationtoken=xxxxxx
I really cannot understand why I am being sent to /login each time....
Thank you for your help!
my analysis is,
Your activation is successful.. then redirect to /home
while your HomeController has auth midleware.. hence you need to be (logged in) or (Auth::check == true) in order to access /home controller
you can check your HomeController via terminal php artisan route:list
to remove the Auth middleware
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community