<?php
/* Template Name: Login */
get_header();
?>

<h2>Login</h2>

<form method="post">
    <input type="text" name="username" placeholder="Username" required>
    <input type="password" name="password" placeholder="Password" required>
    <button type="submit" name="login_user">Login</button>
</form>

<?php
if (isset($_POST['login_user'])) {
    $creds = array(
        'user_login'    => $_POST['username'],
        'user_password' => $_POST['password'],
        'remember'      => true
    );

    $user = wp_signon($creds, false);

    if (!is_wp_error($user)) {
        wp_redirect(home_url('/activity'));
        exit;
    } else {
        echo "<p>Login failed.</p>";
    }
}

get_footer();
