PlainSQLiteBlog/pages/user/info.php

81 lines
2.2 KiB
PHP

<?php
global $c;
$strError = null;
if (UserAuth::getUser() == null)
Respond::redirect("/user/signin");
$varUser = UserAuth::getUser();
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">
<?php BootstrapRender::message(); ?>
<form method="post">
<?php BootstrapRender::input([
"name" => "username",
"label" => "Username",
"value" => $varUser["username"],
"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::button([
"tag" => "button",
"type" => "submit",
"class" => "outline-success",
"icon" => "save",
"label" => "Save"
]); ?>
</form>
</div>
</div>
</div>