PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/app/Http/Controllers/ForgotPasswordController.php

https://bitbucket.org/coredeveloper2013/navipi-test
PHP | 113 lines | 80 code | 14 blank | 19 comment | 7 complexity | 1338c3a1efc4f4a8a3038cd7a3dd648c MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\User;
  5. use App\Country;
  6. use App\City;
  7. use App\Http\Requests;
  8. use App\Http\Controllers\Controller;
  9. use Mail;
  10. class ForgotPasswordController extends Controller
  11. {
  12. public function __construct()
  13. {
  14. $this->general_settings = app('settings');
  15. }
  16. public function forgetPassword()
  17. {
  18. $countries = Country::All();
  19. return view('user.forgot_password')->with('general_settings', $this->general_settings)->with('countries',$countries);
  20. }
  21. public function forgotPasswordProcess(Request $request)
  22. {
  23. $input_data=$request->all();
  24. $this->validate($request, [
  25. 'email' => 'required',
  26. ]);
  27. $user = User::where('email',$input_data['email'])->first();
  28. //print_r($user);echo count($user);exit;
  29. //Click here to reset your password: {{ url('password/reset/'.$token) }}
  30. if(count($user))
  31. {
  32. $enc_user = base64_encode($user->id.'####'.$user->email);
  33. $reset_pass_link = url('reset-password/'.$enc_user);
  34. $mailcontent = "Click here to reset your password: ".$reset_pass_link." ";
  35. $to=$input_data['email'];
  36. //dd($this->general_settings);
  37. // $headers ="From: ".$this->general_settings->SiteTitle." Admin <".$this->general_settings->Contact_Email.">\n";
  38. // $headers .= "MIME-Version: 1.0\n";
  39. // $headers .= "Content-type: text/html; charset=UTF-8\n";
  40. // $subject = $this->general_settings->SiteTitle.' Forget Password';
  41. // $message ="<html><head></head><body>"."<style type=\"text/css\">
  42. // <!--
  43. // .style4 {font-size: x-small}
  44. // -->
  45. // </style>
  46. // ".$mailcontent."
  47. // </body></html>";
  48. //
  49. // mail($to,$subject,$message,$headers);
  50. $data = [
  51. 'user' => $user,
  52. 'mailcontent' => $mailcontent,
  53. ];
  54. Mail::send('emails.forgot-password', $data, function ($message) use ($user,$input_data) {
  55. $message->from($this->general_settings->contact_email, $this->general_settings->site_title);
  56. $message->to($input_data['email'], $user->name)->subject('Forgot Password - '.$this->general_settings->site_title);
  57. $message->replyTo($this->general_settings->contact_email, $this->general_settings->contact_name);
  58. });
  59. return redirect(url('forget-password'))->with('forget_pass_success', 'Reset password link send successful!!');
  60. }
  61. else return redirect(url('forget-password'))->with('error_msg', 'User credentials not found.');
  62. }
  63. public function resetPassword($token = '')
  64. {
  65. $countries = Country::All();
  66. return view('user.reset_password')->with('general_settings', $this->general_settings)->with('token', $token)->with('countries',$countries);
  67. }
  68. public function resetPassProcess(Request $request)
  69. {
  70. $input_data=$request->all();
  71. //dd($input_data);
  72. $this->validate($request, [
  73. 'password' => 'required',
  74. 'password_confirmation' => 'required|same:password',
  75. ]);
  76. if(!$input_data['token'])
  77. {
  78. return redirect(url('reset-password/'.$input_data['token']))->with('error_msg', 'Invalid token error.');
  79. }
  80. if($input_data['password'] != $input_data['password_confirmation'])
  81. {
  82. return redirect(url('reset-password/'.$input_data['token']))->with('error_msg', 'Password confirmation password does not matched.');
  83. }
  84. $info_user = base64_decode($input_data['token']);
  85. $info_user_arr = explode('####',$info_user);
  86. $user_id = $info_user_arr[0];
  87. $update=0;
  88. $user = User::find($user_id);
  89. //print_r($user);exit;
  90. if(count($user)>0){
  91. $user->password = password_hash($input_data['password'], PASSWORD_DEFAULT);
  92. $update=$user->save();
  93. //
  94. }
  95. if($update==1){
  96. return redirect(url('reset-password'))->with('reset_pass_success', 'Password successfully changed!');
  97. }
  98. }
  99. }