vendredi 25 septembre 2020

Laravel Reset Password - non unique email with additional condition

I am wrecking my brain over this. So I have non unique emails because we have different events that registers guests and one guest can register to more than one event with same email. Registeration isnt hard the problem is with forget password. I have added a new column in password_reset table with name event_id. I overrided the default sendResetLinkEmail with the following code. So that lets me update the event id with the token that is stored. what it looks like

    /**
     * Send a reset link to the given user.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
     */
    public function sendResetLinkEmail(Request $request)
    {
        $this->validateEmail($request);
        $event_id = Event::where('event_url',session('slug'))->first()->id;
        $userData = $this->credentials($request);
        $userData['event_id'] = $event_id;
        // We will send the password reset link to this user. Once we have attempted
        // to send the link, we will examine the response then see the message we
        // need to show to the user. Finally, we'll send out a proper response.
        $response = $this->broker()->sendResetLink(
            $userData
        );
        
        DB::table('guest_password_resets')->where('email', $request->email)->update(['event_id' => $event_id]);
        return $response == Password::RESET_LINK_SENT
                    ? $this->sendResetLinkResponse($request, $response)
                    : $this->sendResetLinkFailedResponse($request, $response);
    }

The problem is, if I want to reset password of event A and not the event B whose token is also present in password_reset, it will replace the token and update the event_id of the event B rather than create a new token for the event A for the same email.

All I want it to do is create new entries based on event_id and not email. Is there any custom way for this?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3j56xqn
via IFTTT

Aucun commentaire:

Enregistrer un commentaire