<commit_before><?php namespace ZN\IndividualStructures\User;

use Encode, DB, Method, Session, Cookie;

class Login extends UserExtends implements LoginInterface
{
    //--------------------------------------------------------------------------------------------------------
    // Username
    //--------------------------------------------------------------------------------------------------------
    //
    // @param  string $username
    // @return this
    //
    //--------------------------------------------------------------------------------------------------------
    public function username(String $username) : Login
    {
        Properties::$parameters['username'] = $username;

        return $this;
    }

    //--------------------------------------------------------------------------------------------------------
    // Password
    //--------------------------------------------------------------------------------------------------------
    //
    // @param  string $password
    // @return this
    //
    //--------------------------------------------------------------------------------------------------------
    public function password(String $password) : Login
    {
        Properties::$parameters['password'] = $password;

        return $this;
    }

    //--------------------------------------------------------------------------------------------------------
    // Remember
    //--------------------------------------------------------------------------------------------------------
    //
    // @param  bool $remember
    // @return this
    //
    //--------------------------------------------------------------------------------------------------------
    public function remember(Bool $remember = true) : Login
    {
        Properties::$parameters['remember'] = $remember;

        return $this;
    }

    //--------------------------------------------------------------------------------------------------------
    // Login
    //--------------------------------------------------------------------------------------------------------
    //
    // @param  string $un
    // @param  string $pw
    // @param  bool   $rememberMe
    // @return bool
    //
    //--------------------------------------------------------------------------------------------------------
    public function do(String $un = NULL, String $pw = NULL, $rememberMe = false) : Bool
    {
        $un         = Properties::$parameters['username'] ?? $un;
        $pw         = Properties::$parameters['password'] ?? $pw;
        $rememberMe = Properties::$parameters['remember'] ?? $rememberMe;

        Properties::$parameters = [];

        if( ! is_scalar($rememberMe) )
        {
            $rememberMe = false;
        }

        $username   = $un;
        $encodeType = INDIVIDUALSTRUCTURES_USER_CONFIG['encode'];

        $password   = ! empty($encodeType) ? Encode::type($pw, $encodeType) : $pw;

        // ------------------------------------------------------------------------------
        // Settings
        // ------------------------------------------------------------------------------
        $tableName          = INDIVIDUALSTRUCTURES_USER_CONFIG['matching']['table'];
        $getColumns         = INDIVIDUALSTRUCTURES_USER_CONFIG['matching']['columns'];
        $passwordColumn     = $getColumns['password'];
        $usernameColumn     = $getColumns['username'];
        $emailColumn        = $getColumns['email'];
        $bannedColumn       = $getColumns['banned'];
        $activeColumn       = $getColumns['active'];
        $activationColumn   = $getColumns['activation'];
        // ------------------------------------------------------------------------------

        $r = DB::where($usernameColumn, $username)
               ->get($tableName)
               ->row();

        if( ! isset($r->$passwordColumn) )
        {
            return ! $this->error = lang('IndividualStructures', 'user:loginError');
        }

        $passwordControl   = $r->$passwordColumn;
        $bannedControl     = '';
        $activationControl = '';

        if( ! empty($bannedColumn) )
        {
            $banned = $bannedColumn ;
            $bannedControl = $r->$banned ;
        }

        if( ! empty($activationColumn) )
        {
            $activationControl = $r->$activationColumn ;
        }

        if( ! empty($r->$usernameColumn) && $passwordControl == $password )
        {
            if( ! empty($bannedColumn) && ! empty($bannedControl) )
            {
                return ! $this->error = lang('IndividualStructures', 'user:bannedError');
            }

            if( ! empty($activationColumn) && empty($activationControl) )
            {
                return ! $this->error = lang('IndividualStructures', 'user:activationError');
            }

            Session::insert($usernameColumn, $username);
            Session::insert($passwordColumn, $password);

            if( Method::post($rememberMe) || ! empty($rememberMe) )
            {
                if( Cookie::select($usernameColumn) != $username )
                {
                    Cookie::insert($usernameColumn, $username);
                    Cookie::insert($passwordColumn, $password);
                }
            }

            if( ! empty($activeColumn) )
            {
                DB::where($usernameColumn, $username)->update($tableName, [$activeColumn  => 1]);
            }

            return $this->success = lang('IndividualStructures', 'user:loginSuccess');
        }
        else
        {
            return ! $this->error = lang('IndividualStructures', 'user:loginError');
        }
    }

