File: D:/HostingSpaces/SBogers10/otto-das.komma.pro/app/Development/PreviewController.php
<?php
namespace App\Development;
use App\Notifications\CustomerRegistered;
use App\Notifications\SiteResetPasswordNotification;
use App\Pages\PageService;
use App\Users\Models\SiteUser;
use Illuminate\Routing\Controller;
use Komma\KMS\Globalization\RegionInfo;
use Komma\KMS\Notifications\SetPassword;
use Komma\KMS\Users\Models\KmsUser;
use Komma\KMS\Notifications\KmsResetPasswordNotification;
use Illuminate\Mail\Markdown;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Support\HtmlString;
use Illuminate\Support\Str;
use Illuminate\View\View;
class PreviewController extends Controller
{
/**
* @var \stdClass
*/
private $links;
public function __construct()
{
if(app()->runningInConsole()) return;
$pageService = new PageService();
$this->links = $pageService->getAllTranslatedPageRoutes();
}
/*
|--------------------------------------------------------------------------
| Mail previews
|--------------------------------------------------------------------------
|
| These functions must returns views that represent mails.
|
*/
/**
* @see KmsResetPasswordNotification
* @return HtmlString|View
*/
public function resetPasswordMail()
{
$customer = factory(SiteUser::class)->make();
$token = Str::random(32);
return $this->notificationToView(new SiteResetPasswordNotification($customer, $token));
}
/**
* @see KmsResetPasswordNotification
* @return HtmlString|View
*/
public function resetPasswordMailKms()
{
$customer = factory(KmsUser::class)->make();
$token = Str::random(32);
return $this->notificationToView(new KmsResetPasswordNotification($customer, $token));
}
/**
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*@see SetPassword
*/
public function setPasswordMail()
{
$customer = factory(SiteUser::class)->make();
$token = Str::random(32);
return $this->notificationToView(new SetPassword($customer, $token));
}
/**
* @see CustomerRegistered
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function registeredMail()
{
$customer = factory(SiteUser::class)->make();
return $this->notificationToView(new CustomerRegistered($customer));
}
/*
|--------------------------------------------------------------------------
| Authentication view previews
|--------------------------------------------------------------------------
|
| These functions must return blade views that are related to authentication
|
*/
public function registerView()
{
$culturesForSelect = RegionInfo::getNeutralCultures()->map(function(RegionInfo $regionInfo) {
return [$regionInfo->getThreeLetterISORegionName() => $regionInfo->getNativeName() ? $regionInfo->getNativeName() : $regionInfo->getDisplayName()];
})->collapse()->sort()->toArray();
$neutralCulturesHotList = RegionInfo::getNeutralCultures()->filter(function(RegionInfo $regionInfo) {
return in_array($regionInfo->getThreeLetterISORegionName(), config('shop.country_hotlist', []), true);
})->map(function(RegionInfo $regionInfo) use(&$culturesForSelect) {
if(isset($culturesForSelect[$regionInfo->getThreeLetterISORegionName()])) unset($culturesForSelect[$regionInfo->getThreeLetterISORegionName()]); //Remove the item from the regular cultures list
return [$regionInfo->getThreeLetterISORegionName() => $regionInfo->getNativeName() !== '' ? $regionInfo->getNativeName() : $regionInfo->getDisplayName()];
})->collapse()->sort();
return view('site.templates.auth.register', ['links' => $this->links, 'cultures' => $culturesForSelect, 'culturesHotlist' => $neutralCulturesHotList]);
}
public function registeredView()
{
return view('site.templates.auth.registered', ['links' => $this->links]);
}
public function loginView()
{
return view('site.templates.auth.login', ['links' => $this->links]);
}
public function forgotPassword()
{
return view('site.templates.auth.password.email', ['links' => $this->links]);
}
public function set()
{
return view('site.templates.auth.password.set', ['token' => Str::random(32)]);
}
public function reset()
{
return view('site.templates.auth.password.reset', ['token' => Str::random(32)]);
}
public function loginViewKms()
{
return view('KMS::kms.auth.login', ['links' => $this->links]);
}
public function forgotPasswordKms()
{
return view('KMS::kms.auth.password.email', ['links' => $this->links]);
}
public function resetKms()
{
return view('KMS::kms.auth.password.reset', ['token' => Str::random(32)]);
}
/*
|--------------------------------------------------------------------------
| Helper methods
|--------------------------------------------------------------------------
|
| These functions provide useful help for the ones that return views.
*/
/**
* Converts a notification to view
*
* @param Notification $notification
* @return HtmlString|View
*/
private function notificationToView(Notification $notification)
{
/** @var MailMessage $mail */
$mail = $notification->toMail(\Auth::user());
if($mail->markdown) {
$markdown = new Markdown(view());
return $markdown->render($mail->markdown, $mail->data());
}
elseif($mail->view)
{
return view($mail->view, $mail->data());
} else {
throw new \RuntimeException('Preview controller: I don\'t know how to render a view for "'.get_class($notification).'"');
}
}
}