diff --git a/.env.example b/.env.example index 330a9e3f..09d89cf1 100644 --- a/.env.example +++ b/.env.example @@ -27,6 +27,9 @@ MAIL_USERNAME= MAIL_PASSWORD= MAIL_ENCRYPTION= +MAIL_FROM_ADDRESS= +MAIL_FROM_NAME= + PUSHER_APP_ID= PUSHER_KEY= PUSHER_SECRET= diff --git a/app/Http/Controllers/EnvironmentController.php b/app/Http/Controllers/EnvironmentController.php index 94d9701a..7bf6aaed 100755 --- a/app/Http/Controllers/EnvironmentController.php +++ b/app/Http/Controllers/EnvironmentController.php @@ -81,10 +81,8 @@ class EnvironmentController extends Controller 'mail_mailgun_endpoint' => config('services.mailgun.endpoint'), 'mail_mailgun_domain' => config('services.mailgun.domain'), 'mail_mailgun_secret' => config('services.mailgun.secret'), - 'mail_sparkpost_secret' => config('services.sparkpost.secret'), 'mail_ses_key' => config('services.ses.key'), 'mail_ses_secret' => config('services.ses.secret'), - 'mail_mandrill_secret' => config('services.mandrill.secret'), ]; @@ -102,9 +100,7 @@ class EnvironmentController extends Controller 'mail', 'sendmail', 'mailgun', - 'mandrill', - 'ses', - 'sparkpost' + 'ses' ]; return response()->json($drivers); diff --git a/app/Http/Controllers/EstimatesController.php b/app/Http/Controllers/EstimatesController.php index 706a50a1..3312842d 100644 --- a/app/Http/Controllers/EstimatesController.php +++ b/app/Http/Controllers/EstimatesController.php @@ -13,6 +13,7 @@ use Crater\User; use Crater\Item; use Validator; use Crater\CompanySetting; +use Crater\Company; use Crater\Mail\EstimatePdf; use Crater\TaxType; use Crater\Tax; @@ -147,6 +148,7 @@ class EstimatesController extends Controller $data['estimate'] = $estimate->toArray(); $userId = $data['estimate']['user_id']; $data['user'] = User::find($userId)->toArray(); + $data['company'] = Company::find($estimate->company_id); $email = $data['user']['email']; $notificationEmail = CompanySetting::getSetting( 'notification_email', @@ -310,6 +312,8 @@ class EstimatesController extends Controller $data['estimate'] = $estimate->toArray(); $userId = $data['estimate']['user_id']; $data['user'] = User::find($userId)->toArray(); + $data['company'] = Company::find($estimate->company_id); + $email = $data['user']['email']; $notificationEmail = CompanySetting::getSetting( 'notification_email', diff --git a/app/Http/Controllers/InvoicesController.php b/app/Http/Controllers/InvoicesController.php index 13415b36..da97751f 100644 --- a/app/Http/Controllers/InvoicesController.php +++ b/app/Http/Controllers/InvoicesController.php @@ -3,6 +3,7 @@ namespace Crater\Http\Controllers; use Illuminate\Http\Request; use Crater\CompanySetting; +use Crater\Company; use Illuminate\Support\Collection; use Crater\Currency; use Crater\InvoiceTemplate; @@ -148,6 +149,7 @@ class InvoicesController extends Controller if ($request->has('invoiceSend')) { $data['invoice'] = Invoice::findOrFail($invoice->id)->toArray(); $data['user'] = User::find($request->user_id)->toArray(); + $data['company'] = Company::find($invoice->company_id); $notificationEmail = CompanySetting::getSetting( 'notification_email', @@ -374,6 +376,7 @@ class InvoicesController extends Controller $data['invoice'] = $invoice->toArray(); $userId = $data['invoice']['user_id']; $data['user'] = User::find($userId)->toArray(); + $data['company'] = Company::find($invoice->company_id); $email = $data['user']['email']; $notificationEmail = CompanySetting::getSetting( 'notification_email', diff --git a/app/Http/Requests/MailEnvironmentRequest.php b/app/Http/Requests/MailEnvironmentRequest.php index cc911c6e..652964cb 100644 --- a/app/Http/Requests/MailEnvironmentRequest.php +++ b/app/Http/Requests/MailEnvironmentRequest.php @@ -29,8 +29,8 @@ class MailEnvironmentRequest extends FormRequest 'mail_driver' => 'required|string|max:50', 'mail_host' => 'required|string|max:50', 'mail_port' => 'required|max:50', - 'mail_username' => 'required|string|max:50', - 'mail_password' => 'required|string|max:50', + 'mail_username' => 'required|string', + 'mail_password' => 'required|string', 'mail_encryption' => 'required|string|max:50', 'from_name' => 'required|string|max:50', 'from_mail' => 'required|string|max:50', @@ -42,21 +42,9 @@ class MailEnvironmentRequest extends FormRequest 'mail_driver' => 'required|string|max:50', 'mail_host' => 'required|string|max:50', 'mail_port' => 'required|max:50', - 'mail_mailgun_domain' => 'required|string|max:50', - 'mail_mailgun_secret' => 'required|string|max:50', - 'mail_mailgun_endpoint' => 'required|string|max:50', - 'mail_encryption' => 'required|string|max:50', - 'from_name' => 'required|string|max:50', - 'from_mail' => 'required|string|max:50', - ]; - break; - - case 'sparkpost': - return [ - 'mail_driver' => 'required|string|max:50', - 'mail_host' => 'required|string|max:50', - 'mail_port' => 'required|max:50', - 'mail_sparkpost_secret' => 'required|string|max:50', + 'mail_mailgun_domain' => 'required|string', + 'mail_mailgun_secret' => 'required|string', + 'mail_mailgun_endpoint' => 'required|string', 'mail_encryption' => 'required|string|max:50', 'from_name' => 'required|string|max:50', 'from_mail' => 'required|string|max:50', @@ -68,8 +56,8 @@ class MailEnvironmentRequest extends FormRequest 'mail_driver' => 'required|string|max:50', 'mail_host' => 'required|string|max:50', 'mail_port' => 'required|max:50', - 'mail_ses_key' => 'required|string|max:50', - 'mail_ses_secret' => 'required|string|max:50', + 'mail_ses_key' => 'required|string', + 'mail_ses_secret' => 'required|string', 'mail_encryption' => 'required|string|max:50', 'from_name' => 'required|string|max:50', 'from_mail' => 'required|string|max:50', @@ -89,19 +77,6 @@ class MailEnvironmentRequest extends FormRequest 'from_mail' => 'required|string|max:50', ]; break; - - case 'mandrill': - return [ - 'mail_driver' => 'required|string|max:50', - 'mail_host' => 'required|string|max:50', - 'mail_port' => 'required|max:50', - 'mail_mandrill_secret' => 'required|string|max:50', - 'mail_encryption' => 'required|string|max:50', - 'from_name' => 'required|string|max:50', - 'from_mail' => 'required|string|max:50', - ]; - break; } - } } diff --git a/app/Space/EnvironmentManager.php b/app/Space/EnvironmentManager.php index 456a0e0f..bd120703 100755 --- a/app/Space/EnvironmentManager.php +++ b/app/Space/EnvironmentManager.php @@ -33,20 +33,20 @@ class EnvironmentManager public function saveDatabaseVariables(DatabaseEnvironmentRequest $request) { $oldDatabaseData = - 'DB_CONNECTION='.config('database.default')."\n". - 'DB_HOST='.config('database.connections.'.config('database.default').'.host')."\n". - 'DB_PORT='.config('database.connections.'.config('database.default').'.port')."\n". - 'DB_DATABASE='.config('database.connections.'.config('database.default').'.database')."\n". - 'DB_USERNAME='.config('database.connections.'.config('database.default').'.username')."\n". - 'DB_PASSWORD='.config('database.connections.'.config('database.default').'.password')."\n\n"; + 'DB_CONNECTION='.config('database.default')."\n". + 'DB_HOST='.config('database.connections.'.config('database.default').'.host')."\n". + 'DB_PORT='.config('database.connections.'.config('database.default').'.port')."\n". + 'DB_DATABASE='.config('database.connections.'.config('database.default').'.database')."\n". + 'DB_USERNAME='.config('database.connections.'.config('database.default').'.username')."\n". + 'DB_PASSWORD='.config('database.connections.'.config('database.default').'.password')."\n\n"; $newDatabaseData = - 'DB_CONNECTION='.$request->database_connection."\n". - 'DB_HOST='.$request->database_hostname."\n". - 'DB_PORT='.$request->database_port."\n". - 'DB_DATABASE='.$request->database_name."\n". - 'DB_USERNAME='.$request->database_username."\n". - 'DB_PASSWORD='.$request->database_password."\n\n"; + 'DB_CONNECTION='.$request->database_connection."\n". + 'DB_HOST='.$request->database_hostname."\n". + 'DB_PORT='.$request->database_port."\n". + 'DB_DATABASE='.$request->database_name."\n". + 'DB_USERNAME='.$request->database_username."\n". + 'DB_PASSWORD='.$request->database_password."\n\n"; if (! $this->checkDatabaseConnection($request)) { @@ -94,9 +94,8 @@ class EnvironmentManager */ public function saveMailVariables(MailEnvironmentRequest $request) { - $mailData = $this->getMailData($request); - dd($mailData); + try { file_put_contents($this->envPath, str_replace( @@ -105,6 +104,22 @@ class EnvironmentManager file_get_contents($this->envPath) )); + if($mailData['extra_old_mail_data']) { + file_put_contents($this->envPath, str_replace( + $mailData['extra_old_mail_data'], + $mailData['extra_mail_data'], + file_get_contents($this->envPath) + )); + } else { + file_put_contents( + $this->envPath, + "\n".$mailData['extra_mail_data'], + FILE_APPEND + ); + } + + + } catch (Exception $e) { return [ 'error' => 'mail_variables_save_error' @@ -118,126 +133,158 @@ class EnvironmentManager private function getMailData($request) { - $mailCredential = ""; - $otherCredential = ""; - $oldMailOtherCredential = ""; + $mailFromCredential = ""; + $extraMailData = ""; + $extraOldMailData = ""; + $oldMailData = ""; + $newMailData = ""; - if(env('MAIL_FROM_ADDRESS') && env('MAIL_FROM_NAME')) { - $oldMailOtherCredential = + if(env('MAIL_FROM_ADDRESS') !== NULL && env('MAIL_FROM_NAME') !== NULL ) { + $mailFromCredential = 'MAIL_FROM_ADDRESS='.config('mail.from.address')."\n". 'MAIL_FROM_NAME='.config('mail.from.name')."\n\n"; } - $oldMailCredential = - 'MAIL_USERNAME='.config('mail.username')."\n". - 'MAIL_PASSWORD='.config('mail.password')."\n"; - - $resetCredential = - 'MAIL_USERNAME='."\n". - 'MAIL_PASSWORD='."\n"; - switch ($request->mail_driver) { case 'smtp': - $mailCredential= + + $oldMailData = + 'MAIL_DRIVER='.config('mail.driver')."\n". + 'MAIL_HOST='.config('mail.host')."\n". + 'MAIL_PORT='.config('mail.port')."\n". + 'MAIL_USERNAME='.config('mail.username')."\n". + 'MAIL_PASSWORD='.config('mail.password')."\n". + 'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n". + $mailFromCredential; + + $newMailData = + 'MAIL_DRIVER='.$request->mail_driver."\n". + 'MAIL_HOST='.$request->mail_host."\n". + 'MAIL_PORT='.$request->mail_port."\n". 'MAIL_USERNAME='.$request->mail_username."\n". - 'MAIL_PASSWORD='.$request->mail_password."\n"; + 'MAIL_PASSWORD='.$request->mail_password."\n". + 'MAIL_ENCRYPTION='.$request->mail_encryption."\n\n". + 'MAIL_FROM_ADDRESS='.$request->from_mail."\n". + 'MAIL_FROM_NAME='.$request->from_name."\n\n"; + break; case 'mailgun': - $mailCredential = $resetCredential; - $otherCredential= + $oldMailData = + 'MAIL_DRIVER='.config('mail.driver')."\n". + 'MAIL_HOST='.config('mail.host')."\n". + 'MAIL_PORT='.config('mail.port')."\n". + 'MAIL_USERNAME='.config('mail.username')."\n". + 'MAIL_PASSWORD='.config('mail.password')."\n". + 'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n". + $mailFromCredential; + + $newMailData = + 'MAIL_DRIVER='.$request->mail_driver."\n". + 'MAIL_HOST='.$request->mail_host."\n". + 'MAIL_PORT='.$request->mail_port."\n". + 'MAIL_USERNAME='.config('mail.username')."\n". + 'MAIL_PASSWORD='.config('mail.password')."\n". + 'MAIL_ENCRYPTION='.$request->mail_encryption."\n\n". + 'MAIL_FROM_ADDRESS='.$request->from_mail."\n". + 'MAIL_FROM_NAME='.$request->from_name."\n\n"; + + $extraMailData= 'MAILGUN_DOMAIN='.$request->mail_mailgun_domain."\n". 'MAILGUN_SECRET='.$request->mail_mailgun_secret."\n". - 'MAILGUN_ENDPOINT='.$request->mail_mailgun_endpoint."\n\n"; + 'MAILGUN_ENDPOINT='.$request->mail_mailgun_endpoint."\n"; - if(env('MAILGUN_DOMAIN') && env('MAILGUN_SECRET') && env('MAILGUN_ENDPOINT')) { - $oldMailOtherCredential = + if(env('MAILGUN_DOMAIN') !== NULL && env('MAILGUN_SECRET') !== NULL && env('MAILGUN_ENDPOINT') !== NULL) { + $extraOldMailData = 'MAILGUN_DOMAIN='.config('services.mailgun.domain')."\n". 'MAILGUN_SECRET='.config('services.mailgun.secret')."\n". - 'MAILGUN_ENDPOINT='.config('services.mailgun.endpoint')."\n\n"; + 'MAILGUN_ENDPOINT='.config('services.mailgun.endpoint')."\n"; } break; - case 'sparkpost': - $mailCredential = $resetCredential; - $otherCredential= - 'SPARKPOST_SECRET='.$request->mail_sparkpost_secret."\n\n"; - - if(env('SPARKPOST_SECRET')) { - $oldMailOtherCredential = - 'SPARKPOST_SECRET='.config('services.sparkpost.secret')."\n\n"; - } - break; - case 'ses': - $mailCredential = $resetCredential; - $otherCredential= - 'SES_KEY='.$request->mail_ses_key."\n". - 'SES_SECRET='.$request->mail_ses_secret."\n\n"; + $oldMailData = + 'MAIL_DRIVER='.config('mail.driver')."\n". + 'MAIL_HOST='.config('mail.host')."\n". + 'MAIL_PORT='.config('mail.port')."\n". + 'MAIL_USERNAME='.config('mail.username')."\n". + 'MAIL_PASSWORD='.config('mail.password')."\n". + 'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n". + $mailFromCredential; - if(env('SES_KEY') && env('SES_SECRET')) { - $oldMailOtherCredential = + $newMailData = + 'MAIL_DRIVER='.$request->mail_driver."\n". + 'MAIL_HOST='.$request->mail_host."\n". + 'MAIL_PORT='.$request->mail_port."\n". + 'MAIL_USERNAME='.config('mail.username')."\n". + 'MAIL_PASSWORD='.config('mail.password')."\n". + 'MAIL_ENCRYPTION='.$request->mail_encryption."\n\n". + 'MAIL_FROM_ADDRESS='.$request->from_mail."\n". + 'MAIL_FROM_NAME='.$request->from_name."\n\n"; + + $extraMailData= + 'SES_KEY='.$request->mail_ses_key."\n". + 'SES_SECRET='.$request->mail_ses_secret."\n"; + + if(env('SES_KEY') !== NULL && env('SES_SECRET') !== NULL ) { + $extraOldMailData = 'SES_KEY='.config('services.ses.key')."\n". - 'SES_SECRET='.config('services.ses.secret')."\n\n"; + 'SES_SECRET='.config('services.ses.secret')."\n"; } + break; case 'mail': - $existMailData = 'MAIL_DRIVER='.$request->mail_driver."\n". + $oldMailData = + 'MAIL_DRIVER='.config('mail.driver')."\n". 'MAIL_HOST='.config('mail.host')."\n". 'MAIL_PORT='.config('mail.port')."\n". - $resetCredential. + 'MAIL_USERNAME='.config('mail.username')."\n". + 'MAIL_PASSWORD='.config('mail.password')."\n". + 'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n". + $mailFromCredential; + + $newMailData = + 'MAIL_DRIVER='.$request->mail_driver."\n". + 'MAIL_HOST='.config('mail.host')."\n". + 'MAIL_PORT='.config('mail.port')."\n". + 'MAIL_USERNAME='.config('mail.username')."\n". + 'MAIL_PASSWORD='.config('mail.password')."\n". 'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n". 'MAIL_FROM_ADDRESS='.$request->from_mail."\n". - 'MAIL_FROM_NAME='.$request->from_name."\n\n". - $otherCredential; + 'MAIL_FROM_NAME='.$request->from_name."\n\n"; + break; case 'sendmail': - $existMailData = 'MAIL_DRIVER='.$request->mail_driver."\n". + $oldMailData = + 'MAIL_DRIVER='.config('mail.driver')."\n". 'MAIL_HOST='.config('mail.host')."\n". 'MAIL_PORT='.config('mail.port')."\n". - $resetCredential. + 'MAIL_USERNAME='.config('mail.username')."\n". + 'MAIL_PASSWORD='.config('mail.password')."\n". + 'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n". + $mailFromCredential; + + $newMailData = + 'MAIL_DRIVER='.$request->mail_driver."\n". + 'MAIL_HOST='.config('mail.host')."\n". + 'MAIL_PORT='.config('mail.port')."\n". + 'MAIL_USERNAME='.config('mail.username')."\n". + 'MAIL_PASSWORD='.config('mail.password')."\n". 'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n". 'MAIL_FROM_ADDRESS='.$request->from_mail."\n". - 'MAIL_FROM_NAME='.$request->from_name."\n\n". - $otherCredential; - break; + 'MAIL_FROM_NAME='.$request->from_name."\n\n"; - case 'mandrill': - $mailCredential = $oldMailCredential; - $otherCredential= - 'MANDRILL_API_KEY='.$request->mail_mandrill_secret."\n\n"; - - if(env('MANDRILL_API_KEY')) { - $oldMailOtherCredential = - 'MANDRILL_API_KEY='.config('services.mandrill.secret')."\n\n"; - } break; } - $oldMailData = - 'MAIL_DRIVER='.config('mail.driver')."\n". - 'MAIL_HOST='.config('mail.host')."\n". - 'MAIL_PORT='.config('mail.port')."\n". - $oldMailCredential. - 'MAIL_ENCRYPTION='.config('mail.encryption')."\n\n". - $oldMailOtherCredential; - - $newMailData = $existMailData ?? - 'MAIL_DRIVER='.$request->mail_driver."\n". - 'MAIL_HOST='.$request->mail_host."\n". - 'MAIL_PORT='.$request->mail_port."\n". - $mailCredential. - 'MAIL_ENCRYPTION='.$request->mail_encryption."\n\n". - 'MAIL_FROM_ADDRESS='.$request->from_mail."\n". - 'MAIL_FROM_NAME='.$request->from_name."\n\n". - $otherCredential; - return [ 'old_mail_data' => $oldMailData, - 'new_mail_data' => $newMailData + 'new_mail_data' => $newMailData, + 'extra_mail_data' => $extraMailData, + 'extra_old_mail_data' => $extraOldMailData ]; } diff --git a/config/services.php b/config/services.php index 319fdc05..bc4699d8 100644 --- a/config/services.php +++ b/config/services.php @@ -34,10 +34,6 @@ return [ 'api_key' => env('SENDGRID_API_KEY'), ], - 'mandrill' => [ - 'secret' => env('MANDRILL_API_KEY'), - ], - 'stripe' => [ 'model' => Crater\User::class, 'key' => env('STRIPE_KEY'), diff --git a/resources/assets/js/plugins/en.js b/resources/assets/js/plugins/en.js index f726b3f9..f15c7a99 100644 --- a/resources/assets/js/plugins/en.js +++ b/resources/assets/js/plugins/en.js @@ -569,16 +569,14 @@ export default { host: 'Mail Host', port: 'Mail Port', driver: 'Mail Driver', - domain: 'Domain', secret: 'Secret', - sparkpost_secret: 'Sparkpost Secret', - mailgin_secret: 'Mailgun Secret', + mailgun_secret: 'Mailgun Secret', + mailgun_domain: 'Domain', + mailgun_endpoint: 'Mailgun Endpoint', ses_secret: 'SES Secret', - mandrill_secret: 'Mandrill Secret', ses_key: 'SES Key', password: 'Mail Password', username: 'Mail Username', - endpoint: 'Mail Endpoint', mail_config: 'Mail Configuration', from_name: 'From Mail Name', from_mail: 'From Mail Address', @@ -747,16 +745,14 @@ export default { host: 'Mail Host', port: 'Mail Port', driver: 'Mail Driver', - domain: 'Domain', secret: 'Secret', - sparkpost_secret: 'Sparkpost Secret', - mailgin_secret: 'Mailgun Secret', + mailgun_secret: 'Mailgun Secret', + mailgun_domain: 'Domain', + mailgun_endpoint: 'Mailgun Endpoint', ses_secret: 'SES Secret', - mandrill_secret: 'Mandrill Secret', ses_key: 'SES Key', password: 'Mail Password', username: 'Mail Username', - endpoint: 'Mail Endpoint', mail_config: 'Mail Configuration', from_name: 'From Mail Name', from_mail: 'From Mail Address', diff --git a/resources/assets/js/views/settings/MailConfig.vue b/resources/assets/js/views/settings/MailConfig.vue index 3ba22956..58820c37 100644 --- a/resources/assets/js/views/settings/MailConfig.vue +++ b/resources/assets/js/views/settings/MailConfig.vue @@ -25,21 +25,17 @@ import MultiSelect from 'vue-multiselect' import { validationMixin } from 'vuelidate' import Smtp from './mailDriver/Smtp' import Mailgun from './mailDriver/Mailgun' -import Sparkpost from './mailDriver/Sparkpost' import Ses from './mailDriver/Ses' import Basic from './mailDriver/Basic' -import Mandrill from './mailDriver/Mandrill' export default { components: { MultiSelect, Smtp, Mailgun, - Sparkpost, Ses, sendmail: Basic, - mail: Basic, - Mandrill + mail: Basic }, mixins: [validationMixin], data () { diff --git a/resources/assets/js/views/settings/mailDriver/Basic.vue b/resources/assets/js/views/settings/mailDriver/Basic.vue index 2d4f4b84..e6d35b9e 100644 --- a/resources/assets/js/views/settings/mailDriver/Basic.vue +++ b/resources/assets/js/views/settings/mailDriver/Basic.vue @@ -2,7 +2,7 @@