    //--------------------------------------------------------------------------------------------------------
    // Is Login
    //--------------------------------------------------------------------------------------------------------
    //
    // @param  void
    // @return bool
    //
    //--------------------------------------------------------------------------------------------------------
    public function is() : Bool
    {
        $getColumns = INDIVIDUALSTRUCTURES_USER_CONFIG['matching']['columns'];
        $tableName  = INDIVIDUALSTRUCTURES_USER_CONFIG['matching']['table'];
        $username   = $getColumns['username'];
        $password   = $getColumns['password'];

        $cUsername  = Cookie::select($username);
        $cPassword  = Cookie::select($password);

        $result     = NULL;

        if( ! empty($cUsername) && ! empty($cPassword) )
        {
            $result = DB::where($username, $cUsername, 'and')
                        ->where($password, $cPassword)
                        ->get($tableName)
                        ->totalRows();
        }

        if( isset(Factory::class('Data')->get($tableName)->$username) )
        {
            $isLogin = true;
        }
        elseif( ! empty($result) )
        {
            Session::insert($username, $cUsername);

            $isLogin = true;
        }
        else
        {
            $isLogin = false;
        }

        return $isLogin;
    }
}<commit_msg>Updated User Libraries<commit_after><?php namespace ZN\IndividualStructures\User;

use Encode, DB, Method, Session, Cookie;

class Login extends UserExtends implements LoginInterface
{
    //--------------------------------------------------------------------------------------------------------
    // Username
    //--------------------------------------------------------------------------------------------------------
    //
    // @param  string $username
    // @return this
    //
    //--------------------------------------------------------------------------------------------------------
    public function username(String $username) : Login
    {
        Properties::$parameters['username'] = $username;

        return $this;
    }

    //--------------------------------------------------------------------------------------------------------
    // Password
    //--------------------------------------------------------------------------------------------------------
    //
    // @param  string $password
    // @return this
    //
    //--------------------------------------------------------------------------------------------------------
    public function password(String $password) : Login
    {
        Properties::$parameters['password'] = $password;

        return $this;
    }

    //--------------------------------------------------------------------------------------------------------
    // Remember
    //--------------------------------------------------------------------------------------------------------
    //
    // @param  bool $remember
    // @return this
    //
    //--------------------------------------------------------------------------------------------------------
    public function remember(Bool $remember = true) : Login
    {
        Properties::$parameters['remember'] = $remember;

        return $this;
    }

    //--------------------------------------------------------------------------------------------------------
    // Login
    //--------------------------------------------------------------------------------------------------------
    //
    // @param  string $un
    // @param  string $pw
    // @param  bool   $rememberMe
    // @return bool
    //
    //--------------------------------------------------------------------------------------------------------
    public function do(String $un = NULL, String $pw = NULL, $rememberMe = false) : Bool
    {
        $un         = Properties::$parameters['username'] ?? $un;
        $pw         = Properties::$parameters['password'] ?? $pw;
        $rememberMe = Properties::$parameters['remember'] ?? $rememberMe;

        Properties::$parameters = [];

        if( ! is_scalar($rememberMe) )
        {
            $rememberMe = false;
        }

        $username   = $un;
        $encodeType = INDIVIDUALSTRUCTURES_USER_CONFIG['encode'];

        $password   = ! empty($encodeType) ? Encode::type($pw, $encodeType) : $pw;

        // ------------------------------------------------------------------------------
        // Settings
        // ------------------------------------------------------------------------------
        $tableName          = INDIVIDUALSTRUCTURES_USER_CONFIG['matching']['table'];
        $getColumns         = INDIVIDUALSTRUCTURES_USER_CONFIG['matching']['columns'];
        $passwordColumn     = $getColumns['password'];
        $usernameColumn     = $getColumns['username'];
        $emailColumn        = $getColumns['email'];
        $bannedColumn       = $getColumns['banned'];
        $activeColumn       = $getColumns['active'];
        $activationColumn   = $getColumns['activation'];
        // ------------------------------------------------------------------------------

        $r = DB::where($usernameColumn, $username)
               ->get($tableName)
               ->row();

        if( ! isset($r->$passwordColumn) )
        {
            return ! $this->error = lang('IndividualStructures', 'user:loginError');
        }

        $passwordControl   = $r->$passwordColumn;
        $bannedControl     = '';
        $activationControl = '';

        if( ! empty($bannedColumn) )
        {
            $banned = $bannedColumn ;
            $bannedControl = $r->$banned ;
        }

        if( ! empty($activationColumn) )
        {
            $activationControl = $r->$activationColumn ;
        }

        if( ! empty($r->$usernameColumn) && $passwordControl == $password )
        {
            if( ! empty($bannedColumn) && ! empty($bannedControl) )
            {
                return ! $this->error = lang('IndividualStructures', 'user:bannedError');
            }

            if( ! empty($activationColumn) && empty($activationControl) )
            {
                return ! $this->error = lang('IndividualStructures', 'user:activationError');
            }

            Session::insert($usernameColumn, $username);
            Session::insert($passwordColumn, $password);

            if( Method::post($rememberMe) || ! empty($rememberMe) )
            {
                if( Cookie::select($usernameColumn) !== $username )
                {
                    Cookie::insert($usernameColumn, $username);
                    Cookie::insert($passwordColumn, $password);
                }
            }

            if( ! empty($activeColumn) )
            {
                DB::where($usernameColumn, $username)->update($tableName, [$activeColumn  => 1]);
            }

            return $this->success = lang('IndividualStructures', 'user:loginSuccess');
        }
        else
        {
            return ! $this->error = lang('IndividualStructures', 'user:loginError');
        }
    }

    //--------------------------------------------------------------------------------------------------------
    // Is Login
    //--------------------------------------------------------------------------------------------------------
    //
    // @param  void
    // @return bool
    //
    //--------------------------------------------------------------------------------------------------------
    public function is() : Bool
    {
        $getColumns = INDIVIDUALSTRUCTURES_USER_CONFIG['matching']['columns'];
        $tableName  = INDIVIDUALSTRUCTURES_USER_CONFIG['matching']['table'];
        $username   = $getColumns['username'];
        $password   = $getColumns['password'];

        $cUsername  = Cookie::select($username);
        $cPassword  = Cookie::select($password);

        $result     = NULL;

        if( ! empty($cUsername) && ! empty($cPassword) )
        {
            $result = DB::where($username, $cUsername, 'and')
                        ->where($password, $cPassword)
                        ->get($tableName)
                        ->totalRows();
        }

        if( isset(Factory::class('Data')->get($tableName)->$username) )
        {
            $isLogin = true;
        }
        elseif( ! empty($result) )
        {
            Session::insert($username, $cUsername);
            Session::insert($password, $cPassword);

            $isLogin = true;
        }
        else
        {
            $isLogin = false;
        }

        return $isLogin;
    }
}
{'fraction_non_alphanumeric': 0.3611383023353377, 'fraction_numerical': 0.00013984058173682003, 'mean_word_length': 0.8871882834146985, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, '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': '3430819', 'n_tokens_mistral': 3058, 'n_tokens_neox': 2900, 'n_words': 496}