在larauth 7中进行管理员身份验证后注册

时间:2020-04-30 11:13:07

标签: php laravel authentication routes

我想在auth之后进行注册,因此管理员可以创建一个用户。我试图找到有关的信息,但是所有示例都在Laravel 5s中,并且控制器的方法也不相同。 请问您有个主意吗?

enter image description here

2 个答案:

答案 0 :(得分:0)

如果您想以管理员身份创建新用户,则只需使用User::create([ ... ])方法。请记住输入电子邮件和哈希密码,以便用户可以登录。

创建用户的示例:

User::create([
  'email' => 'foo@bar.com',
  'password' => bcrypt('foobar'),
]);

如果要删除访客的注册,则应删除RegistrationController并将路由更改为Auth::routes(['register' => false]);

答案 1 :(得分:-1)

管理员通常会为其应用程序创建用户。您必须谨慎对待用户的创建。我个人不希望管理员为我的帐户创建密码。

我将执行以下操作:

1。使用临时密码创建用户。

public function create(){
    $user = new User();
    $user->name = $request->name;
    $user->email = $request->email;
    $user->password = Hash::make(Str::random(32));
    $user->regToken = Str::random(32);
}

2。使用临时密码保存用户,并向新用户发送注册电子邮件,以便他可以更改密码。

$user->notify(new MailCompleteRegistrationNotification($user->regToken, $user->email));

我使用邮件通知发送注册邮件。在通知中,我具有以下tomail功能。

 public function toMail($notifiable)
    {
        return (new MailMessage)
            ->subject("Subject")
            ->line('Welcome to the application. We created a account for you but still need some details.')
            ->line('If you want to complete the registration you can click the button below:')
            ->action('Complete registration', url('registration',  [$this->regToken,  $this->email]));
    }

我建议像这样进行用户创建