account settings without front

This commit is contained in:
Szymon 2018-12-03 01:55:36 +01:00
parent 44dadd86d8
commit 4979901e3c
4 changed files with 358 additions and 1 deletions

208
admin-zone/acc_settings.php Normal file
View File

@ -0,0 +1,208 @@
<?php
if( !isset( $_SESSION ) ) session_start();
$_SESSION['messagep']='';
$_SESSION['messagee']='';
$_SESSION['messagea']='';
$_SESSION['messageas']='';
$_SESSION['messageam']='';
$_SESSION['messageab']='';
$_SESSION['messagefb']='';
$_SESSION['messagetw']='';
if(empty($_SESSION['user'])){
header('Location: login.php');
}
include "../settings/db_connect.php";
$user=$_SESSION['user'];
$password=$_SESSION['password'];
$data = mysqli_query($mysqli, "SELECT * FROM user WHERE password='$password' AND username='$user'");
$row = mysqli_fetch_array($data);
$about_short = $row['about_short'];
$about_me = $row['about_me'];
$about_blog = $row['about_blog'];
if(isset($_POST['password_change'])){
if(!empty($_POST['password']) && !empty($_POST['newpassword']) && !empty($_POST['confirmpassword'])) {
if($password != md5($_POST['newpassword'])) {
if($_POST['newpassword'] == $_POST['confirmpassword']) {
if(md5($_POST['password']) == $password) {
$newpassword=md5($_POST['newpassword']);
$sql = "UPDATE user SET password='$newpassword' WHERE password='$password' AND username='$user'";
if($mysqli->query($sql) === true){
$_SESSION['user']=$user;
$_SESSION['password']=$newpassword;
$_SESSION['loggedIn']=1;
$_SESSION['messagep'] = "Hasło zostało zmienione!";
}
else{
$_SESSION['messagep'] = "Coś poszło nie tak, spróbuj ponownie później.";
}
mysqli_close($mysqli);
}
else {
$_SESSION['messagep'] = "Błędne hasło!";
}
}
else{
$_SESSION['messagep'] = "Potwierdź hasło ponownie";
}
}
else{
$_SESSION['messagep'] = "Nowe hasło nie może być takie samo jak obecne";
}
}
else{
$_SESSION['messagep'] = "Należy wypełnić wszystkie wmagane pola";
}
}
if(isset($_POST['email_change'])){
$email=$row['email'];
if(!empty($_POST['password']) && !empty($_POST['newemail']) && !empty($_POST['confirmemail'])) {
if($email != md5($_POST['newemail'])) {
if($_POST['newemail'] == $_POST['confirmemail']) {
if(md5($_POST['password']) == $password) {
$newemail=$_POST['newemail'];
$sql = "UPDATE user SET email='$newemail' WHERE password='$password' AND username='$user'";
if($mysqli->query($sql) === true){
$_SESSION['messagee'] = "email został zmieniony!";
}
else{
$_SESSION['messagee'] = "Coś poszło nie tak, spróbuj ponownie później.";
}
mysqli_close($mysqli);
}
else {
$_SESSION['messagee'] = "Błędne hasło!";
}
}
else{
$_SESSION['messagee'] = "Potwierdź email ponownie";
}
}
else{
$_SESSION['messagee'] = "Nowy email nie może być taki sam jak obecny";
}
}
else{
$_SESSION['messagee'] = "Należy wypełnić wszystkie wmagane pola";
}
}
if(isset($_POST['avatar_change'])){
$currentavatar = $row['avatar'];
$avatar_path = $mysqli->real_escape_string('../images/avatars/'.$_FILES['avatar']['name']);
if (preg_match("!image!", $_FILES['avatar']['type'])){
if(copy($_FILES['avatar']['tmp_name'], $avatar_path)){
$sql = "UPDATE user SET avatar='$avatar_path' WHERE password='$password' AND username='$user'";
if($mysqli->query($sql) === true){
if($currentavatar != $avatar_path){
unlink($currentavatar);
}
$_SESSION['messagea'] = "avatar został zmieniony!";
}
else{
$_SESSION['messagea'] = "Coś poszło nie tak, spróbuj ponownie później.";
}
mysqli_close($mysqli);
}
else{
$_SESSION['messagea'] = "Coś poszło nie tak, spróbuj ponownie później.";
}
}
else{
$_SESSION['messagea'] = "Plik musi byc graficzny\n";
}
}
if(isset($_POST['aboutshort_change'])){
$newabout_short = $_POST['aboutshort'];
if($about_short != $newabout_short){
$sql = "UPDATE user SET about_short='$newabout_short' WHERE password='$password' AND username='$user'";
if($mysqli->query($sql) === true){
$_SESSION['messageas'] = "Zmiany zostały zatwierdzone!";
$about_short = $row['about_short'];
header('Location: account_settings.php');
}
else{
$_SESSION['messageas'] = "Coś poszło nie tak, spróbuj ponownie później.";
}
}
else{
$_SESSION['messageas'] = "Brak zmian";
}
}
if(isset($_POST['aboutme_change'])){
$newabout_me = $_POST['aboutme'];
if($about_me != $newabout_me){
$sql = "UPDATE user SET about_me='$newabout_me' WHERE password='$password' AND username='$user'";
if($mysqli->query($sql) === true){
$_SESSION['messageam'] = "Zmiany zostały zatwierdzone!";
$about_me = $row['about_me'];
header('Location: account_settings.php');
}
else{
$_SESSION['messageam'] = "Coś poszło nie tak, spróbuj ponownie później.";
}
}
else{
$_SESSION['messageam'] = "Brak zmian";
}
}
if(isset($_POST['aboutblog_change'])){
$newabout_blog = $_POST['aboutblog'];
if($about_blog != $newabout_blog){
$sql = "UPDATE user SET about_blog='$newabout_blog' WHERE password='$password' AND username='$user'";
if($mysqli->query($sql) === true){
$_SESSION['messageab'] = "Zmiany zostały zatwierdzone!";
$about_blog = $row['about_blog'];
header('Location: account_settings.php');
}
else{
$_SESSION['messageab'] = "Coś poszło nie tak, spróbuj ponownie później.";
}
}
else{
$_SESSION['messageab'] = "Brak zmian";
}
}
if(isset($_POST['face_change'])){
if(!empty($_POST['FB'])) {
$face = $row['FB'];
$newface = $_POST['FB'];
if($face != $newface) {
$sql = "UPDATE user SET FB='$newface' WHERE password='$password' AND username='$user'";
if($mysqli->query($sql) === true){
$_SESSION['messagefb'] = "Zmiany zostały zatwierdzone!";
}
else{
$_SESSION['messagefb'] = "Coś poszło nie tak, spróbuj ponownie później.";
}
}
else{
$_SESSION['messagefb'] = "Brak zmian";
}
}
}
if(isset($_POST['twit_change'])){
if(!empty($_POST['TW'])) {
$twit = $row['FB'];
$newtwit = $_POST['TW'];
if($twit != $newtwit) {
$sql = "UPDATE user SET TW='$newtwit' WHERE password='$password' AND username='$user'";
if($mysqli->query($sql) === true){
$_SESSION['messagetw'] = "Zmiany zostały zatwierdzone!";
}
else{
$_SESSION['messagetw'] = "Coś poszło nie tak, spróbuj ponownie później.";
}
}
else{
$_SESSION['messagetw'] = "Brak zmian";
}
}
}
?>

