aboutsummaryrefslogtreecommitdiff
path: root/user/update.php
blob: 1fe291a6b2201731bbb4463f95541f9cbdcecdab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
require '../config.php';
require_once(TEMPLATES_PATH . "/header.php");
require_once(TEMPLATES_PATH . "/panel.php");
require_once(LIBRARY_PATH . "/functions.php");

print_r($_POST);

if (isset($_SESSION['user_id']) && $_SESSION['user_id'] != "") {
    $conn = new PDO($config['db']['dsn'], $config['db']['username'], $config['db']['password']);
    $query = $conn->prepare("UPDATE users SET username=:username, email=:email WHERE id={$_SESSION['user_id']}");
    $query->bindParam(':username', $_POST['username']);
    $query->bindParam(':email', $_POST['email']);

    if($query->execute()) {
        echo "<h2>Account updated</h2>";
    } else {
        echo "<h2>Account update failed</h2>";
    }

    if($_POST['password'] != "") {
        $password = password_hash($_POST['password'], PASSWORD_ARGON2I);
        $query = $conn->prepare("UPDATE users SET password=:password WHERE id={$_SESSION['user_id']}");
        $query->bindParam(':password', $password);

        if($query->execute()) {
            echo "<p>Password updated</p>";
        } else {
            echo "<p>Password update failed</p>";
        }
    }

}

header("Refresh: 2; URL=$_SERVER[HTTP_REFERER]");
require_once(TEMPLATES_PATH . "/footer.php");
?>