diff --git a/layout.php b/layout.php index 7917cb1..a1ff871 100644 --- a/layout.php +++ b/layout.php @@ -1,3 +1,13 @@ +Logout'; +} +else { + $logButton = 'href="account/login.php">Login'; +} +?> + @@ -6,29 +16,30 @@ echo $pageTitle ?> - +
-

ibuy

+

ibuy

+
Banner diff --git a/public/account/login.php b/public/account/login.php index e69de29..8afbb39 100644 --- a/public/account/login.php +++ b/public/account/login.php @@ -0,0 +1,32 @@ +Don\'t have an account?Click here to register

+

Login

+
+ + + +
'; +$stylesheet = '../assets/ibuy.css'; +require '../../layout.php'; +$server = 'mysql'; + $username = 'student'; + $password = 'student'; + $schema = 'ibuy'; + $pdo = new PDO('mysql:dbname=' . $schema . ';host=' . $server, $username, $password); +if (isset($_POST['submit'])) { + $stmt = $pdo->prepare('SELECT * FROM users WHERE email = :email'); + $values = [ + 'email' => $_POST['email'] + ]; + $stmt->execute($values); + $user = $stmt->fetch(); + if (password_verify($_POST['password'], $user['password'])) { + $_SESSION['loggedin'] = $user['user_id']; + echo'

Successful login

'; + } + else { + echo '

Unsuccessful Login

'; + } +} +?> \ No newline at end of file diff --git a/public/account/register.php b/public/account/register.php index e69de29..6e35b28 100644 --- a/public/account/register.php +++ b/public/account/register.php @@ -0,0 +1,38 @@ +prepare('INSERT INTO users (first_name, last_name, email, password) + VALUES (:first_name, :last_name, :email, :password)'); + $values = [ + 'first_name' => $_POST['first_name'], + 'last_name' => $_POST['last_name'], + 'email' => $_POST['email'], + 'password' => password_hash($_POST['password'], PASSWORD_DEFAULT) + ]; + $stmt->execute($values); +} + +$pageTitle = 'iBuy - Register'; +$pageContent = '

Already have an account?Click here to Login

+

Register

+
+ + + + + +
'; +require '../../layout.php'; + + +if (isset($_POST['submit'])) { + addUser(); + echo '

Successful account creation

'; +} +?> \ No newline at end of file