public static function do_signin_content_user($user_name, $password) { $login_data = array(); $login_data['user_login'] = $user_name; $login_data['user_password'] = $password; // 1. Verify that the user name exists in the system $user_party_data = EntityAPI::get_by_field('party', 'user_name', $user_name); if (!isset($user_party_data['id'])) { return EntityAPIUtils::init_error($login_data, 'Invalid username or password. Please try again'); } // 2. Ensure the account is active $profile_data = EntityAPI::get_by_field('partyprofile', 'profile_party', $user_party_data['id']); if (!isset($profile_data['id'])) { return EntityAPIUtils::init_error($user_party_data, 'Profile not found'); } if ($profile_data['profile_status'] != 'A') { return EntityAPIUtils::init_error($user_party_data, 'You account has been deactivated please contact support on ' . get_option('cp_notify_accounts')); } $user_verify = wp_signon($login_data, true); if (is_wp_error($user_verify)) { return EntityAPIUtils::init_error($login_data, 'Invalid username or password. Please try again'); } wp_set_current_user($user_verify->ID); wp_set_auth_cookie($user_verify->ID); // Build the return $content_user = array('user_login' => $user_name, 'user_password' => $password); // Process redirect if (isset($_POST['redirect_to'])) { $content_user['redirect_url'] = $_POST['redirect_to']; } return array('has_errors' => false, 'content_user' => $content_user); }
/** * */ public static function do_edit_entity($entity_data) { // First check if the user exists $display_name = $entity_data['display_name']; $entity_data = EntityAPI::do_create_entity($entity_data); if (!isset($entity_data['id'])) { return EntityAPIUtils::init_error($entity_data, 'Could not update party'); } $entity_data['display_name'] = $display_name; PartyProfileAPI::do_edit_party_profile($entity_data); BillingAccountAPI::do_edit_billing_account($entity_data); return $entity_data; }
/** * */ public static function edit_individual($content_user_data, $party_data) { $entity_data = EntityAPI::get_by_field('person', 'person_party', $party_data['id']); if (!isset($entity_data['id'])) { return EntityAPIUtils::init_error($content_user_data, 'Could not find the specified individual'); } $entity_data['edit_mode'] = false; $entity_data['email'] = $content_user_data['user_login']; $entity_data['last_name'] = $content_user_data['last_name']; $entity_data['first_name'] = $content_user_data['first_name']; if (isset($content_user_data['description'])) { $entity_data['description'] = $content_user_data['description']; } if (isset($content_user_data['display_name'])) { $entity_data['display_name'] = $content_user_data['display_name']; } $entity_data = PartyAPI::do_edit_individual($entity_data, $party_data); return $entity_data; }
/** * */ public static function do_create_entity($entity_data) { // First check if the user exists if ($entity_data['edit_mode']) { if (UserPartyAPI::does_party_exist($entity_data['user_name'])) { return EntityAPIUtils::init_error($entity_data, 'Party with the specified user name already exists'); } } $party_role = $entity_data['role']; $display_name = $entity_data['display_name']; $entity_data = EntityAPI::do_create_entity($entity_data); if (isset($entity_data['id'])) { $entity_data['display_name'] = $display_name; PartyProfileAPI::do_create_party_profile($entity_data); BillingAccountAPI::do_create_billing_account($entity_data); PartyRoleAPI::add_role_to_party($entity_data, $party_role); } return $entity_data; }