BootstrapSQLiteBlog/pages/user/info.php

89 lines
2.5 KiB
PHP

<?php
global $c;
$strError = null;
if (UserAuth::getUser() == null)
Respond::redirect("/user/signin");
$varUser = UserAuth::getUser();
$strUsername = $varUser["user_name"] ?? "";
$strDisplayName = $varUser["display_name"] ?? "";
if ($varUser == null)
Respond::redirect("/");
try
{
if (Request::posts("user_name", "display_name"))
{
$strUsername = Request::getPosted("user_name");
$strDisplayName = Request::getPosted("display_name");
if (!preg_match("/^[A-Za-z0-9]{1,}$/", $strUsername))
throw new Exception("Username must be alphanumeric characters only");
$c->query(
"INSERT or replace into users (email, user_name, display_name)
select
?,
?,
?",
$varUser["email"],
$strUsername,
$strDisplayName);
BootstrapRender::message("Profile updated", "success");
}
}
catch (Exception $x)
{
BootstrapRender::message($x->getMessage(), "danger");
}
?>
<div class="container">
<div class="row my-5">
<div class="col-md-4">
<div class="mb-3">Edit your account details here.</div>
</div>
<div class="col-md-4">
<?php BootstrapRender::message(); ?>
<form method="post">
<?php BootstrapRender::input([
"name" => "email",
"label" => "E-Mail Address",
"value" => $varUser["email"],
"disabled" => 1,
]); ?>
<?php BootstrapRender::input([
"name" => "user_name",
"label" => "Username",
"value" => $strUsername,
]); ?>
<?php BootstrapRender::input([
"name" => "display_name",
"label" => "Display Name",
"value" => $strDisplayName,
]); ?>
<?php BootstrapRender::buttons([
"input_group" => 0,
"buttons" => [[
"icon" => "save",
"label" => "Save",
"type" => "submit",
"class" => "outline-success"
]]]); ?>
</form>
</div>
</div>
</div>