<commit_before><?php
/*
Plugin Name:        Proud Core
Plugin URI:         http://getproudcity.com
Description:        ProudCity distribution
Version:            1.0.0
Author:             ProudCity
Author URI:         http://getproudcity.com

License:            MIT License
License URI:        http://opensource.org/licenses/MIT
*/


namespace Proud\Core\ProudAuthentication;

class ProudAuthentication extends \ProudPlugin {

  function __construct() {

    $this->hook('init',  'checkAuthentication');

    add_action( 'init', array( $this, 'login_redirect' ) );
    //apply_filters( 'login_url', array( $this, 'pc_dashboard_login_url' ), 10, 3 );

  }

  /**
   * Filters any calls to wp_login_url() so they go to our dashboard
   *
   * @since 2022.05.05
   * @author <NAME>
   * @access public
   *
   * @todo could improve this by adding $redirect value that is parsed by the dashboard so the user goes back to where they were
   *
   * @param   $login_url      string        required              Existing login_url
   * @param   $redirect       string        optional              Path to redirect to after successful login
   * @param   $force_reauth   bool          optional              TRUE to force reauthorization even if login cookie is present
   */
  public static function pc_dashboard_login_url( $login_url, $redirect, $force_reauth ){
    return 'my.proudcity.com';
  }

  /**
   * Takes requests for wp-login.php and sends users to the PC Dashboard and my.proudcity.com
   *
   * Sends any type of request to wp-login.php to PC Dashboard. This includes any password reset
   * any logout...it's all going to PC Dashboard.
   *
   * @since 2022.05.05
   * @author <NAME>
   */
  public static function login_redirect(){

    global $pagenow;

    $excluded = array( 'https://www.colma.ca.gov' );

    /**
     * $_GET['connection_id'] corresponds to Auth0 so that we don't have fatal site errors
     */
    if ( ! isset( $_GET['connection_id'] ) && ! isset( $_GET['postpass'] )  && 'production' === wp_get_environment_type() && 'wp-login.php' === $pagenow && ! in_array( site_url(), $excluded ) ){
      wp_redirect( 'https://my.proudcity.com' );
      exit;
    } // if wp-login.php

  } // login_redirect

  // Do we need to put this behind an HTTP-auth wall, or redirect them to login to WordPress?
  public function checkAuthentication() {

    if (php_sapi_name() === "cli") {
      return;
    }

    $authRequired = getenv("AUTH_REQUIRED");
    if ($authRequired === 'wordpress') {

      global $wp;
      $current_url = home_url(add_query_arg(array(),$wp->request));

      if ( !is_user_logged_in() && empty($_GET['auth0']) && strpos($_SERVER['REQUEST_URI'], 'wp-login') === false && strpos($_SERVER['REQUEST_URI'], 'wp-admin') === false ) {
        header("Location: https://my.proudcity.com/login?msg=Please%20login%20to%20access%20your%20intranet"); //&destination=" . urlencode($current_url));
        exit;
      }
<commit_msg>Temporarily disable my.pc.com redirection on wp-login.php https://github.com/proudcity/wp-proudcity/issues/2078<commit_after><?php
/*
Plugin Name:        Proud Core
Plugin URI:         http://getproudcity.com
Description:        ProudCity distribution
Version:            1.0.0
Author:             ProudCity
Author URI:         http://getproudcity.com

License:            MIT License
License URI:        http://opensource.org/licenses/MIT
*/


namespace Proud\Core\ProudAuthentication;

class ProudAuthentication extends \ProudPlugin {

  function __construct() {

    $this->hook('init',  'checkAuthentication');

    add_action( 'init', array( $this, 'login_redirect' ) );
    //apply_filters( 'login_url', array( $this, 'pc_dashboard_login_url' ), 10, 3 );

  }

  /**
   * Filters any calls to wp_login_url() so they go to our dashboard
   *
   * @since 2022.05.05
   * @author <NAME>
   * @access public
   *
   * @todo could improve this by adding $redirect value that is parsed by the dashboard so the user goes back to where they were
   *
   * @param   $login_url      string        required              Existing login_url
   * @param   $redirect       string        optional              Path to redirect to after successful login
   * @param   $force_reauth   bool          optional              TRUE to force reauthorization even if login cookie is present
   */
  public static function pc_dashboard_login_url( $login_url, $redirect, $force_reauth ){
    return 'my.proudcity.com';
  }

  /**
   * Takes requests for wp-login.php and sends users to the PC Dashboard and my.proudcity.com
   *
   * Sends any type of request to wp-login.php to PC Dashboard. This includes any password reset
   * any logout...it's all going to PC Dashboard.
   *
   * @since 2022.05.05
   * @author <NAME>
   */
  public static function login_redirect(){

    global $pagenow;

    $excluded = array( 'https://www.colma.ca.gov' );

    /**
     * $_GET['connection_id'] corresponds to Auth0 so that we don't have fatal site errors
     */
    if ( ! isset( $_GET['connection_id'] ) && ! ( ! isset( $_GET['action'] ) || $_GET['action'] !== 'postpass' )  && 'production' === wp_get_environment_type() && 'wp-login.php' === $pagenow && ! in_array( site_url(), $excluded ) ){
      // wp_redirect( 'https://my.proudcity.com' );
      // exit;
    } // if wp-login.php

  } // login_redirect

  // Do we need to put this behind an HTTP-auth wall, or redirect them to login to WordPress?
  public function checkAuthentication() {

    if (php_sapi_name() === "cli") {
      return;
    }

    $authRequired = getenv("AUTH_REQUIRED");
    if ($authRequired === 'wordpress') {

      global $wp;
      $current_url = home_url(add_query_arg(array(),$wp->request));

      if ( !is_user_logged_in() && empty($_GET['auth0']) && strpos($_SERVER['REQUEST_URI'], 'wp-login') === false && strpos($_SERVER['REQUEST_URI'], 'wp-admin') === false ) {
        header("Location: https://my.proudcity.com/login?msg=Please%20login%20to%20access%20your%20intranet"); //&destination=" . urlencode($current_url));
        exit;
      }

{'fraction_non_alphanumeric': 0.13245469522240527, 'fraction_numerical': 0.01186161449752883, 'mean_word_length': 2.8375474083438683, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 7, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '131751', 'n_tokens_mistral': 1918, 'n_tokens_neox': 1849, 'n_words': 510}