Hey people,
first, I am new to this forum, so hi to everyone!
Second, I think I am trying to implement a similar thing to what is discussed here and I run into a problem I can't get my head around.
The logic:
Some admin creates a new user in some kind of admin panel. The user will be created and put into the users database table with some random password.
Now a password reset link shall be emailed to that person so she / he can choose a new password by her-/himself.
The problem:
The links in that email are not working. In fact I get redirected to /home, which I think is the path to redirect when the url is not valid as per Illuminate\Foundation\Auth\RedirectUsers
The strange:
It all works fine, when the new user goes to the login view, clicks "forgot my password" and does the reset this way.
What am I missing?
Here is the code:
<?php
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
use App\Models\User;
use Password;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Validator;
class UserController extends AdminBaseController
{
use SendsPasswordResetEmails;
...
public function store(Request $request, $id = NULL)
{
$redirect_url = 'admin/users/create';
if($id) {
$obj = User::find($id);
$redirect_url = 'admin/users/update/' . $id;
}
$rules = [
'first_name' => 'required',
'last_name' => 'required',
'email' => 'required',
'level' => 'required',
];
$input = Input::only(array_keys($rules));
$validator = Validator::make($input, $rules);
if($validator->fails()) {
return redirect($redirect_url)
->withErrors($validator)
->withInput();
}
$pw = User::generatePassword();
if($id && $id == $request->get('id'))
{
User::where('id', $id)->update($input);
}
else
{
$this->sendResetLinkEmail($request);
$user = new User;
$user->first_name = $request->input('first_name');
$user->last_name = $request->input('last_name');
$user->email = $request->input('email');
$user->level = $request->input('level');
$user->password = $pw;
$user->save();
}
return redirect('admin/users');
}
}