Path: blob/1.0-develop/app/Http/Controllers/Admin/Settings/MailController.php
10284 views
<?php12namespace Pterodactyl\Http\Controllers\Admin\Settings;34use Illuminate\View\View;5use Illuminate\Http\Request;6use Illuminate\Http\Response;7use Illuminate\Contracts\Console\Kernel;8use Pterodactyl\Notifications\MailTested;9use Illuminate\Support\Facades\Notification;10use Pterodactyl\Exceptions\DisplayException;11use Pterodactyl\Http\Controllers\Controller;12use Illuminate\Contracts\Encryption\Encrypter;13use Pterodactyl\Providers\SettingsServiceProvider;14use Illuminate\Contracts\Config\Repository as ConfigRepository;15use Pterodactyl\Contracts\Repository\SettingsRepositoryInterface;16use Pterodactyl\Http\Requests\Admin\Settings\MailSettingsFormRequest;1718class MailController extends Controller19{20/**21* MailController constructor.22*/23public function __construct(24private ConfigRepository $config,25private Encrypter $encrypter,26private Kernel $kernel,27private SettingsRepositoryInterface $settings,28) {29}3031/**32* Render UI for editing mail settings. This UI should only display if33* the server is configured to send mail using SMTP.34*/35public function index(): View36{37return view('admin.settings.mail', [38'disabled' => $this->config->get('mail.default') !== 'smtp',39]);40}4142/**43* Handle request to update SMTP mail settings.44*45* @throws DisplayException46* @throws \Pterodactyl\Exceptions\Model\DataValidationException47* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException48*/49public function update(MailSettingsFormRequest $request): Response50{51if ($this->config->get('mail.default') !== 'smtp') {52throw new DisplayException('This feature is only available if SMTP is the selected email driver for the Panel.');53}5455$values = $request->normalize();56if (array_get($values, 'mail:mailers:smtp:password') === '!e') {57$values['mail:mailers:smtp:password'] = '';58}5960foreach ($values as $key => $value) {61if (in_array($key, SettingsServiceProvider::getEncryptedKeys()) && !empty($value)) {62$value = $this->encrypter->encrypt($value);63}6465$this->settings->set('settings::' . $key, $value);66}6768$this->kernel->call('queue:restart');6970return response('', 204);71}7273/**74* Submit a request to send a test mail message.75*/76public function test(Request $request): Response77{78try {79Notification::route('mail', $request->user()->email)80->notify(new MailTested($request->user()));81} catch (\Exception $exception) {82return response($exception->getMessage(), 500);83}8485return response('', 204);86}87}888990