gpt4 book ai didi

php - Laravel 在电子邮件确认 View 不起作用后立即更改密码

转载 作者:行者123 更新时间:2023-11-29 12:08:49 25 4
gpt4 key购买 nike

创建用户时,将创建一个随 secret 码(和授权码)并通过电子邮件发送给用户。

当点击电子邮件中的链接时,用户状态将为 1(如此活跃),并且用户将能够立即更改其密码。

现在它不能按我想要的方式工作。

用户 Controller :

public function store(CreateUserRequest $request, User $user, Attribute $attribute)
// some unnecessary code

if ((Input::get('usertype_id')) > 1) {
$randomPassword = str_random(8);
$user->password = Hash::make($randomPassword);

$authentication_code = str_random(12);
$user->authentication_code = $authentication_code;

$user->active = 0;
};

$user->save();

if ((Input::get('usertype_id')) > 1) {
// Email sturen met verficatie code
$email = Input::get('email');

Mail::send('emails.user', ['user' => $user, 'password' => $randomPassword, 'authentication_code' => $authentication_code], function ($message) use ($email) {
$message->to($email, 'Lilopel')->subject('Lilopel: Verify your account!');
});
};


public function confirmUser($authentication_code)
{
if (!$authentication_code)
{
return 'auth code not found!';
}

$user = User::where('authentication_code', '=', $authentication_code)->first();

if (!$user)
{
return 'user not found!';
}

$user->active = 1;
$user->save();

Session::put('user_id', $user->id);

return view('user.setpassword', ['user' => $user]);
//return redirect()->route('user.setPassword', [$user_id]);
}


public function setPassword(SetPasswordRequest $request)
{
$user_id = Session::get('user_id');


$user = $this->user->find($user_id);

$user->fill($request->only('password'));

$user->save();
}

路线:

Route::get('user/verify/{authenticationCode}', 'UserController@confirmUser');

Route::get('user/password', 'UserController@setPassword');

查看:

{!! Form::model($user, ["route"=>['user.setPassword', $user->id] , "method" => 'PATCH']) !!}

<div class="form-group {{ $errors->has('password') ? 'has-error' : '' }}">
{!! Form::label('password', trans('common.password'), ['class' => 'form-label col-sm-3 control-label
text-capitalize']) !!}
<div class="col-sm-6">
{!! Form::password('password', ['name' => 'password', "class"=>"form-control","placeholder" =>
trans('common.password') ]) !!}
{!! $errors->first('password', '<span class="help-block">:message</span>') !!}
</div>
</div>
<div class="form-group {{ $errors->has('confirm_password') ? 'has-error' : '' }}">
{!! Form::label('password_confirmation', trans('common.confirmpassword'), ['class' => 'form-label
col-sm-3 control-label text-capitalize']) !!}
<div class="col-sm-6">
{!! Form::password('password_confirmation', ['name' => 'password_confirmation',
"class"=>"form-control","placeholder" => trans('common.confirmpassword') ]) !!}
{!! $errors->first('password_confirmation', '<span class="help-block">:message</span>') !!}
</div>
</div>

{!! Form::submit( trans('common.edit'), ["class"=>"btn btn-primary text-capitalize center-block "]) !!}

{!! Form::close() !!}

电子邮件链接有效,用户的状态变为事件状态,但 .blade 将给出未定义的Route [user.setPassword]。 (查看:public_html/server2/resources/views/user/setpassword.blade.php)错误。

最佳答案

协同工作要像您一样使用路线,您需要 named route .

改变这个

Route::get('user/password', 'UserController@setPassword');

到此

Route::get('user/password', [
'as' => 'user.setPassword',
'uses' => 'UserController@showProfile'
]);

此外,请确保路由的 HTTP 谓词与表单的方法协同工作。

关于php - Laravel 在电子邮件确认 View 不起作用后立即更改密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31048660/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com