我在 laravel 4 中的 UserController 中发送密码请求的某个函数存在问题。它检查数据库中是否存在电子邮件,然后如果用户存在则发送电子邮件。然后,该函数在表中创建一个令牌,并将其发送到电子邮件中链接的末尾。
该函数的工作原理与在数据库中创建令牌一样,但它似乎有问题,因为我不断收到Maximum execution time
错误消息。我不知道是什么原因造成的,它似乎与重定向有关。有人可以帮帮我吗?提前致谢!
这是控制器功能:
public function passwordRequest()
{
$data = [
"requested"=>Input::old("requested")
];
if(Input::server("REQUEST_METHOD") == "POST") {
$input = Input::all();
$rules = [
"email" => "required|exists:users,email"
];
$v = Validator::make($input, $rules);
if($v->passes()) {
$credentials = [
"email" => Input::get("email"),
];
Password::remind($credentials, function($message, $user) {
$message->from("request@test.com");
});
$data["requested"] = true;
return Redirect::route("user/request")->with($data);
}
return Redirect::to(URL::route("user/request"))->withInput($data)->withErrors($v);
}
return View::make("user/request", $data);
}
这是 routes.php 文件:
Route::group(["before"=>"guest"], function() {
Route::any("/", [
"as"=>"user/login",
"uses"=>"UserController@userLogin"
]);
Route::any("/request", [
"as"=>"user/request",
"uses"=>"UserController@passwordRequest"
]);
Route::any("/reset", [
"as"=>"user/reset",
"uses"=>"UserController@passwordReset"
]);
Route::any("/register", [
"as" => "user/register",
"uses" => "UserController@userRegister"
]);
})
;
如果需要,这是视图:
@extends("layouts.master")
@section("content")
<h1>Request Password Reset</h1>
{{ Form::open([
"route"=>"user/request",
"autocomplete"=>"off"
]) }}
@if(isset($errors))
@foreach ($errors->all() as $error)
<div class="error">
<li>{{ $error }}</li>
</div>
@endforeach
@endif
@if(Session::has("requested"))
<div class="success">
<li>An email has been sent with your password reset request.</li>
</div>
{{ Session::forget('requested') }}
@endif
<br />
{{ Form::label("email", "Email:") }}
{{ Form::text("email", Input::old("email"), [
"placeholder"=>"Email Address"
]) }}
{{ Form::submit("Reset") }}
{{ Form::close() }}
<br />
{{ HTML::linkRoute("user/login", "Return to Login") }}
@stop