Skip to content

Commit

Permalink
Fixed Slack Token verify and resend email issues
Browse files Browse the repository at this point in the history
  • Loading branch information
techjewel committed Oct 19, 2024
1 parent baa704c commit 06ae9ce
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
10 changes: 7 additions & 3 deletions app/Hooks/Handlers/AdminMenuHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,23 @@ public function addFluentMailMenu()

if (isset($_REQUEST['sub_action']) && $_REQUEST['sub_action'] == 'slack_success') {
add_action('admin_init', function () {
$nonce = Arr::get($_REQUEST, '_slacK_nonce');
if (!wp_verify_nonce($nonce, 'fluent_smtp_slack_register_site')) {
wp_redirect(admin_url('options-general.php?page=fluent-mail&slack_security_failed=1#/notification-settings'));
die();
}

$settings = (new Settings())->notificationSettings();
$token = Arr::get($_REQUEST, 'site_token');

if ($token == Arr::get($settings, 'slack.token')) {
if ($token && $token == Arr::get($settings, 'slack.token')) {
$settings['slack'] = [
'status' => 'yes',
'token' => sanitize_text_field($token),
'slack_team' => sanitize_text_field(Arr::get($_REQUEST, 'slack_team')),
'webhook_url' => sanitize_url(Arr::get($_REQUEST, 'slack_webhook'))
];

$settings['active_channel'] = 'slack';

update_option('_fluent_smtp_notify_settings', $settings);
}

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/LoggerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function retry(Request $request, Logger $logger)
$log['retries'] = $log['retries'] + 1;
$logger->updateLog($log, ['id' => $id]);

$this->sendError([
return $this->sendError([
'message' => $response->get_error_message(),
'errors' => $response->get_error_data()
], $response->get_error_code());
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Controllers/SlackController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ public function registerSite(Request $request)
], 422);
}

$nonce = wp_create_nonce('fluent_smtp_slack_register_site');

$payload = [
'admin_email' => $userEmail,
'smtp_url' => admin_url('options-general.php?page=fluent-mail#/'),
'smtp_url' => admin_url('options-general.php?_slacK_nonce='.$nonce.'&page=fluent-mail#/'),
'site_url' => site_url(),
'site_title' => get_bloginfo('name'),
'site_lang' => get_bloginfo('language'),
Expand Down
5 changes: 5 additions & 0 deletions app/Models/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ public function resendEmailFromLog($id, $type = 'retry')
$headers = [];

foreach ($email['headers'] as $key => $value) {

if($key == 'content-type' && $value == 'multipart/alternative') {
$value = 'text/html';
}

if (is_array($value)) {
$values = [];
$value = array_filter($value);
Expand Down

0 comments on commit 06ae9ce

Please sign in to comment.