Classes

File phpboost/user/authentication/AuthenticationMethod.class.php

File phpboost/user/authentication/AuthenticationMethod.class.php

  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 
<?php
/**
 * The AuthenticationMethod interface could be implemented in different ways to enable specifics
 * authentication mecanisms.
 * PHPBoost comes with a PHPBoostAuthenticationMethod which will be performed on the internal member
 * list. But it is possible to implement external authentication mecanism by providing others
 * implementations of this class to support LDAP authentication, OpenID, Facebook connect and more...
 * @package     PHPBoost
 * @subpackage  User\authentication
 * @copyright   &copy; 2005-2019 PHPBoost
 * @license     https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL-3.0
 * @author      Loic ROUCHON <horn@phpboost.com>
 * @version     PHPBoost 5.2 - last update: 2018 04 10
 * @since       PHPBoost 3.0 - 2010 11 28
 * @contributor Julien BRISWALTER <j1.seth@phpboost.com>
*/

abstract class AuthenticationMethod
{
    protected $error_msg;

    /**
     * associate the current authentication method with the given user_id.
     * @param int $user_id
     * @throws IllegalArgumentException if the user_id is already associate with an authentication method
     */
    abstract public function associate($user_id);

    /**
     * dissociate the current authentication method with the given user_id.
     * @param int $user_id
     * @throws IllegalArgumentException if the user_id is already dissociate with an authentication method
     */
    abstract public function dissociate($user_id);

    /**
     * Tries to authenticate the user and returns true on success, false otherwise.
     * @return int $user_id, if authentication has been performed successfully
     */
    abstract public function authenticate();

    public function has_error()
    {
        return !empty($this->error_msg);
    }

    public function get_error_msg()
    {
        return $this->error_msg;
    }

    protected function check_user_bannishment($user_id)
    {
        $infos = array();
        try {
            $infos = PersistenceContext::get_querier()->select_single_row(DB_TABLE_MEMBER, array('warning_percentage', 'delay_banned'), 'WHERE user_id=:user_id', array('user_id' => $user_id));
        } catch (RowNotFoundException $e) {
        }

        if (!empty($infos) && $infos['warning_percentage'] == 100)
            $this->error_msg = LangLoader::get_message('e_member_ban_w', 'errors');
        else if (!empty($infos) && $infos['delay_banned'])
        {
            $delay_ban = (time() - $infos['delay_banned']); //Vérification si le membre est banni.
            $delay = ceil((0 - $delay_ban)/60);
            if ($delay > 0)
            {
                $date_lang = LangLoader::get('date-common');

                if ($delay < 60)
                    $this->error_msg = LangLoader::get_message('e_member_ban', 'errors') . ' ' . $delay . ' ' . (($delay > 1) ? $date_lang['minutes'] : $date_lang['minute']);
                elseif ($delay < 1440)
                {
                    $delay_ban = NumberHelper::round($delay/60, 0);
                    $this->error_msg = LangLoader::get_message('e_member_ban', 'errors') . ' ' . $delay_ban . ' ' . (($delay_ban > 1) ? $date_lang['hours'] : $date_lang['hour']);
                }
                elseif ($delay < 10080)
                {
                    $delay_ban = NumberHelper::round($delay/1440, 0);
                    $this->error_msg = LangLoader::get_message('e_member_ban', 'errors') . ' ' . $delay_ban . ' ' . (($delay_ban > 1) ? $date_lang['days'] : $date_lang['day']);
                }
                elseif ($delay < 43200)
                {
                    $delay_ban = NumberHelper::round($delay/10080, 0);
                    $this->error_msg = LangLoader::get_message('e_member_ban', 'errors') . ' ' . $delay_ban . ' ' . (($delay_ban > 1) ? $date_lang['weeks'] : $date_lang['week']);
                }
                elseif ($delay < 525600)
                {
                    $delay_ban = NumberHelper::round($delay/43200, 0);
                    $this->error_msg = LangLoader::get_message('e_member_ban', 'errors') . ' ' . $delay_ban . ' ' . (($delay_ban > 1) ? $date_lang['months'] : $date_lang['month']);
                }
                else
                {
                    $this->error_msg = LangLoader::get_message('e_member_ban_w', 'errors');
                }
            }
        }
    }

    protected function update_user_last_connection_date($user_id)
    {
        PersistenceContext::get_querier()->update(DB_TABLE_MEMBER, array('last_connection_date' => time()), 'WHERE user_id=:user_id', array('user_id' => $user_id));
    }
}
?>