繁体   English   中英

用户在单击电子邮件中的激活链接后进行更新

[英]USER update after clicking the activation link in the email

我有标准的Laravel注册系统。 单击电子邮件中的链接后,我需要为用户更新列启用(enable = 1)。

我的迁移:

Schema::create('users', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->bigInteger('company_id')->unsigned();
            $table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
            $table->boolean('enable')->default(0);
            $table->string('name', 120)->nullable();
            $table->string('surname', 120)->nullable();
            $table->string('email', 120)->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->bigInteger('counter')->default(0);
            $table->string('url_address', 160);
            $table->string('ip', 25)->nullable();
            $table->boolean('isCompany')->default(0);
            $table->boolean('isMailing')->default(0);
            $table->text('content')->nullable();
            $table->string('nip1', 12)->nullable();
            $table->string('business1', 120)->nullable();
            $table->string('phone1', 60)->nullable();
            $table->string('street1', 150)->nullable();
            $table->string('number1', 8)->nullable();
            $table->string('postal_code1', 12)->nullable();
            $table->string('city1', 100)->nullable();
            $table->bigInteger('country_id1')->default(0);
            $table->bigInteger('provincial_id1')->default(0);
            $table->string('nip2', 12)->nullable();
            $table->string('business2', 120)->nullable();
            $table->string('phone2', 60)->nullable();
            $table->string('street2', 150)->nullable();
            $table->string('number2', 8)->nullable();
            $table->string('postal_code2', 12)->nullable();
            $table->string('city2', 100)->nullable();
            $table->bigInteger('country_id2')->default(0);
            $table->bigInteger('provincial_id2')->default(0);
            $table->string('nip3', 12)->nullable();
            $table->string('business3', 120)->nullable();
            $table->string('phone3', 60)->nullable();
            $table->string('street3', 150)->nullable();
            $table->string('number3', 8)->nullable();
            $table->string('postal_code3', 12)->nullable();
            $table->string('city3', 100)->nullable();
            $table->bigInteger('country_id3')->default(0);
            $table->bigInteger('provincial_id3')->default(0);
            $table->decimal('cash', 9, 2)->default(0);
            $table->decimal('lng', 10, 8)->default(0);
            $table->decimal('lat', 10, 8)->default(0);
            $table->boolean('enable_map')->default(0);
            $table->rememberToken();
            $table->timestamps();
            $table->engine = "InnoDB";
        });

我怎样才能做到这一点? 默认情况下,用户设置为启用= 0

好了,您已经建立并enabled用户表,可以很好地实现您的目的。 接下来,您有几种选择,最简单的方法是在注册时触发一封带有链接的电子邮件,其链接为www.my.site/activate?token=MD5TOKEN,其中md5令牌是他们所注册电子邮件的md5哈希用。 然后,当他们点击该路线时将其激活,将其电子邮件哈希并进行比较(如果未登录),请先登录。 之后,如果匹配则将其激活。

替代方法是创建另一个名为activation_tokens表,该表存储电子邮件和可以多次重新生成的随机生成的令牌以及is_used列。

编辑以回答评论:

DB::table('users')
            ->where('email', $email)
            ->update(['enabled' => 1]);

尝试更改userActive()函数。

  public function userActive(Request $request, User $user) {
        echo "XXXXX".$request->user()->email; 
        $user->update([ 'enable' => 1]); 
        dd($user); // Redirect 
    }

暂无
暂无

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

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