View File

@ -0,0 +1,148 @@
<?php
if( !isset( $_SESSION ) ) session_start();
if(empty($_SESSION['user'])){
header('Location: login.php');
}
include "acc_settings.php";
?>
<html>
<head>
<meta charset="utf-8">
<title>Ustawienia Konta CMS - Bloggero</title>
<meta name="robots" content="noindex,nofollow" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- JS STYLE AND BS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="css/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="../css/style2.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/malihu-custom-scrollbar-plugin/3.1.5/jquery.mCustomScrollbar.min.css">
</head>
<body>
<div class="wrapper">
<?php include "sidebar.php"; ?>
<div id="content">
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" id="sidebarCollapse" class="btn btn-info navbar-btn">
<i class="glyphicon glyphicon-align-left"></i>
<span>Toggle Sidebar</span>
</button>
</div>
</div>
</nav>
</div>
<div class="container-fluid">
<div clas="flex-row">
<div class="flex-column">
<form class="form" action="" method="POST">
<p>Zmiana hasła</p>
<input type="password" class="form-control" placeholder="Hasło" id="password" name="password" required />
<input type="password" class="form-control" placeholder="Nowe hasło" id="newpassword" name="newpassword" required />
<input type="password" class="form-control" placeholder="Potwierdź nowe hasło" id="confirmpassword" name="confirmpassword" required />
<span><?php echo $_SESSION['messagep']; ?></span><br>
<input type="submit" class="btn" value="Zmień Hasło" name="password_change" />
</form>
</div>
</div>
<div clas="flex-row">
<div class="flex-column">
<form class="form" action="" method="POST">
<p>Zmiana adresu e-mail</p>
<input type="password" class="form-control" placeholder="Hasło" id="password" name="password" required />
<input type="email" class="form-control" placeholder="email" id="newemail" name="newemail" required />
<input type="email" class="form-control" placeholder="Potwierdź email" id="confirmemail" name="confirmemail" required />
<span><?php echo $_SESSION['messagee']; ?></span><br>
<input type="submit" class="btn" value="Zmień email" name="email_change" />
</form>
</div>
</div>
<div clas="flex-row">
<div class="flex-column">
<form class="form" action="" method="POST" enctype="multipart/form-data">
<p>Zmiana avatara</p>
<label>Wybierz nowy avatar: </label>
<input type="file" name="avatar" accept="image/*" required />
<span><?php echo $_SESSION['messagea']; ?></span><br>
<input type="submit" class="btn" value="Zmień avatar" name="avatar_change" />
</form>
</div>
</div>
<div clas="flex-row">
<div class="flex-column">
<form class="form" action="" method="POST">
<p>Krótko o mnie</p>
<textarea name="aboutshort" rows="10" cols="80"><?php echo $about_short; ?></textarea><br>
<span><?php echo $_SESSION['messageas']; ?></span><br>
<input type="submit" class="btn" value="Zatwierdź" name="aboutshort_change" />
</form>
</div>
</div>
<div clas="flex-row">
<div class="flex-column">
<form class="form" action="" method="POST">
<p>O mnie</p>
<textarea name="aboutme" rows="10" cols="80"><?php echo $about_me; ?></textarea><br>
<span><?php echo $_SESSION['messageam']; ?></span><br>
<input type="submit" class="btn" value="Zatwierdź" name="aboutme_change" />
</form>
</div>
</div>
<div clas="flex-row">
<div class="flex-column">
<form class="form" action="" method="POST">
<p>Opis Bloga</p>
<textarea name="aboutblog" maxlength="50" rows="10" cols="80"><?php echo $about_blog; ?></textarea><br>
<span><?php echo $_SESSION['messageab']; ?></span><br>
<input type="submit" class="btn" value="Zatwierdź" name="aboutblog_change" />
</form>
</div>
</div>
<div clas="flex-row">
<div class="flex-column">
<form class="form" action="" method="POST">
<p>Social Media</p>
<input type="text" class="form-control" placeholder="facebook" id="FB" name="FB" required />
<span><?php echo $_SESSION['messagefb']; ?></span><br>
<input type="submit" class="btn" value="Zatwierdź" name="face_change" />
</form>
<form class="form" action="" method="POST">
<input type="text" class="form-control" placeholder="twitter" id="TW" name="TW" required />
<span><?php echo $_SESSION['messagetw']; ?></span><br>
<input type="submit" class="btn" value="Zatwierdź" name="twit_change" />
</form>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
<!-- Bootstrap Js CDN -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!-- jQuery Custom Scroller CDN -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/malihu-custom-scrollbar-plugin/3.1.5/jquery.mCustomScrollbar.concat.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#sidebar").mCustomScrollbar({
theme: "minimal"
});
$('#sidebarCollapse').on('click', function () {
$('#sidebar, #content').toggleClass('active');
$('.collapse.in').toggleClass('in');
$('a[aria-expanded=true]').attr('aria-expanded', 'false');
});
$('#dodajemy').click(function(){
$("#zawartosc").load('index.php');
});
});
</script>
<a href="logout.php">Logout</a>
</body>
</html>

View File

@ -51,7 +51,7 @@ include "../settings/db_connect.php";
if ($sql = $mysqli->prepare("SELECT * FROM post ORDER BY data_dodania")) if ($sql = $mysqli->prepare("SELECT * FROM post ORDER BY data_dodania"))
{ {
$sql->execute(); $sql->execute();
$sql->bind_result($post_id,$trash,$title,$description,$main,$date,$mod_date); $sql->bind_result($post_id,$trash,$title,$description,$main,$img,$date,$mod_date);
while ($sql->fetch()) while ($sql->fetch())
{ {
echo "<tr> echo "<tr>

View File

@ -7,5 +7,6 @@
<li><a href="">Strona główna</a></li> <li><a href="">Strona główna</a></li>
<li class="active"><a target="zawartosc" name="dodajemy" href="index.php">Posty</a></li> <li class="active"><a target="zawartosc" name="dodajemy" href="index.php">Posty</a></li>
<li><a href="newsy.php">Newsy</a></li> <li><a href="newsy.php">Newsy</a></li>
<li><a href="account_settings.php">Ustawienia Konta</a></li>
</ul> </ul>
</nav> </nav>