Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function resetPassword($id)
- {
- $user = User::find($id);
- // generate 8 character randomly
- $randomPassword = str_random(8);
- // change user's password with the newly generated 8 char
- $user->password = bcrypt($randomPassword);
- // send email to user
- $data['new_password'] = $randomPassword;
- $data['name'] = $user->name;
- $data['email'] = $user->email;
- Mail::send('emails.reset_password', $data, function($message) use ($data)
- {
- $message->from('admin@igaleri.perkeso.com.my', "Admin iGaleri");
- $message->subject("Password Baru Ditetapkan Semula - iGaleri");
- $message->to($data['email']);
- });
- try {
- $user->save();
- 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.");
- } catch (\Exception $e) {
- return back()->withInput()->with('errorMessage', 'Unable to reset password.');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement