<commit_before><?php

/**
 * This file is part of authchain, Laravel 4 chain authentication provider
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright <NAME> (c) 2013
 *
 **/

namespace Restricted\Authchain\Mapping;

use Illuminate\Auth\UserInterface;

/**
 * Class LdapMapping
 *
 * @package Restricted\Authchain\Mapping
 */
class LdapMapping
{
    /**
     * Windows Active Directory userAccountControl variables if user is locked
     *
     * @var array
     */
    protected $locked = array(
        "PASSWORD_EXPIRED"   => 8388608,
        "NOT_DELEGATED"      => 1048576,
        "SMARTCARD_REQUIRED" => 262144,
        "LOCKOUT"            => 514,
        "ACCOUNTDISABLE"     => 2
    );

    /**
     * Constructor. Sets mappings from config.
     *
     * @param $mappings
     */
    public function __construct($mappings)
    {
        $this->mappings = $mappings;
    }

    /**
     * Map ldap user to model
     *
     * @param array                   $ldap
     * @param UserInterface|\Eloquent $model
     *
     * @return mixed
     */
    public function map($ldap, UserInterface $model)
    {
        foreach ($this->mappings['fields'] as $field => $mapped) {
            if (!isset($ldap[$mapped])) {
                continue;
            }
            if ($mapped == 'userAccountControl') {
                if (!in_array($ldap[$mapped][0], $this->locked)) {
                    $ldap[$mapped][0] = true;
                } else {
                    $ldap[$mapped][0] = false;
                }
            }
            $model->$field = $ldap[$mapped][0];
        }
        $model->save();<commit_msg>[fix] Implement checking of required user fields<commit_after><?php

/**
 * This file is part of authchain, Laravel 4 chain authentication provider
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright <NAME> (c) 2013
 *
 **/

namespace Restricted\Authchain\Mapping;

use Illuminate\Auth\UserInterface;
use Restricted\Authchain\Config\Loader;

/**
 * Class LdapMapping
 *
 * @package Restricted\Authchain\Mapping
 */
class LdapMapping
{
    /**
     * Windows Active Directory userAccountControl variables if user is locked
     *
     * @var array
     */
    protected $locked = array(
        "PASSWORD_EXPIRED"   => 8388608,
        "NOT_DELEGATED"      => 1048576,
        "SMARTCARD_REQUIRED" => 262144,
        "LOCKOUT"            => 514,
        "ACCOUNTDISABLE"     => 2
    );
    /**
     * @var array
     */
    protected $mappings = array();

    /**
     * Constructor. Sets mappings from config.
     *
     * @param $mappings
     */
    public function __construct($mappings)
    {
        $this->mappings = $mappings;
    }

    /**
     * Map ldap user to model
     *
     * @param array                   $ldap
     * @param UserInterface|\Eloquent $model
     *
     * @return mixed
     */
    public function map($ldap, UserInterface $model)
    {
        if (!isset($ldap[strtolower($this->mappings['fields'][Loader::username()])])) {
            return false;
        }
        foreach ($this->mappings['fields'] as $field => $mapped) {
            $mapped = strtolower($mapped);
            if (!isset($ldap[$mapped])) {
                continue;
            }
            if ($mapped == 'useraccountcontrol') {
                if (!in_array($ldap[$mapped][0], $this->locked)) {
                    $ldap[$mapped][0] = true;
                } else {
                    $ldap[$mapped][0] = false;
                }
            }
            $model->$field = $ldap[$mapped][0];
        }
        $model->save();
{'fraction_non_alphanumeric': 0.13839662447257384, 'fraction_numerical': 0.018565400843881856, 'mean_word_length': 1.7759562841530054, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 34, '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': '4257070', 'n_tokens_mistral': 1129, 'n_tokens_neox': 1066, 'n_words': 228}