Updates for smtp

This commit is contained in:
David Bomba 2024-02-29 14:02:32 +11:00
parent c4807be9df
commit 3772d2a165
2 changed files with 47 additions and 11 deletions

View File

@ -30,16 +30,24 @@ class SmtpController extends BaseController
$user = auth()->user(); $user = auth()->user();
$company = $user->company(); $company = $user->company();
$smtp_host = $request->input('smtp_host', $company->smtp_host);
$smtp_port = $request->input('smtp_port', $company->smtp_port);
$smtp_username = $request->input('smtp_username', $company->smtp_username);
$smtp_password = $request->input('smtp_password', $company->smtp_password);
$smtp_encryption = $request->input('smtp_encryption', $company->smtp_encryption ?? 'tls');
$smtp_local_domain = $request->input('smtp_local_domain', strlen($company->smtp_local_domain) > 2 ? $company->smtp_local_domain : null);
$smtp_verify_peer = $request->input('verify_peer', $company->smtp_verify_peer ?? true);
config([ config([
'mail.mailers.smtp' => [ 'mail.mailers.smtp' => [
'transport' => 'smtp', 'transport' => 'smtp',
'host' => $request->input('smtp_host', $company->smtp_host), 'host' => $smtp_host,
'port' => $request->input('smtp_port', $company->smtp_port), 'port' => $smtp_port,
'username' => $request->input('smtp_username', $company->smtp_username), 'username' => $smtp_username,
'password' => $request->input('smtp_password', $company->smtp_password), 'password' => $smtp_password,
'encryption' => $request->input('smtp_encryption', $company->smtp_encryption ?? 'tls'), 'encryption' => $smtp_encryption,
'local_domain' => $request->input('smtp_local_domain', strlen($company->smtp_local_domain) > 2 ? $company->smtp_local_domain : null), 'local_domain' => $smtp_local_domain,
'verify_peer' => $request->input('verify_peer', $company->smtp_verify_peer ?? true), 'verify_peer' => $smtp_verify_peer,
'timeout' => 5, 'timeout' => 5,
], ],
]); ]);

View File

@ -36,18 +36,46 @@ class CheckSmtpRequest extends Request
public function rules() public function rules()
{ {
return [ return [
'smtp_host' => 'sometimes|nullable|string|min:3',
'smtp_port' => 'sometimes|nullable|integer',
'smtp_username' => 'sometimes|nullable|string|min:3',
'smtp_password' => 'sometimes|nullable|string|min:3',
]; ];
} }
public function prepareForValidation() public function prepareForValidation()
{ {
/** @var \App\Models\User $user */
$user = auth()->user();
$company = $user->company();
$input = $this->input(); $input = $this->input();
if(isset($input['smtp_username']) && $input['smtp_username'] == '********') if(isset($input['smtp_username']) && $input['smtp_username'] == '********'){
unset($input['smtp_username']); // unset($input['smtp_username']);
$input['smtp_username'] = $company->smtp_username;
}
if(isset($input['smtp_password'])&& $input['smtp_password'] == '********'){
// unset($input['smtp_password']);
$input['smtp_password'] = $company->smtp_password;
}
if(isset($input['smtp_host']) && strlen($input['smtp_host']) >=3){
}
else {
$input['smtp_host'] = $company->smtp_host;
}
if(isset($input['smtp_port']) && strlen($input['smtp_port']) >= 3) {
} else {
$input['smtp_port'] = $company->smtp_port;
}
if(isset($input['smtp_password'])&& $input['smtp_password'] == '********')
unset($input['smtp_password']);
$this->replace($input); $this->replace($input);
} }