ollieread / multiauth

Laravel multi auth
441 stars 109 forks source link

Argument 1 passed to Ollieread\Multiauth\Reminders\PasswordBrokerManager::__construct() must be an instance of Ollieread\Multiauth\Reminders\ReminderRepositoryInterface, instance of Illuminate\Auth\Reminders\DatabaseReminderRepository given #106

Closed mh-jamil closed 9 years ago

mh-jamil commented 9 years ago

Hello,

I'm trying to integrate multiauth for my L-4.2 project for first time. Everything seems to work fine but the reminders aren't working. When I enter the email address in password/remind page and submit, it gives me an error:

 Argument 1 passed to Ollieread\Multiauth\Reminders\PasswordBrokerManager::__construct() must be an instance of Ollieread\Multiauth\Reminders\ReminderRepositoryInterface, instance of Illuminate\Auth\Reminders\DatabaseReminderRepository given, called in D:\....\vendor\ollieread\multiauth\src\Ollieread\Multiauth\Reminders\ReminderServiceProvider.php on line 59 and defined 

You can view complete error details here:

error

My Admin Controller:

use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;

class Admin extends Eloquent implements UserInterface, RemindableInterface {

    use UserTrait, RemindableTrait;

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'admins';

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = array('password', 'remember_token');

    // fillable array
    protected $fillable = array('name', 'email', 'password');

    // validation rules
    public static $rules = array(
        'name'                      => 'required|min:2', // alpha = only alphabets
        'email'                     => 'required|email|unique:admins', // unique in admins table
        'password'                  => 'required|between:8,20|confirmed',
        'password_confirmation'     => 'required|between:8,20'
    );
}

AdminRemindersController

class AdminRemindersController extends Controller {

    /**
     * Display the password reminder view.
     *
     * @return Response
     */
    public function getRemind()
    {
        return View::make('admin.password.remind');
    }

    /**
     * Handle a POST request to remind a user of their password.
     *
     * @return Response
     */
    public function postRemind()
    {
        $response = Password::admin()->remind(Input::only('email'), function($message)
        {
            $message->subject('Password Reminder');
        });

        switch ($response)
        {
            case Password::INVALID_USER:
                return Redirect::back()
                    ->with('message', Lang::get($response))
                    ->with('message-type', 'alert-danger');

            case Password::REMINDER_SENT:
                return Redirect::back()
                    ->with('message', Lang::get($response))
                    ->with('message-type', 'alert-success');
        }
    }

    /**
     * Display the password reset view for the given token.
     *
     * @param  string  $token
     * @return Response
     */
    public function getReset($token = null)
    {
        if (is_null($token)) App::abort(404);

        return View::make('admin.password.reset')->with('token', $token);
    }

    /**
     * Handle a POST request to reset a user's password.
     *
     * @return Response
     */
    public function postReset()
    {
        $credentials = Input::only(
            'email', 'password', 'password_confirmation', 'token'
        );

        $response = Password::admin()->reset($credentials, function($user, $password)
        {
            $user->password = Hash::make($password);

            $user->save();
        });

        switch ($response)
        {
            case Password::INVALID_PASSWORD:
            case Password::INVALID_TOKEN:
            case Password::INVALID_USER:
                return Redirect::back()->with('error', Lang::get($response));

            case Password::PASSWORD_RESET:
                return Redirect::to('admin.login')
                            ->with('message', 'Password changed successfully.')
                            ->with('message-type', 'alert-success');
        }
    }

}

Please help.

mh-jamil commented 9 years ago

Any help? I'm stuck with this and can't seem to resolve this issue.. :(

ollieread commented 9 years ago

Which version of multiauth are you using?

mh-jamil commented 9 years ago

I'm using Laravel 4.2 and I have required "ollieread/multiauth": "dev-master" in my composer.json file

ollieread commented 9 years ago

Have you replaced the default service provider with the one for this package? Not just the auth, but the reminders one too?

mh-jamil commented 9 years ago

Following is my providers array:

'providers' => array(

    'Illuminate\Foundation\Providers\ArtisanServiceProvider',
    'Illuminate\Cache\CacheServiceProvider',
    'Illuminate\Session\CommandsServiceProvider',
    'Illuminate\Foundation\Providers\ConsoleSupportServiceProvider',
    'Illuminate\Routing\ControllerServiceProvider',
    'Illuminate\Cookie\CookieServiceProvider',
    'Illuminate\Database\DatabaseServiceProvider',
    'Illuminate\Encryption\EncryptionServiceProvider',
    'Illuminate\Filesystem\FilesystemServiceProvider',
    'Illuminate\Hashing\HashServiceProvider',
    'Illuminate\Html\HtmlServiceProvider',
    'Illuminate\Log\LogServiceProvider',
    'Illuminate\Mail\MailServiceProvider',
    'Illuminate\Database\MigrationServiceProvider',
    'Illuminate\Pagination\PaginationServiceProvider',
    'Illuminate\Queue\QueueServiceProvider',
    'Illuminate\Redis\RedisServiceProvider',
    'Illuminate\Remote\RemoteServiceProvider',
    'Illuminate\Auth\Reminders\ReminderServiceProvider',
    'Illuminate\Database\SeedServiceProvider',
    'Illuminate\Session\SessionServiceProvider',
    'Illuminate\Translation\TranslationServiceProvider',
    'Illuminate\Validation\ValidationServiceProvider',
    'Illuminate\View\ViewServiceProvider',
    'Illuminate\Workbench\WorkbenchServiceProvider',
    'Way\Generators\GeneratorsServiceProvider',
    'Barryvdh\Elfinder\ElfinderServiceProvider',
    'Laravel\Cashier\CashierServiceProvider',
    'Ollieread\Multiauth\MultiauthServiceProvider',
    'Ollieread\Multiauth\Reminders\ReminderServiceProvider'

)
ollieread commented 9 years ago

You've left the default one in there, you need to replace Illuminate\Auth\Reminders\ReminderServiceProvider, or in this case, completely remove it as you already have mine.

mh-jamil commented 9 years ago

Ok, I've just removed this default provider and now reminders seems to work fine:

'Illuminate\Auth\Reminders\ReminderServiceProvider',

Thanks for the help.

ollieread commented 9 years ago

You'd be surprised how often that's the cause of the problem. There is actually something in the readme/documentation:

NOTE It is very important that you replace the default service providers. If you do 
not wish to use Reminders, then remove the original Reminder server provider as 
it will cause errors.

People often just append rather than replace.

mh-jamil commented 9 years ago

Hi,

I have run into another issue. I have two user types, 'admin' and 'user'. The password reminders are working perfectly fine for admins and I'm able to reset passwords, but for users the reminder email is send, but on reset page it always give the error "This password reset token is invalid."

Any clue? If there is anything wrong in following the documentation then admin reminders shouldn't work. I'm having this issue with only users type.

ollieread commented 9 years ago

That sounds like an issue with your implementing code.

shahbaz-gaxon commented 8 years ago

Argument 1 passed to Ollieread\Multiauth\Reminders\PasswordBroker::remind() must be of the type array, string given, called in D:\laravel\cmr\app\controllers\backend\AdminController.php on line 87 and defined

Please suggest me solution.