Skip to content

Instantly share code, notes, and snippets.

Created July 29, 2016 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/d6749095ed20a995ec8697ef203d164f to your computer and use it in GitHub Desktop.
Save anonymous/d6749095ed20a995ec8697ef203d164f to your computer and use it in GitHub Desktop.
<?php
require_once 'core/init.php';
$errors = [];
if(Input::exists()) {
if(Token::check(Input::get('token'))) {
$validate = new Validate();
$validation = $validate->check($_POST, array(
'username' => array('required' => true),
'password' => array('required' => true)
));
if($validate->passed()) {
$user = new User();
$remember = (Input::get('remember') === 'on') ? true : false;
$login = $user->login(Input::get('username'), Input::get('password'), $remember);
if($login) {
Redirect::to('index.php');
} else
echo "Incorrect username or password";
} else {
foreach($validate->errors() as $error) {
array_push($errors, "<td>" . $error . "</td>");
}
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form action='' method='post'>
<table>
<tr>
<?php array_map(function($err) {echo $err;}, $errors) ?>
</tr>
<tr>
<td><label for='username'>Username</label></td>
<td><input type='text' name='username' id='username'></td>
</tr>
<tr>
<td><label for='password'>Password</label></td>
<td><input type='password' name='password' id='password'></td>
</tr>
<tr>
<td></td>
<td><label for='remember'><input type='checkbox' name='remember' id='remember'>Remember me</label></td>
</tr>
<tr>
<td><input type='hidden' name='token' value='<?php echo Token::generate(); ?>'></td>
<td><input type='submit' value='Login'></td>
</tr>
</table>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment