public function postChangePassword(ChangePasswordRequest $request) { if (Auth::check()) { $user = Auth::user(); // Get passwords from the user's input $old_password = $request->input('password_old'); $password = $request->input('password'); // test input password against the existing one if (Hash::check($old_password, $user->getAuthPassword())) { $user->password = $password; // save the new password if ($user->save()) { return redirect('user/profile')->withErrors(['password' => 'Ваш пароль успешно изменен']); } } else { return redirect($this->changePasswordPath())->withErrors(['password' => 'Вы ввели неверный старый пароль']); } // if ($this->auth->attempt([ // 'email' =>$user->email, // 'password' =>$request->input('password_old') // ])) { // // $hash= Hash::make($request->input('password')); // // $user->password =$hash; // // $user->save(); // // $this->auth->login($user); // // return view('user.profile',['password_was_changed'=>'Пароль бых изменен'])->withUser($user); // // } else return redirect($this->changePasswordPath()) // ->withErrors([ // 'password'=> 'Вы ввели неверный старый пароль' // ]); } else { return redirect($this->changePasswordPath())->withErrors(['password' => 'Пользователь не авторизован']); } }
/** * @param Requests\ChangePasswordRequest $request * @return \Illuminate\Http\JsonResponse */ public function postChangePassword(Requests\ChangePasswordRequest $request) { $user_id = $request->input('user_id'); $user = User::find($user_id); $change = User::find($request->input('id')); if ($user && $user->access < 5) { return response()->json(['notPermission' => true, 'message' => $user->first_name . ' não possui permissão!']); } if ($user->access < $change->access) { return response()->json(['notPermission' => true, 'message' => 'Sua permissão e menor do que deseja alterar!']); } $change->password = bcrypt($request->input('password')); if ($change->save()) { return response()->json(['status' => true]); } return response()->json(['status' => false]); }