<?php # admin/usernameChange.php
require_once("restrictAccessToPage.php");
if(isset($_POST['username'])){
require_once("connection.php"); # $con
$username=addslashes($_POST['username']);
require_once("token.php"); # $token
$sql="SELECT idUsername FROM username WHERE username = '$username'";
$query=mysqli_query($con, $sql) or die ($sql);
$total=mysqli_num_rows($query);
if($total==0) {
$idUsername=$_SESSION['idUsername'];
$sql="INSERT INTO token (idUsername, token) VALUES ($idUsername, '$token')";
mysqli_query($con, $sql) or die($sql);
$path="mail/usernameChangeActivation.php?email=$username&token=$token&idUsername=$idUsername";
} else {
$path="usernameChange.php?usernameInvalido";
}
header("Location:$path");
}
?>
<!DOCTYPE html>
<html lang="en">
<?php require_once("head.php");?>
<body>
<?php require_once("navTop.php");?>
<div id="layoutSidenav">
<?php require_once("navSide.php");?>
<div id="layoutSidenav_content">
<main>
<div class="container-fluid px-4">
<h1 class="mt-4">Backoffice</h1>
<ol class="breadcrumb mb-4">
<li class="breadcrumb-item"><a href="cPanel.php">Control Panel</a></li>
<li class="breadcrumb-item active">Change Username (email)</li>
</ol>
<div class="card mb-4">
<div class="card-body">
<div class="mb-0">
<?php if(isset($_GET['naoAutorizado'])) {?>
<div class="alert alert-warning alert-dismissible fade show" role="alert"> <strong>System Warning!</strong> Password já foi utilizada. <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php } ?>
<?php if(isset($_GET['usernameInvalido'])) {?>
<div class="alert alert-warning alert-dismissible fade show" role="alert"> <strong>Warning!</strong> Username inválido.
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php } ?>
<?php if(isset($_GET['usernameAlterado'])) {?>
<div class="alert alert-success alert-dismissible fade show" role="alert"> <strong>Success!</strong> O seu email foi alterado.
</div>
<?php } ?>
<?php if(isset($_GET['verEmail'])) {?>
<div class="alert alert-success alert-dismissible fade show" role="alert"> <strong>Success!</strong> Foi enviado um email para a sua caixa de email.
</div>
<?php } ?>
<?php if(!isset($_GET['verEmail']) && !isset($_GET['usernameAlterado'])) {?>
<form method="post" autocomplete="off">
<div class="form-floating mb-3">
<input required name="username" class="form-control" id="inputUsername" type="email" autofocus/>
<label for="inputUsername">New email</label>
</div>
<div class="d-flex align-items-center justify-content-between mt-4 mb-0">
<button type="submit" class="btn btn-primary">Change email</button>
</div>
</form>
<?php } ?>
</div>
</div>
</div>
<div style="height: 100vh"></div>
<div class="card mb-4"><div class="card-body">When scrolling, the navigation stays at the top of the page. This is the end of the static navigation demo.</div></div>
</div>
</main>
<?php require_once("footer.php");?>
</div>
</div>
<?php require_once("script.php");?>
</body>
</html>
Sem comentários:
Enviar um comentário