laravel-multiauth
laravel-multiauth copied to clipboard
Password Reset not working for second type
Hi, I have used your package for multi auth and it is working well so far for login. But now I am working on reset password and it isn't working. I mean when I go to reset password link received in email and submit form it returns to same page with no notification and password isn't reset. Even on this form if I give some wrong credentials, proper error message is shown.
Here is my code auth.php
<?php
return [
/*
|--------------------------------------------------------------------------
| Authentication Defaults
|--------------------------------------------------------------------------
|
| This option controls the default authentication "guard" and password
| reset options for your application. You may change these defaults
| as required, but they're a perfect start for most applications.
|
*/
'defaults' => [
'guard' => 'user',
'passwords' => 'users',
],
/*
|--------------------------------------------------------------------------
| Authentication Guards
|--------------------------------------------------------------------------
|
| Next, you may define every authentication guard for your application.
| Of course, a great default configuration has been defined for you
| here which uses session storage and the Eloquent user provider.
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| Supported: "session", "token"
|
*/
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'user' => [
'driver' => 'session',
'provider' => 'users'
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
'dealer' => [
'driver' => 'session',
'provider' => 'dealers',
]
],
/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| If you have multiple user tables or models you may configure multiple
| sources which represent each model / table. These sources may then
| be assigned to any extra authentication guards you have defined.
|
| Supported: "database", "eloquent"
|
*/
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'dealers' => [
'driver' => 'eloquent',
'model' => App\Models\Dealer::class,
]
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
/*
|--------------------------------------------------------------------------
| Resetting Passwords
|--------------------------------------------------------------------------
|
| Here you may set the options for resetting passwords including the view
| that is your password reset e-mail. You may also set the name of the
| table that maintains all of the reset tokens for your application.
|
| You may specify multiple password reset configurations if you have more
| than one user table or model in the application and you want to have
| separate password reset settings based on the specific user types.
|
| The expire time is the number of minutes that the reset token should be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/
'passwords' => [
'users' => [
'provider' => 'users',
'email' => 'auth.emails.password',
'table' => 'password_resets',
'expire' => 60,
],
'dealers' => [
'provider' => 'dealers',
'email' => 'dealer.auth.emails.password',
'table' => 'password_resets',
'expire' => 60,
],
],
];
PasswordController
<?php
namespace App\Http\Controllers\DealerAuth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
use Illuminate\Http\Request;
use Password;
use Message;
class PasswordController extends Controller
{
protected $guard = 'dealer'; //For guard
protected $broker = 'dealers';
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset requests
| and uses a simple trait to include this behavior. You're free to
| explore this trait and override any methods you wish to tweak.
|
*/
use ResetsPasswords;
/**
* Create a new password controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
public function getEmail()
{
return $this->showLinkRequestForm();
}
public function showLinkRequestForm()
{
if (property_exists($this, 'linkRequestView')) {
return view($this->linkRequestView);
}
if (view()->exists('dealer_cms.auth.passwords.email')) {
return view('dealer_cms.auth.passwords.email');
}
return view('dealer_cms.auth.password');
}
public function showResetForm(Request $request, $token = null)
{
if (is_null($token)) {
return $this->getEmail();
}
$email = $request->input('email');
if (property_exists($this, 'resetView')) {
return view($this->resetView)->with(compact('token', 'email'));
}
if (view()->exists('dealer_cms.auth.passwords.reset')) {
return view('dealer_cms.auth.passwords.reset')->with(compact('token', 'email'));
}
return view('dealer_cms.passwords.auth.reset')->with(compact('token', 'email'));
}
public function postEmail(Request $request)
{
$this->validate($request, ['email' => 'required|email']);
$response = Password::sendResetLink($request->only('email'), function ($message) {
$message->subject($this->getEmailSubject());
$message->from('[email protected]',"abc Password Reset");
});
switch ($response) {
case Password::RESET_LINK_SENT:
return redirect()->back()->with('status', trans($response));
case Password::INVALID_USER:
return redirect()->back()->withErrors(['email' => trans($response)]);
}
}
}
And I use authtenticable in my dealers model
/**
* @file Dealer.php
* @Package: App/Models
* @author: Awais Qarni
*/
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\User as Authenticatable;
class Dealer extends Authenticatable {}
routes.php
Route::post('dealer/password/email','DealerAuth\PasswordController@postEmail');
Route::post('dealer/password/reset','DealerAuth\PasswordController@reset');
Route::get('dealer/password/reset/{token?}','DealerAuth\PasswordController@showResetForm');
Can you please look into as it is very urgent matter for me to work on
@mirzaawais everything seems fine in your code. did you solve this issue ? if not can you show me your view dealer_cms.passwords.auth.reset.blade.php
?