Я пытаюсь добиться того, чтобы при создании пользователя он получал письмо с ссылкой, действительное только в течение 6 часов. Этого недостаточно, и в большинстве случаев мы должны вручную установить пароль для пользователя.
У пользователя должно быть 3 дня для создания его первого пароля.
Однако, когда пользовательнажимает на забытый пароль, 6-часового лимита достаточно (потому что это то, что он делает сознательно).
Вот что у меня есть до сих пор!
Функция нашего магазина в UsersController выглядит следующим образом:
public function store(StoreUser $request)
{
...
\DB::transaction(function () use ($request, $data) {
$roles = $request->input('roles');
$isInternal = $request->input('is_internal');
$customers = $request->input('customers', []);
/** @var User $user */
$user = $this->userRepository->create($data);
$user->assignRole($roles);
if ($isInternal == false && !empty($customers)) {
$user->customers()->sync($customers);
}
$token = app(PasswordBroker::class)->createToken($user);
$user->notify(new AccountActivationNotification($token));
});
return $this->respond()->success([], "User successfully created.");
}
Наши сброс и забыли функции:
public function reset(Request $request)
{
$request->validate([
'token' => 'required',
'email' => 'required|email',
'password' => 'required|confirmed|min:6',
]);
$credentials = $request->only('email', 'password', 'password_confirmation', 'token');
// Here we will attempt to reset the user's password. If it is successful we
// will update the password on an actual user model and persist it to the
// database. Otherwise we will parse the error and return the response.
$response = $this->passwordBroker->reset(
$credentials,
function ($user, $password) {
$user->password = $password;
$user->status = StatusesService::STATUS_ACTIVE;
$user->email_verified_at = now();
$user->save();
event(new PasswordReset($user));
}
);
return $response == $this->passwordBroker::PASSWORD_RESET
? $this->respond()->success()
: $this->respond()->validationFailed(trans($response));
}
public function forgot(Request $request)
{
$request->validate([
'email' => 'required|email',
]);
// We will send the password reset link to this user. Once we have attempted
// to send the link, we will examine the response then see the message we
// need to show to the user. Finally, we'll send out a proper response.
$response = $this->passwordBroker->sendResetLink(
$request->only('email')
);
return $response == $this->passwordBroker::RESET_LINK_SENT
? $this->respond()->success([], "Your password has been reset, please check your inbox.")
: $this->respond()->validationFailed(trans($response));
}
Мы уже установили две разныеконфигурации в config / auth.php:
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 4320, //3 days
],
'users_fpassword' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 1440, //6 hours
],
],
Что мы можем сделать, чтобы динамически переключаться между конфигурациями, которые мы имеем в config/auth.php
, в соответствии с ситуацией, описанной в начале сообщения?