<?php

require 'includes/db.php';
require 'includes/init.php';

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<!-- Apple iOS and Android stuff (do not remove) -->
<meta name="apple-mobile-web-app-capable" content="no" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />

<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no,maximum-scale=1" />

<!-- Required Stylesheets -->
<link rel="stylesheet" type="text/css" href="css/reset.css" media="screen" />
<link rel="stylesheet" type="text/css" href="css/text.css" media="screen" />
<link rel="stylesheet" type="text/css" href="css/fonts/ptsans/stylesheet.css" media="screen" />

<link rel="stylesheet" type="text/css" href="css/core/form.css" media="screen" />
<link rel="stylesheet" type="text/css" href="css/core/login.css" media="screen" />
<link rel="stylesheet" type="text/css" href="css/core/button.css" media="screen" />

<link rel="stylesheet" type="text/css" href="css/mws.theme.css" media="screen" />

<!-- JavaScript Plugins -->
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>

<!-- jQuery-UI Dependent Scripts -->
<script type="text/javascript" src="js/jquery-ui-effecs.min.js"></script>

<!-- Plugin Scripts -->
<script type="text/javascript" src="plugins/placeholder/jquery.placeholder-min.js"></script>
<script type="text/javascript" src="plugins/validate/jquery.validate-min.js"></script>

<!-- Login Script -->
<script type="text/javascript" src="js/login.js"></script>

<title><?php echo $title_prefix; ?> - Login Page</title>

</head>

<body>

	<center>
	<img src="https://dl.dropboxusercontent.com/u/137988773/ilGQkJeXa39Jl.png" height="170" width="550">
	</center>
<center><h4><font color="white">By logging in you agree to the</font><a href=http://flashstresser.net/tos.php><font color="#029aff" face="verdana">Terms of Service.</font></h4></center></a>
<center><h5><font color="red" face="arial">Rasbora Stresser and Apathy Booter customers look<a href=http://flashstresser.net/explanation.php> Here.</a></center></h5></font>

    <div id="mws-login-wrapper">
        <div id="mws-login">
            <h1>Login</h1>
            <div class="mws-login-lock"><img src="css/icons/24/locked-2.png" alt="" /></div>
			<?php
if (!($user -> LoggedIn()))
{
	if (isset($_POST['loginBtn']))
	{
		$username = $_POST['username'];
		$password = $_POST['password'];
		$errors = array();
		if (!ctype_alnum($username) || strlen($username) < 4 || strlen($username) > 15)
		{
			$errors[] = 'Username Must Be  Alphanumberic And 4-15 characters in length';
		}
		
		if (empty($username) || empty($password))
		{
			$errors[] = 'Please fill in all fields';
		}
		
		if (empty($errors))
		{
			$SQLCheckLogin = $odb -> prepare("SELECT COUNT(*) FROM `users` WHERE `username` = :username AND `password` = :password");
			$SQLCheckLogin -> execute(array(':username' => $username, ':password' => SHA1($password)));
			$countLogin = $SQLCheckLogin -> fetchColumn(0);
			if ($countLogin == 1)
			{
				$SQLGetInfo = $odb -> prepare("SELECT `username`, `ID` FROM `users` WHERE `username` = :username AND `password` = :password");
				$SQLGetInfo -> execute(array(':username' => $username, ':password' => SHA1($password)));
				$userInfo = $SQLGetInfo -> fetch(PDO::FETCH_ASSOC);
				if ($userInfo['status'] == 0)
				{
					$_SESSION['username'] = $userInfo['username'];
					$_SESSION['ID'] = $userInfo['ID'];
					{
						$ip = getRealIpAddr();
						if (filter_var($ip, FILTER_VALIDATE_IP))
						{
							$SQL = $odb -> prepare('INSERT INTO `loginlogs` VALUES(:username, :ip, UNIX_TIMESTAMP())');
							$SQL -> execute(array(':ip' => $ip, ':username' => $username));
							echo '<div class="nNote nSuccess hideit"><p><font color=\'white\'><strong>SUCCESS: </strong>Login Successful.  Redirecting....</font></p></div><meta http-equiv="refresh" content="3;url=index.php">';
							die();
						}
						else
						{
							echo '<div class="nNote nFailure hideit"><p><font color=\'white\'><strong>ERROR: </strong>Login Failed</font></p></div>';
						}
					}
				}
				else
				{
					echo '<div class="nNote nFailure hideit"><p><font color=\'white\'><strong>ERROR: </strong>Your user was banned</font></p></div>';
				}
			}
			else
			{
				echo '<div class="nNote nFailure hideit"><p><font color=\'white\'><strong>ERROR: </strong>Login Failed</font></p></div>';
			}
		}
		else
		{
			echo '<div class="nNote nFailure hideit"><p><strong>ERROR:</strong><br />';
			foreach($errors as $error)
			{
				echo '-'.$error.'<br />';
			}
			echo '</div>';
		}
	}
}
else
{
	echo "<font color='white'>Already logged in, redirecting...</font>";
	echo "<meta http-equiv=\"refresh\" content=\"3;url=index.php\">";
	die();
}
?>
            <div id="mws-login-form">
                <form class="mws-form" method="post">
                    <div class="mws-form-row">
                        <div class="mws-form-item large">
                            <input type="text" name="username" class="mws-login-username mws-textinput required" placeholder="username" />
                        </div>
                    </div>
                    <div class="mws-form-row">
                        <div class="mws-form-item large">
                            <input type="password" name="password" class="mws-login-password mws-textinput required" placeholder="password" />
                        </div>
                    </div>
                    <div class="mws-form-row mws-inset">
                        <ul class="mws-form-list inline">
                            <li><input type="checkbox" /> <label>Remember me</label></li>
                        </ul>
                    </div>
                    <div class="mws-form-row">
                        <input type="submit" value="Login" name='loginBtn' class="mws-button green mws-login-button" /><br /></form>
	         <form action="register.php" method="get">
<input type="submit" value="Register" 
class="mws-button blue mws-login-button" id="frm1_submit" />
</form>
	        
	
	          
</a></center>
                    </div>
               
            </div>
        </div>
    </div>

</body>
</html>