Location: PHPKode > projects > Gnew > Gnew-2013.1/users/login.php
<?php
// -----------------------------------------------------------------------------
// $Id: login.php 644 2013-03-22 12:54:09Z raoul $
//
// Copyright (C) 2013 Raoul Proença
// License: GNU GPL version 3 (see copying.txt file)
// Website: http://www.gnew.fr/
// -----------------------------------------------------------------------------
// This program is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation, either version 3 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program. If not, see <http://www.gnu.org/licenses/>.
// -----------------------------------------------------------------------------

include('./../includes/common.php');

page_header($lang['USERS_LOGIN']);

// User logged?
if ($_SESSION['user_id'] > 0)
{
    error_template($lang['ERROR_USER_ONLINE']);
}
else
{
    // From login form?
    if (isset($_POST['login']))
    {
        $sql->query('SELECT user_id, user_key, user_level
                     FROM ' . TABLE_USERS . '
                     WHERE user_name = \'' . utf8_entities($_POST['user_name']) . '\'
                     AND user_password = \'' . sha1(utf8_entities($_POST['user_password'])) . '\'');
        $table_users = $sql->fetch();
        // Check user
        if (!$table_users['user_id'])
        {
            error_template($lang['ERROR_ID_MATCH']);
        }
        // Active account?
        elseif ($table_users['user_key'] != 0)
        {
            error_template($lang['ERROR_ACCOUNT_DISABLED']);
        }
        // Banned user?
        elseif ($table_users['user_level'] == 0)
        {
            error_template($lang['ERROR_USER_DISABLED']);
        }
        else
        {
            // Moderator?
            if ($table_users['user_level'] > 1)
            {
                $_SESSION['check_version'] = 0;
            }
            $sql->query('UPDATE ' . TABLE_USERS . '
                         SET user_ip = \'' . $_SERVER['REMOTE_ADDR'] . '\'
                         WHERE user_id = \'' . $table_users['user_id'] . '\'');
            $_SESSION['user_id'] = (integer) $table_users['user_id'];
            // For the time being user_ip is not displayed
            // $GLOBALS['cache']->clean(TABLE_USERS);
            success_template($lang['USER_ONLINE'], './../index.php');
        }
    }
    // Login form
    else
    {
        $template->set_file('login', 'users/login.htpl');
        $template->parse('login');
    }
}

page_footer();

?>
Return current item: Gnew