HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/mountadvies.komma.pro/app/Auth/AuthMailService.php
<?php


namespace App\Auth;


use App\Shop\Orders\Kms\OrderMailService;
use Komma\KMS\Users\Models\KmsUser;
use Komma\KMS\Users\Models\KmsUserRole;
use App\Users\Models\SiteUser;
use App\Notifications\CustomerRegistered;
use App\Notifications\CustomerRegisteredSetPassword;
use App\Notifications\KmsUserRegisteredSetPassword;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Facades\Password;

/**
 * Class AuthMailService
 *
 * A service responsible for sending mails about authorisation and authentication.
 *
 * @see OrderMailService
 * @package App\Auth
 */
final class AuthMailService implements AuthMailServiceInterface
{
    /**
     * Notify admins that a new user has been created
     *
     * @param $customer
     * @return null
     */
    public function notifyAdminsForNewCustomer(SiteUser $customer)
    {
        KmsUser::where('role', '=', KmsUserRole::Admin)->get()->each(function(KmsUser $admin) use ($customer) {
            $admin->notify(new CustomerRegistered($customer));
            \Log::debug('Notified admin with id: '.$admin->id.' that user with id '.$customer->id.' registered');
        });
        return null;
    }

    /**
     * Notify user that he needs to set a password to login
     *
     * @param Authenticatable $newUser
     * @return null
     */
    public function notifyUserToSetPassword(Authenticatable $newUser)
    {
        $token = Password::getRepository()->create($newUser);

        if(is_a($newUser, KmsUser::class)) {
            $newUser->notify(new KmsUserRegisteredSetPassword($newUser, $token));
        }
        elseif(is_a($newUser, SiteUser::class)) {
            $newUser->notify(new CustomerRegisteredSetPassword($newUser, $token));
        }
        else{
            throw new \UnexpectedValueException(self::class.': Undefined user model.');
        }
        return null;
    }
}