简体   繁体   English

管理员从管理仪表板创建新用户后,Laravel 发送“创建密码电子邮件”

[英]Laravel Send "create password email" after admin created new user from Admin Dashboard

I have an admin dashboard.我有一个管理仪表板。 User can't create a user account by himself only admin has the rights to do it.用户不能自己创建用户帐户,只有管理员有权这样做。 But he will only create a user with "username" and "email".但他只会创建一个带有“用户名”和“电子邮件”的用户。 What I want to achieve is when he created a new user to send a email to the user email address with his "username" and "email" + button or link to create his password.我想要实现的是,当他创建一个新用户时,使用他的“用户名”和“电子邮件”+ 按钮或链接向用户电子邮件地址发送电子邮件以创建他的密码。 I was trying to search about customizing the default reset password functioanlity but I failed.我试图搜索有关自定义默认重置密码功能的信息,但我失败了。 Can someone provide some easier approach for this ?有人可以为此提供一些更简单的方法吗? Thank you谢谢

I think that is pretty easy, and in my opinion if you start thinking instead of "how to customise existing functionality" to "how to create my own functionality", you can figure it out by yourself in no time.我认为这很容易,而且在我看来,如果您开始思考而不是“如何自定义现有功能”到“如何创建我自己的功能”,您可以很快自己弄清楚。

You can do it for example like this, that after signing up the user, you can send within the registration email a link to "set my passwowrd" and the link might look like https://example.com/user/finish-registration?hash=sadfjasdnfdaisfnsduff例如,您可以这样做,在注册用户后,您可以在注册电子邮件中发送一个链接以“设置我的密码”,该链接可能看起来像https://example.com/user/finish-registration ?hash=sadfjasdnfdaisfnsduff

    //migration
    Schema::create($table, function() => {
        $table->string("set_password_hash");
        $table->string("username");
    });

    //signup method
    public function signUpUser(Request $request) {
        
        $user = new User();
        $user->username = $request->input("username");
        $user->email = $request->input("email");

        $user->set_password_hash = Hash::make(20); //or some random hash generator

        //set as empty string
        $user->password = "";
        $user->save();

        $signupMail = new SignupMail($user);
        $signupMail->send();
    }

    public function setPasswordView(Request $request) {
        $user = User::where("set_password_hash", $request->input("hash"))->first();

        if($user) {
            if($user->password === "") {
                //display a form for the user to create his own password
                return view("user.setPassword");
            } else {
                //the password has already been set    
            }
        }

        //fail or something
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM