Ejemplo n.º 1
0
<?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';