| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) die('No direct access allowed.'); |
| 4 |
|
| 5 |
if (!class_exists('UpdraftPlus_Login')) require_once('updraftplus-login.php'); |
| 6 |
|
| 7 |
class UpdraftPlus_UpdraftCentral_Cloud extends UpdraftPlus_Login { |
| 8 |
|
| 9 |
/** |
| 10 |
* Pulls the appropriate message for the given code and translate it before |
| 11 |
* returning it to the caller |
| 12 |
* |
| 13 |
* @internal |
| 14 |
* @param string $code The code of the message to pull |
| 15 |
* @return string - The translated message |
| 16 |
*/ |
| 17 |
protected function translate_message($code) { |
| 18 |
switch ($code) { |
| 19 |
case 'generic': |
| 20 |
default: |
| 21 |
return __('An error has occurred while processing your request.', 'updraftplus').' '.__('The server might be busy or you have lost your connection to the internet at the time of the request.', 'updraftplus').' '.__('Please try again later.', 'updraftplus'); |
| 22 |
break; |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Executes login or registration process. Connects and sends request to the UpdraftCentral Cloud |
| 28 |
* and returns the response coming from the server |
| 29 |
* |
| 30 |
* @internal |
| 31 |
* @param array $data The submitted form data |
| 32 |
* @param boolean $register Indicates whether the current call is for a registration process or not. Defaults to false. |
| 33 |
* @return array - The response from the request |
| 34 |
*/ |
| 35 |
protected function login_or_register($data, $register = false) { |
| 36 |
global $updraftplus, $updraftcentral_main; |
| 37 |
|
| 38 |
$action = ($register) ? 'updraftcentral_cloud_register' : 'updraftcentral_cloud_login'; |
| 39 |
if (empty($data['site_url'])) $data['site_url'] = trailingslashit(network_site_url()); |
| 40 |
|
| 41 |
$response = $this->send_remote_request($data, $action); |
| 42 |
if (is_wp_error($response)) { |
| 43 |
$response = array('error' => true, 'code' => $response->get_error_code(), 'message' => $response->get_error_message()); |
| 44 |
} else { |
| 45 |
if (isset($response['status'])) { |
| 46 |
if (in_array($response['status'], array('authenticated', 'registered'))) { |
| 47 |
$response['redirect_url'] = $updraftplus->get_url('mothership').'/?udm_action=updraftcentral_cloud_redirect'; |
| 48 |
|
| 49 |
if (is_a($updraftcentral_main, 'UpdraftCentral_Main')) { |
| 50 |
$response['keys_table'] = $updraftcentral_main->get_keys_table(); |
| 51 |
} |
| 52 |
|
| 53 |
if (!empty($data['addons_options_connect']) && class_exists('UpdraftPlus_Options')) { |
| 54 |
UpdraftPlus_Options::update_updraft_option('updraftplus_com_and_udc_connection_success', 1, false); |
| 55 |
} |
| 56 |
|
| 57 |
} else { |
| 58 |
if ('error' === $response['status']) { |
| 59 |
$message = isset($response['message']) ? $response['message'] : $this->translate_message('generic'); |
| 60 |
|
| 61 |
if (isset($response['code']) && 'incorrect_password' === $response['code']) { |
| 62 |
$message = __("Your email is valid, but your password wasn't recognised.", 'updraftplus').'<br>'; |
| 63 |
if (time() < strtotime('2026-01-01 00:00:00')) $message .= __('Some users were asked to reset their passwords as part of a recent website migration.', 'updraftplus').'<br>'; |
| 64 |
// translators: %s: The reset password link |
| 65 |
$message .= sprintf(__('Try again, or %s before connecting again.', 'updraftplus'), '<a href="'.$updraftplus->get_url('lost-password').'">'.__('reset your password', 'updraftplus').'</a>'); |
| 66 |
} |
| 67 |
|
| 68 |
$response = array( |
| 69 |
'error' => true, |
| 70 |
'code' => isset($response['code']) ? $response['code'] : -1, |
| 71 |
'message' => $message, |
| 72 |
'response' => $response |
| 73 |
); |
| 74 |
} |
| 75 |
} |
| 76 |
} else { |
| 77 |
$response = array('error' => true, 'message' => $this->translate_message('generic')); |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
return $response; |
| 82 |
} |
| 83 |
} |
| 84 |
|