Commit 91b78455 authored by Dave Lane's avatar Dave Lane

interim commit - nothing's working properly...

parent 9d6e35f8
......@@ -113,6 +113,10 @@ article.ore-form .container .entry-content > div.ore {
margin-bottom: 6px;
height: 0px;
}
.ore-dialog .ore-extra {
margin-left: 10px;
}
/* end body */
/* close button */
......
......@@ -50,7 +50,7 @@ class OREMain extends OREBase {
add_action('wp_ajax_nopriv_ore_username_check', array($this, 'ajax_username_check'));
// bypass the "Are you sure" log out confirmation
//add_action('check_admin_referer', array($this, 'logout_without_confirmation'), 10, 2);
add_action('wp_logout', array($this, 'process_logout'),10, 1);
//add_action('wp_logout', array($this, 'process_logout'),10, 1);
}
public function enqueue_scripts() {
......@@ -138,14 +138,14 @@ class OREMain extends OREBase {
// the function called after the ore-submit button is clicked in our form
public function ajax_submit() {
//$this->log('in ajax_submit: '.print_r($_POST, true));
$this->log('in ajax_submit: '.print_r($_POST, true));
// check if the submitted nonce matches the generated nonce created in the auth_init functionality
if ( ! wp_verify_nonce(sanitize_text_field($_POST['nonce_submit']), 'ore-submit-nonce') ) {
die (__("Drat and blast - someone's trying something funny in submit!", 'oeru-register-enrol'));
} else {
$this->log('ore-submit-nonce all good.');
}
//$this->log("processing submit form...");
$this->log("processing submit form...");
/*$this->log("sleeping briefly for debugging purposes");
sleep(5);
//$this->log("done sleeping");*/
......@@ -154,7 +154,7 @@ class OREMain extends OREBase {
$response = $this->process();
//$this->log('returned result of '.print_r($result, true));
if (!is_wp_error($response)) {
//$this->log('successfully completed '.$_POST['form_action']);
$this->log('successfully completed '.$_POST['form_action']);
$this->ajax_response(array('success' => $response));
} else {
//$this->log('We\'ve got an error!');
......@@ -175,8 +175,9 @@ class OREMain extends OREBase {
$response = $this->login();
break;
case 'log_out':
$this->log('logout');
$this->log('processing logout');
$response = $this->logout();
$this->log('logout response: '.print_r($response, true));
break;
case 'password_reset':
//$this->log('password_reset');
......@@ -203,11 +204,11 @@ class OREMain extends OREBase {
$response = $this->enrol();
break;
case 'leave':
//$this->log('leave');
$this->log('leave');
$response = $this->leave();
break;
default:
//$this->log('default action');
$this->log('default action');
break;
}
// if response isn't 'true'
......@@ -247,7 +248,8 @@ class OREMain extends OREBase {
//$this->log('login: '.print_r($login, true));
// if login fails
if (!is_wp_error($response)) {
$this->log('logged user out! Now redirecting back to last page');
$this->log('logged user out!');
/*$this->log('logged user out! Now redirecting back to last page');
$redirect = '';
if (isset($_REQUEST['redirect_to'])) {
$redirect = $_REQUEST['redirect_to'];
......@@ -255,8 +257,8 @@ class OREMain extends OREBase {
$redirect = "default_redirect";
}
$this->log('redirect = '.$redirect);
wp_safe_redirect($redirect);
wp_safe_redirect($redirect);*/
return true;
}
return $response;
}
......@@ -612,7 +614,7 @@ class OREMain extends OREBase {
// if not, proceed with creating the user!
} else {
$username = $user->data->user_login;
return $this->edit_existing_user($user_id, $username, $first, $last, $display, $exiting_email, $email, $country, $user);
return $this->edit_existing_user($user_id, $username, $first, $last, $display, $existing_email, $email, $country, $user);
}
}
}
......@@ -714,6 +716,7 @@ class OREMain extends OREBase {
}
// unenrol a user from a course
public function leave() {
$this->log('user '.$user_id.' leaving course '.$course_id);
$errors = $this->get_errors();
if (empty($_POST['user_id']) || empty($_POST['course_id'])) {
if (empty($_POST['user_id'])) {
......@@ -903,7 +906,7 @@ class OREMain extends OREBase {
// deal with the special case of the former menu items, now
// represented by dialogs
if ($index === 'visitor' || $index === 'authenticated') {
$this->log('getting info about $val: '.print_r($val, true));
//$this->log('getting info about $val: '.print_r($val, true));
continue;
}
//$markup = '<form class="ore-form dialog-body ore-body"><fieldset class="modal-content">';
......@@ -999,12 +1002,10 @@ class OREMain extends OREBase {
// bypass logout confirmation
// see
public function logout_without_confirmation($action, $result) {
/*public function logout_without_confirmation($action, $result) {
$this->redirect_counter++;
$this->log('another redirect... '.$this->redirect_counter);
$this->log('cookie info :'.print_r($_COOKIE, true));
/*$logout_status = get_query_var('logout');
$this->log('logout_status... '.$logout_status);*/
if ($action == "log-out" && is_user_logged_in()) {
$this->log('request array: '. print_r($_REQUEST, true));
if (isset($_REQUEST['redirect_to'])) {
......@@ -1037,5 +1038,5 @@ class OREMain extends OREBase {
public function process_logout($user_id) {
$this->log('process_logout: request array: ', print_r($_REQUEST, true));
$this->log("user $user_id has been logged out with URL: $url");
}
}*/
}
......@@ -95,7 +95,7 @@ $dialog_definitions = array(
'title' => __('Login successful', 'oeru-register-enrol'),
'token' => 'successful-login',
'purpose' => 'confirmation',
'markup' => '<p>'.__('You have successfully logged in as {display_name} ({username})', 'oeru-register-enrol').'</p>',
'markup' => '<p>'.__('You have successfully logged in as {display_name} ({username}) - please wait while we refresh the page.', 'oeru-register-enrol').'</p>',
'default' => array(
'label' => __('Ok', 'oeru-register-enrol'),
'class' => 'submit',
......
......@@ -34,7 +34,7 @@ jQuery(document).ready(function() {
//var inputs = ':input';
var container = $('#'+ore_data.container); // the container...
var trigger = $('.'+ore_data.trigger); // trigger for menu content
var status_link = null; // the DOM entity that contains the login status link
var status_link = $('#'+ore_data.login_status); // the DOM entity that contains the login status link
var last_focus = false; // what element had focus prior to the menu
var dialog = null;
var dialogs = ore_data.dialogs;
......@@ -301,7 +301,9 @@ jQuery(document).ready(function() {
LOG('using username instead ', ore_data.user.username);
$('#ore-label').text(ore_data.user.username);
}
$('#ore-login-modal').prop('title', ore_data.strings.login_message.replace('{{user.username}}', ore_data.user.username));
trigger.prop('title', ore_data.strings.login_message.replace('{{user.username}}', ore_data.user.username));
// required to make it a valid link, for keyboard navigation...
trigger.attr('href', '#');
if (ore_data.user.hasOwnProperty('avatar_url')) {
LOG('avatar', ore_data.user.avatar_url);
var avatar = $('<img>').attr({src: ore_data.user.avatar_url + '?s=26&r=g', class: 'ore-avatar'});
......@@ -315,7 +317,7 @@ jQuery(document).ready(function() {
msg = ore_data.strings.not_enrolled;
msg += '<span class="ore-unenrolled ore-course-status-indicator">&nbsp;</span>';
}
$('#ore-login-modal').append('<span class="ore-spacer">&nbsp;&raquo;&nbsp;</span><span id="ore-course-info" class="course-info">'+msg+'</span>');
trigger.append('<span class="ore-spacer">&nbsp;&raquo;&nbsp;</span><span id="ore-course-info" class="course-info">'+msg+'</span>');
}
}
......@@ -457,13 +459,18 @@ jQuery(document).ready(function() {
if (form.length == 1) {
LOG('form found: ', form);
form.each(function() {
LOG('setting rules and messages', validation[id]);
LOG('we have validation settings for '+ id);
LOG('applying to this form: ', $(this));
var validation_details = Object.assign({}, validation_defaults, validation[id]);
LOG('setting rules and messaging to ', validation_details);
$(this).validate(validation_details);
LOG('turn off submit button until valid...');
if (validation.hasOwnProperty(id)) {
LOG('setting rules and messages', validation[id]);
LOG('we have validation settings for '+ id);
LOG('applying to this form: ', $(this));
var validation_details = Object.assign({}, validation_defaults, validation[id]);
LOG('setting rules and messaging to ', validation_details);
set_validation_details(form, validation_details);
//$(this).validate(validation_details);
LOG('turn off submit button until valid...');
} else {
LOG('no validation for id: ',id)
}
});
} else if (form.length > 1) {
LOG('found too many forms!');
......@@ -552,34 +559,47 @@ jQuery(document).ready(function() {
function handle_action(action) {
LOG('current_dialog: ', current_dialog);
LOG('action: ', action);
var orig_action = action;
// check if there's a form that needs processing
if (action == 'log_out') {
LOG('logging user out');
log_out(action);
return;
}
}
if (process_form(action)) {
LOG('processed form for ', action);
return;
} else {
LOG('failed to processes form for ', action);
}
// if no form, or after it's processed, take further action
if (ore_data.dialogs.hasOwnProperty(action)) {
LOG('orig action '+orig_action+' and new action '+action);
if (create_dialog(action)) {
LOG('created '+action+' dialog');
} else {
LOG('failed to create '+action+' dialog');
}
} else {
LOG('unknown button clicked!');
}
//LOG('failed to processes form for ', action);
// if no form, or after it's processed, take further action
//return;
}
// get the current form, if any
function get_form() {
if (form = $(form_container).find(form_class)) { return form; }
else return false;
if (form = $(form_container).find(form_class)) {
LOG('found a stub form: ', form);
inputs = form.find(':input');
if (inputs.length) {
LOG('got some inputs! ', inputs.length);
} else {
LOG('no inputs in form');
}
return form;
}
return false;
}
// get the values from a form
......@@ -607,8 +627,7 @@ jQuery(document).ready(function() {
// get the purpose
function check_purpose(action, purpose) {
LOG('checking action: ', action);
LOG('checking for purpose: ', purpose);
LOG('checking action '+action+' and purpose '+purpose);
LOG('ore_data.dialogs: ', ore_data.dialogs);
//LOG('details of dialog: ', dialogs[action]);
LOG('ore_data.details of dialog: ', ore_data.dialogs[action]);
......@@ -625,21 +644,27 @@ jQuery(document).ready(function() {
// manage events
function process_form(action) {
LOG('processing form associated with action: ', action);
var special_data = null;
if (form = get_form()) {
LOG('got a form');
// if there's a form, get values from it
// some forms require additional state info to complete them...
var special_data = null;
if (action == 'enrol' || action == 'leave') {
LOG('setting special data for ', action);
special_data = {
'user_id': ore_data.user.user_id,
'course_id': ore_data.user.course.course_id,
'course_tag': ore_data.user.course.course_tag
};
} else if (check_purpose(action, 'confirmation')) {
close_dialog();
return true;
} else {
} else { // deal with general confirmation dialogs
if (check_purpose(action, 'confirmation')) {
LOG('purpose is confirmation! Closing dialog.');
close_dialog();
//clear_hash();
return true;
} else {
LOG('purpose is not confirmation');
}
if (special_data = get_form_values(form)) {
if (action == 'password_reset' ||
action == 'update_password' ||
......@@ -656,7 +681,13 @@ jQuery(document).ready(function() {
}
}
// if we've got a valid form... proceed.
if (form.valid() && special_data != null) {
valid_form = form.valid();
if (valid_form) {
LOG('form is valid...');
} else {
LOG('form is not valid!');
}
if (valid_form && special_data != null) {
LOG('form is valid');
// process the ajax call...
if (ajax_submit(action, special_data)) {
......@@ -675,10 +706,19 @@ jQuery(document).ready(function() {
LOG('form is not valid!');
}
return true;
} else {
} /*else {
if (check_purpose(action, 'confirmation')) {
LOG('no form - purpose is confirmation! Closing dialog.');
close_dialog();
clear_hash();
return true;
} else {
LOG('no form - purpose is not confirmation');
}
LOG('no form to process for ', action);
return false;
}
}*/
return false;
}
// replace country selector tag with country selector
......@@ -776,7 +816,7 @@ jQuery(document).ready(function() {
obj.forEach(function(value, key) {
//LOG('key: '+key+' val: '+String(value)+' needle: '+String(needle));
if (String(needle).trim() == String(value).trim()) {
LOG('strings are equal!');
//LOG('strings are equal!');
match = true;
}
})
......@@ -908,8 +948,9 @@ jQuery(document).ready(function() {
dialog.remove();
LOG('setting current_dialog to null');
current_dialog = "";
clear_hash();
if (hash != null) {
clear_hash();
LOG('setting hash to ', hash);
set_hash(hash);
}
}
......@@ -928,7 +969,7 @@ jQuery(document).ready(function() {
// and displaying error/status messages where relevant
function ajax_submit(action, special_data) {
LOG('in ajax_submission for', action);
LOG('url: ', ore_data.ajaxurl);
//LOG('url: ', ore_data.ajaxurl);
LOG('special_data: ', special_data);
default_data = {
'action': 'ore_submit',
......@@ -974,8 +1015,9 @@ jQuery(document).ready(function() {
LOG('redirecting to ', data.redirect_to);
window.location.href = data.redirect_to;
} else {
LOG('reloading the page: ', window.location.href);
window.location.reload();
LOG('reloading the same page...');
// no has specified
reload('');
}
}
// do special stuff for changes that have an impact on what
......@@ -1144,7 +1186,7 @@ jQuery(document).ready(function() {
current = window.location.href;
LOG('forcing reload of '+current);
window.location.reload();
if (hash == null) {
if (hash != null) {
LOG('setting hash to '+hash);
window.location.hash = hash;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment