PluginProbe
FluentSMTP – WP Mail SMTP Plugin with Amazon SES, SendGrid, Mailgun, Postmark, Cloudflare, toSend, Gmail and Any SMTP / trunk
FluentSMTP – WP Mail SMTP Plugin with Amazon SES, SendGrid, Mailgun, Postmark, Cloudflare, toSend, Gmail and Any SMTP vtrunk
2.4.0 trunk 1.0.1 1.1.0 1.1.1 1.2.0 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.71 2.2.72 2.2.73 2.2.80 2.2.81 All 32 releases
fluent-smtp / app / Http / Controllers / Controller.php

Controller.php in FluentSMTP – WP Mail SMTP Plugin with Amazon SES, SendGrid, Mailgun, Postmark, Cloudflare, toSend, Gmail and Any SMTP trunk, at app/Http/Controllers/Controller.php

82 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentMail\App\Http\Controllers;
4
5 use FluentMail\App\App;
6
7 abstract class Controller
8 {
9 /**
10 * @var \FluentMail\App\Plugin
11 */
12 protected $app = null;
13
14 /**
15 * @var \FluentMail\Includes\Request\Request
16 */
17 protected $request = null;
18
19 /**
20 * @var \FluentMail\Includes\Response\Response
21 */
22 protected $response = null;
23
24 public function __construct()
25 {
26 $this->app = App::getInstance();
27 $this->request = $this->app['request'];
28 $this->response = $this->app['response'];
29 }
30
31 public function send($data = null, $code = 200)
32 {
33 return $this->response->send($data, $code);
34 }
35
36 public function sendSuccess($data = null, $code = 200)
37 {
38 return $this->response->sendSuccess($data, $code);
39 }
40
41 public function sendError($data = null, $code = 422)
42 {
43 return $this->response->sendError($data, $code);
44 }
45
46 /*
47 * Both failures carry 403.
48 *
49 * wp_send_json_error() defaults to HTTP 200, so a rejected request used to arrive
50 * looking exactly like a successful one: jQuery resolved it, the frontend read the
51 * error object as data, and an expired nonce was reported to the user as a green
52 * success reading "Security check failed". Every other error path in the plugin already
53 * carries a status - sendError() defaults to 422 and the exception handler sends
54 * 403/422 - and the frontend is written against that, with two dozen handlers
55 * reading responseJSON.data.message on failure. These two were the exception.
56 *
57 * The status is the only thing that changes: wp_send_json_error() builds the same
58 * {success: false, data: {...}} body either way, so nothing reading the response
59 * has to change with it.
60 */
61 public function verify()
62 {
63 $permission = fluentMailManageCapability();
64 if(!current_user_can($permission)) {
65 wp_send_json_error([
66 'message' => __('You do not have permission to do this.', 'fluent-smtp')
67 ], 403);
68 die();
69 }
70
71 $nonce = $this->request->get('nonce');
72 if(!wp_verify_nonce($nonce, FLUENTMAIL)) {
73 wp_send_json_error([
74 'message' => __('Security check failed. Please reload the page.', 'fluent-smtp')
75 ], 403);
76 die();
77 }
78
79 return true;
80 }
81 }
82