-
app/Notifications/SendEmailTokenNotification.php
Open in GitHubuse Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; use Illuminate\Support\Facades\Lang; class SendEmailTokenNotification extends Notification { use Queueable; public $token; public $password; public function __construct($token, $password) { $this->token = $token; $this->password = $password; } public function via($notifiable) { return ['mail']; } public function toMail($notifiable) { return (new MailMessage()) ->subject(Lang::get('Verify Email Token')) ->greeting(Lang::get('Welcome to V-school!')) ->line(Lang::get('Your e-mail verification token is **:token**. It expires in :count minutes.', ['count' => config('auth.verification.email.expire'), 'token' => $this->token])) ->line(Lang::get("Your temporary password is, {$this->password}")) ->line(Lang::get('Please you are advise to change your temporary password by using the forgetPassword link on login page.')) ->line(Lang::get('If you did not request a verification token, no further action is required. Thank you.')); } // }
-
app/Http/Controllers/Auth/RegistrationController.php
Open in GitHubuse App\Enums\StatusEnum; use App\Enums\VerificationEnum; use App\Http\Controllers\RespondsWithHttpStatusController; use App\Http\Requests\RegistrationFormRequest; use App\Models\Token; use App\Models\User; use App\Notifications\SendEmailTokenNotification; use Illuminate\Support\Facades\Hash; class RegistrationController extends RespondsWithHttpStatusController { public function __invoke(RegistrationFormRequest $request) { Token::where('email', $request->email)->where('type', VerificationEnum::Email)->delete(); $password = generateTempPassword(); $user = User::create([ 'first_name' => $request->first_name, 'last_name' => $request->last_name, 'email' => $request->email, 'gender' => $request->gender, 'telephone' => $request->telephone, 'password' => Hash::make($password), 'status' => StatusEnum::ACTIVE ]) ->assignRole($request->input('roles')); $tokenData = Token::create([ 'token' => generateToken(), 'email' => $request->email, 'type' => VerificationEnum::Email ]); $user->notify(new SendEmailTokenNotification($tokenData->token, $password)); return $this->responseOk([ 'message' => 'Registration successful, An email has been sent to the user', ]); } }