doujie1917 2019-08-09 03:27
浏览 57

验证电子邮件时将用户重定向到自定义页面

I was following a post on medium on how to do API email verification in Laravel 5.8 here https://medium.com/@pran.81/how-to-implement-laravels-must-verify-email-feature-in-the-api-registration-b531608ecb99

I tested it and it works perfectly but I was wondering how it would work when a web or mobile application consumes the API. Here are my thoughts

  1. Web or mobile user registers a new account by calling the route Route::post('register', 'AuthController@register') and the controller register method is this
public function register(Request $request)
{
    // validate inputs

    // store new user & send verify email notification to user
    $user = User::create([
        'firstname' => $request->firstname,
        'lastname'  => $request->lastname,
        'username'  => $request->username,
        'password'  => bcrypt($request->password)
    ]);

    $user->sendApiEmailVerificationNotification();

    // assign access token to newly registered user

    // return access token & user data

}
  1. User get an email with a Verify Email Address button

Now what should happen next? Should the user be redirected to the web app login page? If yes, how do I customise the redirect url? At the moment when I click on the verify email address button, a browser opens up and I get all the response on the browser page like this api endpoint response

  • 写回答

1条回答 默认 最新

  • douhuantui6259 2019-08-09 03:57
    关注

    Once the user clicks on Verify they are redirected to the path mentioned in

    App\Http\Controllers\Auth\VerificationController

    Now if you want to change the redirect after verification you can change the below line of code with your route in VerificationController

    /** * Where to redirect users after verification. * * @var string */ protected $redirectTo = '/home';

    评论

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助