<?php if (isset($_POST['sign_in']) && isset($_POST['password']) && isset($_POST['email'])) { // start new session if not exist if (!isset($_SESSION)) { session_start(); } // array for errors $errors = []; // create connection variable $db = new models\tkDatabase($GLOBALS['config']['db']); // sign_in user $tk_user = []; $tk_user = models\tkUser::tk_sign_in(['email' => $_POST['email'], 'password' => helpers\tkPassword::tk_get_passwd($_POST['password'])], $db); // stores user info in the session if (!empty($tk_user)) { $_SESSION['first_name'] = $tk_user['first_name']; $_SESSION['last_name'] = $tk_user['last_name']; $_SESSION['email'] = $tk_user['email']; header('Location: lessons'); } else { $errors = ['incorrect' => 'Email or password is incorrect']; } } include $GLOBALS['config']['site']['basedir'] . '/templates/site/sign_in.tmpl.php';
<?php if (isset($_POST['sign_up']) && isset($_POST['password']) && isset($_POST['first_name']) && isset($_POST['last_name']) && isset($_POST['email'])) { // array for errors $errors = []; // create connection variable $db = new models\tkDatabase($GLOBALS['config']['db']); // sign up a user models\tkUser::tk_sign_up(['first_name' => $_POST['first_name'], 'last_name' => $_POST['last_name'], 'email' => $_POST['email'], 'password' => helpers\tkPassword::tk_get_passwd($_POST['password'])], $db); } include $GLOBALS['config']['site']['basedir'] . '/templates/site/sign_up.tmpl.php';
<?php $db = new models\tkDatabase($GLOBALS['config']['db']); $tk = []; $error = []; if (isset($_SESSION['first_name'])) { $tk = models\tkUser::tk_user_info(['email' => $_SESSION['email'], 'first_name' => $_SESSION['first_name']], $db); } // Change password if (isset($_POST['current_password']) && isset($_POST['new_password']) && $_POST['current_password'] == $tk['password']) { models\tkUser::tk_change_password(['email' => $tk['email'], 'current_password' => helpers\tkPassword::tk_get_passwd($_POST['current_password']), 'new_password' => helpers\tkPassword::tk_get_passwd($_POST['new_password'])], $db); header("Location: lessons"); } elseif (isset($_POST['current_password']) && $_POST['current_password'] != $tk['password']) { $error[0] = 'Wrong current password'; } // Log out if (isset($_POST['log-out'])) { models\tkUser::tk_sign_out(['first_name' => $_SESSION['first_name'], 'email' => $_SESSION['email']], $db); session_destroy(); if (isset($_SESSION['first_name'])) { session_unset($_SESSION['first_name']); } header("Location: lessons"); } include $GLOBALS['config']['site']['basedir'] . '/templates/site/user.tmpl.php';