Skip to content

Commit 2392211

Browse files
authored
Add files via upload
1 parent 7566532 commit 2392211

File tree

2 files changed

+130
-0
lines changed

2 files changed

+130
-0
lines changed

webform_authcode.admin.inc

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* Webform authcode module functions for admin sections.
6+
*/
7+
8+
/**
9+
* Validation callback handler for the webform configure form.
10+
*/
11+
function webform_authcode_webform_configure_validate($form, $form_state) {
12+
// Retrieve values from form_state.
13+
$values = $form_state['values'];
14+
15+
// Check for emtpty pass phrase.
16+
if ($values['authcode_protect'] == TRUE && empty($values['authcode_pass_phrase'])) {
17+
form_set_error('authcode_pass_phrase', t("The field pass phrase can't be empty."));
18+
}
19+
}
20+
21+
/**
22+
* Submit callback handler for the webform configure form.
23+
*/
24+
function webform_authcode_webform_configure_submit($form, $form_state) {
25+
// Retrieve values from form_state.
26+
$values = $form_state['values'];
27+
28+
// Retrieve the node id.
29+
$nid = $form['#node']->nid;
30+
31+
// Retrieve the stored pass phrases from the variable store.
32+
$authcode_phrases = variable_get('authtcode_pass_phrases', array());
33+
34+
// If the authcode protect checkbox was not checked, remove existing phrase.
35+
// Otherwise add/update it.
36+
if ($values['authcode_protect'] != TRUE && isset($authcode_phrases[$nid])) {
37+
// Delete the pass phrase.
38+
unset($authcode_phrases[$nid]);
39+
}
40+
else if ($values['authcode_protect'] != TRUE ) {
41+
// Delete the pass phrase.
42+
unset($authcode_phrases[$nid]); // added by John 161227 to avoid autocheck of master passwords BUG
43+
}
44+
else {
45+
// Add / update the pass phrase.
46+
$authcode_phrases[$nid] = $values['authcode_pass_phrase'];
47+
}
48+
49+
// Store the pass phrase in the variable store.
50+
variable_set('authtcode_pass_phrases', $authcode_phrases);
51+
}

webform_authcode.pages.inc

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* Webform authcode module functions for frontend.
6+
*/
7+
8+
/**
9+
* Callback function to build pass phrase form.
10+
*/
11+
function webform_authcode_pass_phrase_form($form, &$form_state) {
12+
13+
$form['description'] = array(
14+
'#prefix' => '<div class="introduction-text">',
15+
'#suffix' => '</div>',
16+
'#markup' => t('This form is protected by a pass phrase. Please enter the the pass phrase provided to you to gain access to the form.'),
17+
);
18+
19+
$form['authcode_pass_phrase'] = array(
20+
'#type' => 'textfield',
21+
'#title' => t('Pass phrase'),
22+
'#maxlength' => 255,
23+
'#size' => 50,
24+
'#description' => t('Please enter the pass phrase provided to you.'),
25+
);
26+
27+
$form['submit'] = array(
28+
'#type' => 'submit',
29+
'#value' => t('Continue'),
30+
);
31+
32+
// Add validation handler.
33+
$form['#validate'][] = 'webform_authcode_pass_phrase_form_validate';
34+
// Add submit handler.
35+
$form['#submit'][] = 'webform_authcode_pass_phrase_form_submit';
36+
37+
return $form;
38+
}
39+
40+
/**
41+
* Validation handler for webform_authcode_pass_phrase_form.
42+
*/
43+
function webform_authcode_pass_phrase_form_validate($form, $form_state) {
44+
// Retrieve values from form_state.
45+
$values = $form_state['values'];
46+
47+
// Retrieve the node id.
48+
$node = menu_get_object();
49+
$nid = $node->nid;
50+
51+
// Retrieve the stored pass phrases from the variable store.
52+
$authcode_phrases = variable_get('authtcode_pass_phrases', array());
53+
54+
// Check for emtpty pass phrase.
55+
if (empty($values['authcode_pass_phrase'])) {
56+
form_set_error('authcode_pass_phrase', t("The field pass phrase can't be empty."));
57+
}
58+
59+
// Check if the pass phrase is correct.
60+
if (!empty($values['authcode_pass_phrase']) && $values['authcode_pass_phrase'] !== $authcode_phrases[$nid]) {
61+
form_set_error('authcode_pass_phrase', t('The pass phrase you entered is incorrect. Please note that the pass phrase is case sensitive.'));
62+
}
63+
}
64+
65+
/**
66+
* Submit handler for webform_authcode_pass_phrase_form.
67+
*/
68+
function webform_authcode_pass_phrase_form_submit($form, $form_state) {
69+
// Retrieve values from form_state.
70+
$values = $form_state['values'];
71+
72+
// Retrieve the node id.
73+
$node = menu_get_object();
74+
$nid = $node->nid;
75+
76+
// Store the authcode in a cookie.
77+
$cookie_name = 'webform_authcode_' . $nid;
78+
user_cookie_save(array($cookie_name => check_plain($values['authcode_pass_phrase'])));
79+
}

0 commit comments

Comments
 (0)