3
votes

I am migrating old project (done in zend framework) to laravel 5.5. Database is mongo db. I am using laravel-mongodb to connect laravel and mongo.

I already override laravel login functionality because table fields are not same as default laravel fields. Login is working fine.

At present when I try to reset password I am getting error message "We can't find a user with that e-mail address". How can I override reset password functionality?

In user table the field name are usrEmail and usrPassword. Working code of login is given below.

At present when I try to reset password I am getting error message We can't find a user with that e-mail address. How can I override reset password functionality?

In user table the field name are usrEmail and usrPassword. Working code of login is given below.

LoginController.php

protected function attemptLogin(Request $request)
    {
        $authUser     = User::where('usrEmail', $request->email)
            ->whereIn('usrlId', [1, 2, 5, 6])
            ->first();

        if($authUser) {
            $password = md5(env('MD5_Key'). $request->password. $authUser->usrPasswordSalt);
            $user     = User::where('usrEmail', $request->email)
                ->where('usrPassword', $password)
                ->where('usrActive', '1')
                ->where('usrEmailConfirmed', '1')
                ->where('is_delete', 0)
                ->where('usrlId', 2)
                ->first();

            if ($user) {
                $updateLoginTime            = User::find($user->_id);
                $updateLoginTime->lastlogin = date('Y-m-d H:i:s');
                $updateLoginTime->save();

                $this->guard()->login($user, $request->has('remember'));
                return true;
            }
            else {
                return false;
            }
        }

        return false;
    }
1
You can override and customize any method in the ResetPasswordController, do you have a problem with something specific?thefallen
@TheFallen Which method should I override?Sarath TS
Try with credentials() but if it doesn't work you need to dig into the trait and test with the password broker.thefallen
Are you using any MongoDB package for laravel e.g. jenssegers/laravel-mongodbAmmar Ali
Personally, I had this issue but I after implementing of MongoDB I choose another direction. Authentication is very important so you should use Laravel Authentication with Mysql for login and stuff. (you will not lose Laravel features and updates) and if your user authenticated then use MongoDB instead for NoSQL and data storing.Payam Khaninejad

1 Answers

0
votes

Try placing this in your Auth/ResetsPasswordController.php

protected function credentials(Request $request)
{
    $data = $request->only(
        'password', 'password_confirmation', 'token'
    );

    $data['usrEmail'] = $request->get('email');

    return $data;
}

By default the ->only( also includes the email field, but since it is different in your database we needed to override this function, which is by default defined in the ResetsPasswords trait.

This should ensure that any email field in the password reset flow (both on requesting the email and the form once you click the emailed link) will point to the right field in your database.