3

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;
    }
5
  • You can override and customize any method in the ResetPasswordController, do you have a problem with something specific? Commented May 30, 2018 at 11:00
  • @TheFallen Which method should I override? Commented May 30, 2018 at 11:02
  • Try with credentials() but if it doesn't work you need to dig into the trait and test with the password broker. Commented May 30, 2018 at 11:05
  • Are you using any MongoDB package for laravel e.g. jenssegers/laravel-mongodb Commented Jun 20, 2018 at 6:47
  • 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. Commented Jun 21, 2018 at 5:41

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.