コミット
85648c5b30
|
@ -7,10 +7,13 @@ use Illuminate\Support\Facades\Validator;
|
|||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
use App\Models\Father;
|
||||
use App\Models\FatherRelation;
|
||||
use App\Models\EmailActivations;
|
||||
use App\Models\EmailActivation;
|
||||
use App\Mail\FathersRegistrationTemporaryMail;
|
||||
use App\Mail\FathersRegistrationMainMail;
|
||||
|
||||
class FathersController extends Controller {
|
||||
use AuthenticationTrait;
|
||||
|
@ -28,7 +31,7 @@ class FathersController extends Controller {
|
|||
|
||||
public function registerTemporary (Request $r) {
|
||||
$validate = Validator::make($r->all(), [
|
||||
'email' => 'required|unique:father|unique:email_activations|max:255|email'
|
||||
'email' => 'required|unique:fathers|unique:email_activations|max:255|email'
|
||||
]);
|
||||
|
||||
if ($validate->fails()) {
|
||||
|
@ -37,24 +40,23 @@ class FathersController extends Controller {
|
|||
}
|
||||
|
||||
if ($get = Father::where('email', $r->email)->first()) {
|
||||
// すでにDBに登録されている場合
|
||||
// すでにfathersに登録されている場合
|
||||
return ['status_code' => 400, 'error_messages' => ['入力したメールアドレスは既に登録済みです。同じメールアドレスは使用できません。']];
|
||||
}
|
||||
else if ($get = EmailActivations::where('email', $r->email)->first()) {
|
||||
// すでにDBに登録されている場合
|
||||
else if ($get = EmailActivation::where('email', $r->email)->first()) {
|
||||
// すでにemail_activationsに登録されている場合
|
||||
return ['status_code' => 400, 'error_messages' => ['入力したメールアドレスは既に登録済みです。同じメールアドレスは使用できません。']];
|
||||
}
|
||||
else {
|
||||
$chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
||||
$token = '';
|
||||
for ($i = 1; $i < 15; $i++) {
|
||||
$token .= $chars[rand(0,35)];
|
||||
}
|
||||
|
||||
$token = bin2hex(random_bytes(16));
|
||||
$create = ['email' => $r->email, 'token' => $token, 'ttl' => date('Y-m-d H:i:s', time()+28800)];
|
||||
|
||||
try {
|
||||
EmailActivations::create($create);
|
||||
// DBに入ります。
|
||||
EmailActivation::create($create);
|
||||
|
||||
// メールを送ります。
|
||||
Mail::to($r->email)->send(new FathersRegistrationTemporaryMail($token));
|
||||
} catch (\Throwable $e) {
|
||||
// 失敗
|
||||
Log::critical($e->getMessage());
|
||||
|
@ -80,25 +82,32 @@ class FathersController extends Controller {
|
|||
return ['status_code' => 422, 'error_messages' => $validate->errors()];
|
||||
}
|
||||
|
||||
$password = Hash::make($r->password);
|
||||
|
||||
if ($get = EmailActivations::where('token', $r->token)->first() && strtotime($get->ttl) > time()) {
|
||||
// 有効期限が切れている場合
|
||||
return['status_code' => 401, 'error_messages' => ['仮登録の有効期限が切れました。改めて管理者にお問い合わせいただき、再登録を行ってください。']];
|
||||
if ($get = EmailActivation::select('email', 'ttl')->where('token', $r->token)->first()) {
|
||||
if (time() > strtotime($get->ttl)) {
|
||||
// 有効期限が切れている場合
|
||||
return['status_code' => 401, 'error_messages' => ['仮登録の有効期限が切れました。改めて管理者にお問い合わせいただき、再登録を行ってください。']];
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// DBの値の準備。
|
||||
$create = [
|
||||
'email' => $get->email,
|
||||
'email_verified_at' => date('Y-m-d H:i:s'),
|
||||
'password' => $password,
|
||||
'password' => Hash::make($r->password),
|
||||
'company' => $r->company,
|
||||
'image' => $r->image,
|
||||
'profile' => $r->profile,
|
||||
'tel' => $r->tel,
|
||||
];
|
||||
|
||||
// DBに入ります。
|
||||
Father::create($create);
|
||||
|
||||
// メールを送ります。
|
||||
Mail::to($get->email)->send(new FathersRegistrationMainMail());
|
||||
|
||||
// email_activationsから削除します。
|
||||
EmailActivation::where('token', $r->token)->delete();
|
||||
} catch (\Throwable $e) {
|
||||
// 本登録に失敗
|
||||
Log::critical($e->getMessage());
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class FathersRegistrationMainMail extends Mailable {
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
public function build () {
|
||||
return $this->subject('本登録が完了しました。')->markdown('emails.fathers.registration.main');
|
||||
}
|
||||
}
|
|
@ -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 FathersRegistrationTemporaryMail extends Mailable {
|
||||
use Queueable, SerializesModels;
|
||||
private $token;
|
||||
|
||||
public function __construct ($token) {
|
||||
$this->token = $token;
|
||||
}
|
||||
|
||||
public function build () {
|
||||
return $this->subject('仮登録が完了しました。')->markdown('emails.fathers.registration.temporary', [
|
||||
'token' => $this->token
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -8,4 +8,6 @@ use Illuminate\Database\Eloquent\Model;
|
|||
class EmailActivation extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $fillable = ['email', 'token', 'ttl'];
|
||||
protected $attributes = ['type' => 0];
|
||||
}
|
||||
|
|
|
@ -8,6 +8,6 @@ use Illuminate\Foundation\Auth\User as Authenticatable;
|
|||
class Father extends Authenticatable
|
||||
{
|
||||
use HasFactory;
|
||||
protected $fillable = ['email', 'password'];
|
||||
protected $fillable = ['email', 'password', 'company', 'image', 'profile', 'tel'];
|
||||
protected $hidden = ['password'];
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
@component('mail::message')
|
||||
# 本登録が完了しました。
|
||||
|
||||
サイトへのアカウント本登録が完了しました。
|
||||
|
||||
以下のリンクからログインしてくださいませ。
|
||||
|
||||
@component('mail::button', ['url' => env('APP_URL').'/p-account/login'])
|
||||
{{ env('APP_URL') }}/p-account/login
|
||||
@endcomponent
|
||||
@endcomponent
|
|
@ -0,0 +1,11 @@
|
|||
@component('mail::message')
|
||||
# 仮登録が完了しました。
|
||||
|
||||
サイトへのアカウント仮登録が完了しました。
|
||||
|
||||
以下のリンクからログインして、本登録を完了させてください。
|
||||
|
||||
@component('mail::button', ['url' => env('APP_URL').'/p-account/register/'.$token])
|
||||
{{ env('APP_URL') }}/p-account/register/{{ $token }}
|
||||
@endcomponent
|
||||
@endcomponent
|
新しいイシューから参照