多重验证与验证电子邮件问题

时间:2020-07-18 10:19:26

标签: laravel

我有一个具有验证电子邮件功能的C:\Users\username>php phpunit --verbose FirstUnitTest 应用程序。我正在使用laravel的默认电子邮件验证功能multi-auth中间件。验证电子邮件通过Laraval的verified方法发送给每个角色。

功能:有2个角色。主要角色是sendEmailVerificationNotification(),它可以注册并可以创建company角色(employee角色不能直接注册)。

这是我的代码:

employee

Company.php

companies:
id | ... | email_verified_at | ...

employees:
id | company_id | ... | email_verified_at | ...


email_verified_at = timestamp : default null

Employee.php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;

class Company extends Authenticatable implements MustVerifyEmail
{
    use Notifiable;

    ...
}

RegisterController.php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;

class Employee extends Authenticatable implements MustVerifyEmail
{
    use Notifiable;

    ...
}

EmployeeController.php

namespace App\Http\Controllers\Auth;

...

use App\Company;

class RegisterController extends Controller
{
    ...

    protected function register()
    {
        # validating
        $arrayPost = $this->validator(request()->all())->validate();

        # models
        $Company = new Company();

        # accessing methods
        if(($company = $Company->_create($arrayPost))['success'] == false)
        {
            return redirect()->withErrors()->withInput();
        }
        else
        {
            $company->sendEmailVerificationNotification();
        }

        # returning
        return redirect()->route('site.registration.success');
    }

    ...
}

验证链接运行正常。但是,在更新记录时,仅namespace App\Http\Controllers; ... use App\Employee; class EmployeeController extends Controller { ... public function store() { $arrayPost = $this->validator(request()->all()); if($arrayPost->fails()) { ... } $Employee = new Employee(); # accessing methods if(($employee = $Employee->_create($arrayPost->validate()))['success'] == false) { return redirect()->withErrors()->withInput(); } else { $employee->sendEmailVerificationNotification(); } # returning return redirect()->route('admin.dashboard'); } ... } 表而不是companies表被更新。即使,验证链接也会从employees生成,并带有新创建的员工ID。

EmployeeController生成的链接:

employee

0 个答案:

没有答案