/** * @todo DRY, same error message thrown thrice. * * @param $ga * * @return string */ function gad_request_error_type($ga) { if ($ga->isError()) { if ($ga->isAuthError()) { if (get_option('gad_auth_token') == 'gad_see_oauth') { if (current_user_can('manage_options')) { printf(__('You need to log in and select an account in the %s$1options panel%s$2.', 'google-analytics-dashboard'), '<a href="options-general.php?page=google-analytics-dashboard/gad-admin-options.php">', '</a>'); } else { _e('The administrator needs to log in and select a Google Analytics account.', 'google-analytics-dashboard'); } return 'perm'; } if (get_option('gad_login_pass') === false || get_option('gad_login_email') === false) { if (current_user_can('manage_options')) { printf(__('You need to log in and select an account in the %s$1options panel%s$2.', 'google-analytics-dashboard'), '<a href="options-general.php?page=google-analytics-dashboard/gad-admin-options.php">', '</a>'); } else { _e('The administrator needs to log in and select a Google Analytics account.', 'google-analytics-dashboard'); } return 'perm'; } else { $gauth = new GAuthLib('wpga-display-1.0'); $gauth->authenticate(get_option('gad_login_email'), get_option('gad_login_pass'), get_option('gad_services')); if ($gauth->isError()) { $error_message = $gauth->getErrorMessage(); if (current_user_can('manage_options')) { printf(__('You need to log in and select an account in the %s$1options panel%s$2.', 'google-analytics-dashboard'), '<a href="options-general.php?page=google-analytics-dashboard/gad-admin-options.php">', '</a>'); } else { _e('The administrator needs to log in and select a Google Analytics account.', 'google-analytics-dashboard'); } return 'perm'; } else { delete_option('gad_auth_token'); add_option('gad_auth_token', $gauth->getAuthToken()); $ga->setAuth($gauth->getAuthToken()); return 'retry'; } } } else { echo __('Error gathering analytics data from Google: ', 'google-analytics-dashboard') . strip_tags($ga->getErrorMessage()); return 'perm'; } } else { return 'none'; } }
function admin_handle_clientlogin_login_options(&$ui, $info_message = '') { if (!isset($_POST['ga_email']) || trim($_POST['ga_email']) == '') { $error_message = "Email is required"; } else { if (!isset($_POST['ga_pass']) || $_POST['ga_pass'] == '') { $error_message = "Password is required"; } else { add_option('gad_login_email', $_POST['ga_email']); if (isset($_POST['ga_save_pass'])) { add_option('gad_login_pass', $_POST['ga_pass']); } else { delete_option('gad_login_pass', $_POST['ga_pass']); } $gauth = new GAuthLib('wpga-display-1.0'); if (isset($_POST['ga_captcha_token']) && isset($_POST['ga_captcha'])) { $gauth->authenticate($_POST['ga_email'], $_POST['ga_pass'], get_option('gad_services'), $_POST['ga_captcha_token'], $_POST['ga_captcha']); } else { $gauth->authenticate($_POST['ga_email'], $_POST['ga_pass'], get_option('gad_services')); } if ($gauth->isError()) { $error_message = $gauth->getErrorMessage(); } else { add_option('gad_auth_token', $gauth->getAuthToken()); $this->admin_plugin_options('Login successful.'); return true; } } } $ui->info_message = $info_message; $ui->error_message = $error_message; return false; }