パスワードリセット

このコミットが含まれているのは:
守矢諏訪子 2021-11-11 18:49:02 +09:00
コミット 52255803b7
8個のファイルの変更55行の追加16行の削除

ファイルの表示

@ -2,7 +2,7 @@ APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
APP_URL=http://127.0.0.1
LOG_CHANNEL=stack
LOG_LEVEL=debug

ファイルの表示

@ -13,6 +13,7 @@ use Illuminate\Support\Facades\Storage;
use App\Models\Father;
use App\Models\FatherRelation;
use App\Models\EmailActivation;
use App\Mail\FathersForgetPasswordMail;
use App\Mail\FathersRegistrationTemporaryMail;
use App\Mail\FathersRegistrationMainMail;
@ -38,7 +39,7 @@ class FathersController extends Controller {
return ['status_code' => 422, 'error_messages' => $validate->errors()];
}
if ($result = Father::select('id')->where('email', $r->email)->first()) {
if (null === ($result = Father::select('id')->where('email', $r->email)->first())) {
// メールアドレス照合に失敗
return ['status_code' => 400, 'error_messages' => ['メールアドレスが未登録です。入力した情報を確認してください。']];
}
@ -57,7 +58,7 @@ class FathersController extends Controller {
EmailActivation::create($create);
// メールを送ります。
Mail::to($r->email)->send(new FathersRegistrationTemporaryMail($token));
Mail::to($r->email)->send(new FathersForgetPasswordMail($token));
} catch (\Throwable $e) {
// 失敗
Log::critical($e->getMessage());
@ -400,17 +401,17 @@ class FathersController extends Controller {
$father_id = $r->father_id;
}
else if (isset($r->token)) {
if (null === ($ea = EmailActivation::select('father_id')->where('token', $r->token)->first())) {
return ['status_code' => 400, 'error_messages' => ['パスワードの更新に失敗しました。']];
}
$father_id = (int)$ea->father_id;
}
if (is_null($father_id) && !isset($r->token)) {
return ['status_code' => 400, 'error_messages' => ['パスワードの更新に失敗しました。']];
}
// if (isset($r->token)) {
// if (null === ($father_id = EmailActivation::select('father_id')->where('token', $r->token)->first())) {
// return ['status_code' => 400, 'error_messages' => ['パスワードの更新に失敗しました。']];
// }
// $father_id = (int)$father_id->father_id;
// }
// バリデーションエラー
$validate = Validator::make($r->all(), [
'password' => 'required|min:8|max:72|confirmed',
@ -426,6 +427,10 @@ class FathersController extends Controller {
try {
Father::where('id', (int)$father_id)->update($update);
if (isset($r->token)) {
EmailActivation::where('token', $r->token)->delete();
}
} catch (\Throwable $e) {
// 失敗
Log::critical($e->getMessage());

ファイルの表示

@ -0,0 +1,23 @@
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class FathersForgetPasswordMail extends Mailable {
use Queueable, SerializesModels;
private $token;
public function __construct ($token) {
$this->token = $token;
}
public function build () {
return $this->subject('パスワードリセットを依頼しました。')->markdown('emails.fathers.forgotpassword', [
'token' => $this->token
]);
}
}

ファイルの表示

@ -8,6 +8,6 @@ use Illuminate\Database\Eloquent\Model;
class EmailActivation extends Model
{
use HasFactory;
protected $fillable = ['email', 'token', 'ttl'];
protected $fillable = ['type', 'father_id', 'email', 'token', 'ttl'];
protected $attributes = ['type' => 0];
}

ファイルの表示

@ -52,7 +52,7 @@ return [
|
*/
'url' => env('APP_URL', 'http://localhost'),
'url' => env('APP_URL', 'http://127.0.0.1'),
'asset_url' => env('ASSET_URL', null),

ファイルの表示

@ -0,0 +1,11 @@
@component('mail::message')
# パスワードリセットを依頼しました。
サイトへのパスワードリセットを依頼しました。
以下のリンクからパスワードを再設定してください。
@component('mail::button', ['url' => url('/').'/p-account/forgot-password/reset/'.$token])
{{ url('/') }}/p-account/forgot-password/reset/{{ $token }}
@endcomponent
@endcomponent

ファイルの表示

@ -5,7 +5,7 @@
以下のリンクからログインしてくださいませ。
@component('mail::button', ['url' => env('APP_URL').'/p-account/login'])
{{ env('APP_URL') }}/p-account/login
@component('mail::button', ['url' => url('/').'/p-account/login'])
{{ url('/') }}/p-account/login
@endcomponent
@endcomponent

ファイルの表示

@ -5,7 +5,7 @@
以下のリンクからログインして、本登録を完了させてください。
@component('mail::button', ['url' => env('APP_URL').'/p-account/register/'.$token])
{{ env('APP_URL') }}/p-account/register/{{ $token }}
@component('mail::button', ['url' => url('/').'/p-account/register/'.$token])
{{ url('/') }}/p-account/register/{{ $token }}
@endcomponent
@endcomponent