M classes/Session.php +13 -1
@@ 27,10 27,22 @@ class Session
return hash_equals($this->getCSRF(), $csrf);
}
- public function login($id)
+ public function login($id, $remember)
{
session_regenerate_id();
$this->id = $_SESSION['id'] = $id;
+ if ($remember) {
+ $param = session_get_cookie_params();
+ setcookie(
+ session_name(),
+ session_id(),
+ time() + 60 * 60 * 24 * 30,
+ $param['path'],
+ $param['domain'],
+ $param['secure'],
+ $param['httponly']
+ );
+ }
}
public function logout()
M includes/index.php +8 -2
@@ 13,11 13,17 @@
<label for="form-password">Password:</label>
<input type="password" name="password" class="form-control" required/>
- <p><input type="submit" value="Login"/> <a href="password-lost.php">Password lost?</a></p>
+ <p>
+ <input type="submit" value="Login"/>
+ <input type="checkbox" id="remember" name="remember"> <label for="remember">Remember me</label>
+ </p>
+
+ <nav>
+ <a href="password-lost.php">Password lost?</a> <a href="register.php">Register</a>
+ </nav>
</form>
<p>
- <a href="register.php" class="link">Register</a><br>
<a href="manual.php" class="link">Manual</a><br>
<a href="activity.php" class="link">Explore</a>
</p>
M login.php +3 -2
@@ 7,13 7,14 @@ require 'includes/app.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$email = $_POST['email'];
$password = $_POST['password'];
+ $remember = $_POST['remember'] ?? false;
Validate::isEmail($email) or $errors[] = "Wrong email";
Validate::isPassword($password) or $errors[] = "Wrong password";
if (!count($errors)) {
- if ($member = $GLOBALS['App']->getUser()->login($email, $password, $errors)) {
- $GLOBALS['App']->getSession()->login($member['id']);
+ if ($member = $App->getUser()->login($email, $password, $errors)) {
+ $App->getSession()->login($member['id'], $remember);
redirect('index.php');
}
}
M register.php +2 -0
@@ 62,6 62,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST
<label for="repeat">Repeat:</label>
<input type="password" id="repeat" name="repeat" class="form-control" required/>
+ <p><a target="_blank" href="https://m15o.gumroad.com/l/lipuli">Buy a key</a> for instant access or email me at m15o at posteo dot net.</p>
+
<label for="name">Key:</label>
<input type="text" id="key" name="key" autocomplete="off" value="<?= $form['key'] ?>" class="form-control"
required/>