<?php
// local template functions
require_once(SITE_TEMPLATES_PATH . '/partial/_template_functions.inc.php');

// page settings
define("PAGE_NAME", t("login_page_name", "Login"));
define("PAGE_DESCRIPTION", t("login_meta_description", "Login to your account"));
define("PAGE_KEYWORDS", t("login_meta_keywords", "login, register, file, hosting"));

// top navigation
require_once(SITE_TEMPLATES_PATH . '/partial/_navigation_header.inc.php');

// login user, this is a non-ajax fallback so rarely used
if ((int) $_REQUEST['submitme'])
{
    // clear any expired IPs
    bannedIP::clearExpiredBannedIps();

    // do login
    $loginUsername = trim($_REQUEST['username']);
    $loginPassword = trim($_REQUEST['password']);

    // check user isn't banned from logging in
    $bannedIp = bannedIP::getBannedIPData();
    if ($bannedIp)
    {
        if ($bannedIp['banType'] == 'Login')
        {
            notification::setError(t("login_ip_banned", "You have been temporarily blocked from logging in due to too many failed login attempts. Please try again [[[EXPIRY_TIME]]].", array('EXPIRY_TIME' => ($bannedIp['banExpiry'] != null ? coreFunctions::formatDate($bannedIp['banExpiry']) : t('later', 'later')))));
        }
    }

    // initial validation
    if (notification::isErrors() == false)
    {
        if (!strlen($loginUsername))
        {
            // log failure
            Auth::logFailedLoginAttempt(coreFunctions::getUsersIPAddress(), $loginUsername);

            notification::setError(t("please_enter_your_username", "Please enter your username"));
        }
        elseif (!strlen($loginPassword))
        {
            // log failure
            Auth::logFailedLoginAttempt(coreFunctions::getUsersIPAddress(), $loginUsername);

            notification::setError(t("please_enter_your_password", "Please enter your password"));
        }
    }

    if (notification::isErrors() == false)
    {
        $rs = $Auth->login($loginUsername, $loginPassword);
        if ($rs)
        {
            // if we know the file
            if (isset($_REQUEST['loginShortUrl']))
            {
                // download file
                $file = file::loadByShortUrl(trim($_REQUEST['loginShortUrl']));
                if ($file)
                {
                    coreFunctions::redirect($file->getFullShortUrl());
                }
            }

            // successful login
            coreFunctions::redirect(coreFunctions::getCoreSitePath() . '/account_home.' . SITE_CONFIG_PAGE_EXTENSION);
        }
        else
        {
            // login failed
            notification::setError(t("username_and_password_is_invalid", "Your username and password are invalid"));
        }
    }
}
// header top
require_once(SITE_TEMPLATES_PATH . '/partial/_header.inc.php');
?>
<!-- Container -->
            <div class="container">
            	<div class="white-space space-big"></div>
                <div class="row">
                    <div class="col-md-6">
                    	<h3 class="fancy-title"><span> Not Registered Yet !?</span></h3>
                        <p>
						Join us now for free and recieve amazing features.
						</p>
                        <div class="row">	
                        	<div class="col-sm-6">
                            	<ul class="list-default fa-ul">
                        			<li><a href="<?php echo coreFunctions::getCoreSitePath(); ?>/register.<?php echo SITE_CONFIG_PAGE_EXTENSION; ?>">Register Now!</a></li>                          
                        		</ul>
                            </div>
                        	<div class="col-sm-6">
                            	<ul class="list-default fa-ul">
                        			<li><a href="<?php echo coreFunctions::getCoreSitePath(); ?>/forgot_password.<?php echo SITE_CONFIG_PAGE_EXTENSION; ?>">Forgot Password?</a></li>
                            		<li><a href="<?php echo coreFunctions::getCoreSitePath(); ?>/terms.<?php echo SITE_CONFIG_PAGE_EXTENSION; ?>">Terms & Conditions</a></li>                         
                        		</ul>
                            </div>
                        </div>
                        <div class="white-space space-small"></div>
                    </div>
					
					<div class="col-md-6">
                    	<h3 class="fancy-title"><span>Sign In</span></h3>
						
                        <!-- Form -->
						 <form method="post" role="form" id="form_login" action="login.html" autocomplete="off">
							 <?php

                if (notification::isErrors())

                {

                    echo notification::outputErrors();

                }

                elseif (notification::isSuccess())

                {

                    echo notification::outputSuccess();

                }

                ?>
							<div class="form-group">
								<div class="col-sm-12">
									<input type="text" class="form-control" name="username" id="username" placeholder="<?php echo UCWords(t("username", "username")); ?>" autocomplete="off" />
								</div>
								
								<div class="col-sm-12">
									<input type="password" class="form-control" name="password" id="password" placeholder="<?php echo UCWords(t("password", "password")); ?>" autocomplete="off" />
								</div>
								
								<div class="col-sm-12">
									<button type="submit" class="btn btn-primary btn-block btn-login">
                            
                            <?php echo UCWords(t("login", "login")); ?>
                        </button>
								</div>
							</div>
						</form>                        
                        <!-- /Form --> 
                                               
                        <div class="white-space space-small"></div>
                    </div>
					
				</div>               
			
            	<div class="white-space space-medium"></div>
        </div>
        
    <!-- Bottom Scripts -->
    <script src="<?php echo SITE_JS_PATH; ?>/gsap/main-gsap.js"></script>
    <script src="<?php echo SITE_JS_PATH; ?>/bootstrap.js"></script>
    <script src="<?php echo SITE_JS_PATH; ?>/joinable.js"></script>
    <script src="<?php echo SITE_JS_PATH; ?>/resizeable.js"></script>
    <script src="<?php echo SITE_JS_PATH; ?>/flow-api.js"></script>
    <script src="<?php echo SITE_JS_PATH; ?>/jquery.validate.min.js"></script>
    <script src="<?php echo SITE_JS_PATH; ?>/flow-login.js"></script>
    <script src="<?php echo SITE_JS_PATH; ?>/custom.js"></script>
	
<?php

// include footer

require_once(SITE_TEMPLATES_PATH . '/partial/_footer.inc.php');

?>