<commit_before><?php
/**
 * No Authentication
 * 
 * Will only run in an environment set to TESTING
 * Doesn't require any authentication - the desired user is chosen from a list
 * 
 */
namespace Jazzee\AdminAuthentication;
class NoAuthentication implements \Jazzee\Interfaces\AdminAuthentication{
  const LOGIN_ELEMENT = 'NoAuthentication_Login';
  
  const SESSION_VAR_ID = 'noauth_userid';
  /**
   * Our user
   * @var \Jazzee\Entity\User
   */
  private $_user;
  
  /**
   * Config instance
   * @var \Jazzee\Controller 
   */
  private $_controller;
  
  /**
   * Login form
   * @var \Foundation\Form
   */
  private $_form;
  
  /**
   * Constructor
   * 
   * Grab the desired user from the configuration file and log in as them
   * @param \Jazzee\Interfaces\AdminController
   */
  public function __construct(\Jazzee\Interfaces\AdminController $controller){
    $this->_controller = $controller;
    if($controller->getConfig()->getStatus() != 'DEVELOPMENT'){
      throw new \Jazzee\Exception('Attmpted to use NoAuthentication in a non development environment.');
    }
    if($this->_controller->getStore()->check(self::SESSION_VAR_ID)){
      $this->_user = $this->_controller->getEntityManager()->getRepository('\Jazzee\Entity\User')->find($this->_controller->getStore()->get(self::SESSION_VAR_ID));
    }
  }
  
  public function isValidUser(){
    return (bool)$this->_user;
  }
  
  public function getUser(){
    return $this->_user;
  }
  
  public function loginUser(){
    $form = $this->getLoginForm();
    if($input = $form->processInput($_POST)){
      $allowedIps = explode(',', $this->_controller->getConfig()->getNoAuthIpAddresses());
      if(in_array($_SERVER['REMOTE_ADDR'], $allowedIps)){
        $this->_user = $this->_controller->getEntityManager()->getRepository('\Jazzee\Entity\User')->findOneBy(array('id'=>$_POST['userid'], 'isActive'=>true));
        $this->_controller->getStore()->expire();
        $this->_controller->getStore()->touchAuthentication();
        $this->_controller->getStore()->set(self::SESSION_VAR_ID, $this->_user->getId());
      }
    }
  }
  
  /**
   * Get the login form
   * 
   * @return \Foundation\Form 
   */
  public function getLoginForm(){<commit_msg>When NoAuthentication doesn't match an IP address throw exception so the problem can be seen.<commit_after><?php
/**
 * No Authentication
 * 
 * Will only run in an environment set to TESTING
 * Doesn't require any authentication - the desired user is chosen from a list
 * 
 */
namespace Jazzee\AdminAuthentication;
class NoAuthentication implements \Jazzee\Interfaces\AdminAuthentication{
  const LOGIN_ELEMENT = 'NoAuthentication_Login';
  
  const SESSION_VAR_ID = 'noauth_userid';
  /**
   * Our user
   * @var \Jazzee\Entity\User
   */
  private $_user;
  
  /**
   * Config instance
   * @var \Jazzee\Controller 
   */
  private $_controller;
  
  /**
   * Login form
   * @var \Foundation\Form
   */
  private $_form;
  
  /**
   * Constructor
   * 
   * Grab the desired user from the configuration file and log in as them
   * @param \Jazzee\Interfaces\AdminController
   */
  public function __construct(\Jazzee\Interfaces\AdminController $controller){
    $this->_controller = $controller;
    if($controller->getConfig()->getStatus() != 'DEVELOPMENT'){
      throw new \Jazzee\Exception('Attmpted to use NoAuthentication in a non development environment.');
    }
    if($this->_controller->getStore()->check(self::SESSION_VAR_ID)){
      $this->_user = $this->_controller->getEntityManager()->getRepository('\Jazzee\Entity\User')->find($this->_controller->getStore()->get(self::SESSION_VAR_ID));
    }
  }
  
  public function isValidUser(){
    return (bool)$this->_user;
  }
  
  public function getUser(){
    return $this->_user;
  }
  
  public function loginUser(){
    $form = $this->getLoginForm();
    if($input = $form->processInput($_POST)){
      $allowedIps = explode(',', $this->_controller->getConfig()->getNoAuthIpAddresses());
      if(in_array($_SERVER['REMOTE_ADDR'], $allowedIps)){
        $this->_user = $this->_controller->getEntityManager()->getRepository('\Jazzee\Entity\User')->findOneBy(array('id'=>$_POST['userid'], 'isActive'=>true));
        $this->_controller->getStore()->expire();
        $this->_controller->getStore()->touchAuthentication();
        $this->_controller->getStore()->set(self::SESSION_VAR_ID, $this->_user->getId());
      } else {
        throw new \Jazzee\Exception("{$_SERVER['REMOTE_ADDR']} is not a valid ip address for NoAuthentication.  Add it to the noAuthIpAddresses configuration to continue.");
      }
    }
  }
  
  /**
   * Get the login form
   * 
   * @return \Foundation\Form 
   */
  public function getLoginForm(){
{'fraction_non_alphanumeric': 0.152868939233538, 'fraction_numerical': 0.0, 'mean_word_length': 3.599805258033106, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3102489', 'n_tokens_mistral': 1435, 'n_tokens_neox': 1396, 'n_words': 293}