PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.2.3
JetFormBuilder — Dynamic Blocks Form Builder v3.2.3
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / modules / verification / actions / verification.php
jetformbuilder / modules / verification / actions Last commit date
send.email.flow.json 2 years ago verification.php 2 years ago
verification.php
166 lines
1 <?php
2
3
4 namespace JFB_Modules\Verification\Actions;
5
6 // If this file is called directly, abort.
7 if ( ! defined( 'WPINC' ) ) {
8 die;
9 }
10
11 use Jet_Form_Builder\Actions\Action_Handler;
12 use Jet_Form_Builder\Actions\Actions_Tools;
13 use Jet_Form_Builder\Actions\Events\Default_Process\Default_Process_Event;
14 use Jet_Form_Builder\Actions\Events\Default_Required\Default_Required_Event;
15 use Jet_Form_Builder\Actions\Types\Base;
16 use Jet_Form_Builder\Db_Queries\Base_Db_Model;
17 use Jet_Form_Builder\Db_Queries\Exceptions\Sql_Exception;
18 use Jet_Form_Builder\Exceptions\Action_Exception;
19 use JFB_Modules\Webhook\Db\Models\Tokens_Model;
20 use JFB_Modules\Webhook\Db\Models\Tokens_To_Records_Model;
21 use JFB_Modules\Form_Record\Action_Types\Save_Record;
22 use JFB_Modules\Verification\Events\Verification_Success;
23 use JFB_Modules\Verification\Events\Verification_Failed;
24 use JFB_Modules\Verification\Module;
25 use JFB_Modules\Webhook;
26 use JFB_Modules\Security;
27
28 class Verification extends Base {
29
30 const TOKEN = '_jfb_verification_token';
31 const TOKEN_ID = '_jfb_verification_token_id';
32 const URL = '_jfb_verification_url';
33
34 public function get_id() {
35 return 'verification';
36 }
37
38 public function get_name() {
39 return __( 'Verification', 'jet-form-builder' );
40 }
41
42 public function unsupported_events(): array {
43 return array(
44 Default_Required_Event::class,
45 Verification_Success\Event::class,
46 Verification_Failed\Event::class,
47 );
48 }
49
50 public function get_required_events(): array {
51 return array(
52 Default_Process_Event::class,
53 );
54 }
55
56 /**
57 * @param array $request
58 * @param Action_Handler $handler
59 *
60 * @return void
61 * @throws Sql_Exception
62 */
63 public function do_action( array $request, Action_Handler $handler ) {
64 // saving the request is required
65 Save_Record::add_hidden();
66
67 // set field-type to make this fields as objects, which extends Field_Data_Parser
68 jet_fb_context()->set_field_type( 'text-field', self::TOKEN );
69 jet_fb_context()->set_field_type( 'text-field', self::URL );
70 jet_fb_context()->set_field_type( 'number-field', self::TOKEN_ID );
71
72 // this fields shouldn't save as field in Form Record
73 jet_fb_context()->make_secure( self::TOKEN );
74 jet_fb_context()->make_secure( self::URL );
75 jet_fb_context()->make_secure( self::TOKEN_ID );
76
77 $lifespan = $this->settings['lifespan'] ?? '';
78
79 list( $id, $token ) = Tokens_Model::create_token( $this->get_id(), $lifespan );
80
81 // generate unique token for current request, which could be used in another actions
82 jet_fb_context()->update_request( $token, self::TOKEN );
83 jet_fb_context()->update_request( $id, self::TOKEN_ID );
84 jet_fb_context()->update_request(
85 add_query_arg(
86 array(
87 Webhook\Module::GET_TOKEN_ID => $id,
88 Webhook\Module::GET_TOKEN => jet_fb_context()->get_value( self::TOKEN ),
89 ),
90 jet_fb_handler()->refer
91 ),
92 self::URL
93 );
94
95 add_action(
96 'jet-form-builder/form-handler/after-send',
97 array( $this, 'connect_record_or_delete_token' ),
98 10,
99 2
100 );
101
102 $this->send_default_email();
103 }
104
105 public function send_default_email() {
106 if ( ! empty( $this->settings['custom_email'] ) || empty( $this->settings['mail_to'] ) ) {
107 return;
108 }
109
110 /** @var Module $module */
111 /** @noinspection PhpUnhandledExceptionInspection */
112 $module = jet_form_builder()->module( Module::class );
113
114 $generator = Actions_Tools::get_flow(
115 $module->get_dir( 'actions/send.email.flow.json' )
116 );
117
118 /**
119 * @var Base $action
120 * @var array $props
121 */
122 foreach ( $generator as list( $action, $props ) ) {
123 $action->settings['mail_to'] = 'form';
124 $action->settings['from_field'] = $this->settings['mail_to'];
125
126 jet_fb_action_handler()->add( $action, $props );
127 /**
128 * Execute action immediately, because is should run on the same event.
129 * If it would be with ON.DEFAULT.STATE - we may not use it line of the code
130 * But we couldn't be sure, that current process runs with DEFAULT.STATE render-state
131 */
132 jet_fb_action_handler()->process_single_action( $action );
133 }
134
135 /**
136 * Reset current action ID, because it was changed
137 * by `jet_fb_action_handler()->process_single_action`
138 */
139 jet_fb_action_handler()->set_current_action( $this->_id );
140 }
141
142 /**
143 * @param $handler
144 * @param $is_success
145 *
146 * @throws Sql_Exception
147 */
148 public function connect_record_or_delete_token( $handler, $is_success ) {
149 $record_id = jet_fb_action_handler()->get_context( Save_Record::ID, 'id' );
150 $token_id = jet_fb_context()->get_value( self::TOKEN_ID );
151
152 if ( ! $is_success ) {
153 ( new Tokens_Model() )->delete( array( 'id' => $token_id ) );
154
155 return;
156 }
157
158 ( new Tokens_To_Records_Model() )->insert(
159 array(
160 'token_id' => $token_id,
161 'record_id' => $record_id,
162 )
163 );
164 }
165 }
166