ResetPasswordController.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace App\Http\Controllers\Admin\Auth;
  3. use App\Http\Controllers\Admin\Controller;
  4. use Illuminate\Foundation\Auth\ResetsPasswords;
  5. use Validator, Auth,Hash;
  6. class ResetPasswordController extends Controller
  7. {
  8. /*
  9. |--------------------------------------------------------------------------
  10. | Password Reset Controller
  11. |--------------------------------------------------------------------------
  12. |
  13. | This controller is responsible for handling password reset requests
  14. | and uses a simple trait to include this behavior. You're free to
  15. | explore this trait and override any methods you wish to tweak.
  16. |
  17. */
  18. use ResetsPasswords;
  19. /**
  20. * Where to redirect users after resetting their password.
  21. *
  22. * @var string
  23. */
  24. protected $redirectTo = '/home';
  25. /**
  26. * Create a new controller instance.
  27. *
  28. * @return void
  29. */
  30. public function __construct()
  31. {
  32. $this->middleware('guest');
  33. }
  34. public function showChangeForm()
  35. {
  36. return view('admin.auth.change');
  37. }
  38. public function changePassword(\Illuminate\Http\Request $request)
  39. {
  40. $validator = Validator::make($data = $request->all(),
  41. [
  42. 'old_passwprd' => 'required', 'password' => 'required','password_confirmation'=> 'required'
  43. ],
  44. [
  45. 'old_passwprd.required'=>'请输入原密码',
  46. 'password.required'=>'请输入密码',
  47. 'password_confirmation.required'=>'请输入确认密码',
  48. ]
  49. );
  50. if ($validator->fails()) {
  51. $msg = $validator->messages()->first();
  52. return $this->showWarning($msg);
  53. }
  54. $user = Auth::guard('admin')->user();
  55. $oldpassword = $request->input('old_passwprd');
  56. $newpassword = $request->input('password');
  57. $password_confirmation= $request->input('password_confirmation');
  58. if($newpassword!=$password_confirmation){
  59. return $this->showWarning("两次密码一直");
  60. }
  61. if(!Hash::check($oldpassword, $user->password)){
  62. return $this->showWarning("原密码不正确");
  63. }
  64. $user->password = bcrypt($newpassword);
  65. $result = $user->save();
  66. if($result){
  67. return $this->showMessage("修改成功");
  68. }else{
  69. return $this->showWarning("修改密码失败");
  70. }
  71. }
  72. }