Advertisement
Guest User

Untitled

a guest
Feb 8th, 2018
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.42 KB | None | 0 0
  1.     public function register(Request $request)
  2.     {
  3.         $temp_password = str_random(20);
  4.         $request->request->add(['password' => $temp_password]);
  5.         $this->validator($request->all())->validate();
  6.         event(new Registered($user = $this->create($request->all())));
  7.  
  8.         $key = env('APP_KEY');
  9.  
  10.         if (Str::startsWith($key, 'base64:')) {
  11.             $key = base64_decode(substr($key, 7));
  12.         }
  13.  
  14.         $reset_token = hash_hmac('sha256', Str::random(40), $key);
  15.         DB::table('password_resets')->insert([
  16.            'email' => $request->email,
  17.             'token' => Hash::make($reset_token),
  18.             'created_at' => Carbon::now(),
  19.         ]);
  20.         return $this->registered($request, $user)
  21.             ?: redirect($this->redirectPath());
  22.     }
  23.  
  24.     protected function registered(Request $request, $user) {
  25.         $user->notify(new UserRegisteredNotification($user));
  26.     }
  27.    
  28. In UserRegisteredNotification:
  29. public function toMail($notifiable) {
  30.         $pw_reset = DB::table('password_resets')->where('email', $this->user->email)->first();
  31.         return (new MailMessage)
  32.             ...
  33.             ->action('Reset Password', url(config('app.url').route('password.reset', $pw_reset->token, false)))
  34.             ...
  35.     }
  36.  
  37. In the password reset e-mail, it has the hashed token and so the link doesn't work.
  38.  
  39. How do I get the pre-hashed token to the Notification class?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement