PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.4.7
JetFormBuilder — Dynamic Blocks Form Builder v3.4.7
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
145 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\Exceptions\Sql_Exception;
17 use JFB_Modules\Webhook\Db\Models\Tokens_Model;
18 use JFB_Modules\Form_Record\Action_Types\Save_Record;
19 use JFB_Modules\Verification\Events\Verification_Success;
20 use JFB_Modules\Verification\Events\Verification_Failed;
21 use JFB_Modules\Verification\Module;
22 use JFB_Modules\Webhook;
23
24 class Verification extends Base {
25
26 const TOKEN = '_jfb_verification_token';
27 const TOKEN_ID = '_jfb_verification_token_id';
28 const URL = '_jfb_verification_url';
29
30 public function get_id() {
31 return 'verification';
32 }
33
34 public function get_name() {
35 return __( 'Verification', 'jet-form-builder' );
36 }
37
38 public function unsupported_events(): array {
39 return array(
40 Default_Required_Event::class,
41 Verification_Success\Event::class,
42 Verification_Failed\Event::class,
43 );
44 }
45
46 public function get_required_events(): array {
47 return array(
48 Default_Process_Event::class,
49 );
50 }
51
52 /**
53 * @param array $request
54 * @param Action_Handler $handler
55 *
56 * @return void
57 * @throws Sql_Exception
58 */
59 public function do_action( array $request, Action_Handler $handler ) {
60 // saving the request is required
61 Save_Record::add_hidden();
62
63 // set field-type to make this fields as objects, which extends Field_Data_Parser
64 jet_fb_context()->set_field_type( 'text-field', self::TOKEN );
65 jet_fb_context()->set_field_type( 'text-field', self::URL );
66 jet_fb_context()->set_field_type( 'number-field', self::TOKEN_ID );
67
68 // this fields shouldn't save as field in Form Record
69 jet_fb_context()->make_secure( self::TOKEN );
70 jet_fb_context()->make_secure( self::URL );
71 jet_fb_context()->make_secure( self::TOKEN_ID );
72
73 $lifespan = $this->settings['lifespan'] ?? 4;
74
75 list( $id, $token ) = Tokens_Model::create_token( $this->get_id(), $lifespan );
76
77 // generate unique token for current request, which could be used in another actions
78 jet_fb_context()->update_request( $token, self::TOKEN );
79 jet_fb_context()->update_request( $id, self::TOKEN_ID );
80 jet_fb_context()->update_request(
81 add_query_arg(
82 array(
83 Webhook\Module::GET_TOKEN_ID => $id,
84 Webhook\Module::GET_TOKEN => jet_fb_context()->get_value( self::TOKEN ),
85 ),
86 jet_fb_handler()->refer
87 ),
88 self::URL
89 );
90
91 $this->send_default_email();
92
93 if ( empty( $this->settings['who_can'] ) ) {
94 return;
95 }
96 /**
97 * Clear parsers with verification info,
98 * to restrict user from self-verification
99 */
100 jet_fb_context()->remove( self::TOKEN );
101 jet_fb_context()->remove( self::URL );
102 }
103
104 public function send_default_email() {
105 if (
106 ! empty( $this->settings['custom_email'] ) ||
107 empty( $this->settings['mail_to'] ) ||
108 'admin' === ( $this->settings['who_can'] ?? '' )
109 ) {
110 return;
111 }
112
113 /** @var Module $module */
114 /** @noinspection PhpUnhandledExceptionInspection */
115 $module = jet_form_builder()->module( Module::class );
116
117 $generator = Actions_Tools::get_flow(
118 $module->get_dir( 'actions/send.email.flow.json' )
119 );
120
121 /**
122 * @var Base $action
123 * @var array $props
124 */
125 foreach ( $generator as list( $action, $props ) ) {
126 $action->settings['mail_to'] = 'form';
127 $action->settings['from_field'] = $this->settings['mail_to'];
128
129 jet_fb_action_handler()->add( $action, $props );
130 /**
131 * Execute action immediately, because is should run on the same event.
132 * If it would be with ON.DEFAULT.STATE - we may not use it line of the code
133 * But we couldn't be sure, that current process runs with DEFAULT.STATE render-state
134 */
135 jet_fb_action_handler()->process_single_action( $action );
136 }
137
138 /**
139 * Reset current action ID, because it was changed
140 * by `jet_fb_action_handler()->process_single_action`
141 */
142 jet_fb_action_handler()->set_current_action( $this->_id );
143 }
144 }
145