Advertisement
Guest User

Untitled

a guest
Oct 5th, 2018
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. public function resetPassword($id)
  2. {
  3. $user = User::find($id);
  4. // generate 8 character randomly
  5. $randomPassword = str_random(8);
  6. // change user's password with the newly generated 8 char
  7. $user->password = bcrypt($randomPassword);
  8.  
  9. // send email to user
  10. $data['new_password'] = $randomPassword;
  11. $data['name'] = $user->name;
  12. $data['email'] = $user->email;
  13.  
  14. Mail::send('emails.reset_password', $data, function($message) use ($data)
  15. {
  16. $message->from('admin@igaleri.perkeso.com.my', "Admin iGaleri");
  17. $message->subject("Password Baru Ditetapkan Semula - iGaleri");
  18. $message->to($data['email']);
  19. });
  20.  
  21. try {
  22. $user->save();
  23. return Redirect::to('home')->with('successMessage', "$user->name's password has been reset and sent to $user->email. The email may takes as long as 5 minutes to arrive.");
  24. } catch (\Exception $e) {
  25. return back()->withInput()->with('errorMessage', 'Unable to reset password.');
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement