Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Ayenko4all/school-management-system-backend

12 stars
2 code files
View Ayenko4all/school-management-system-backend on GitHub

app/Notifications/SendEmailTokenNotification.php

Open in GitHub
use 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 GitHub
use 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',
]);
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.