finalisation de ma part :)

This commit is contained in:
Florian Bouillon 2019-03-06 09:13:31 +01:00
parent 9df001d565
commit cc8ee929f8
13 changed files with 91 additions and 101 deletions

View File

@ -507,7 +507,7 @@ input {
.article .title {
line-height: 24px;
font-weight: bold;
color: #3a3a3a;
color: #3a3a3a;
}
.article .text {
@ -519,7 +519,7 @@ input {
height: 180px;
}
.article .text img {
.article .text img, .container-search img {
display: none;
}
@ -672,10 +672,7 @@ label{
-o-transition: 200ms;
transition: 200ms;
box-shadow: 1px 1px 30px 1px lightgrey;
}
.next:hover{
color: #007bff;
box-shadow: 1px 1px 30px 1px rgba(0,163,249,0.3);
color:#000;
}
.filtre {
@ -886,7 +883,7 @@ label{
}
}
form.login > input {
form.login > input, form.login > a {
/* text-align: center; */
display: block;
margin: auto;
@ -903,9 +900,8 @@ form.login >input[type="submit"], form.login > a {
border: none;
}
form.login > a {
left: -28%;
margin-top: 65px;
form.login a {
width: 106px;
}
a:hover {

View File

@ -9,3 +9,4 @@
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<link href="http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.11/summernote.css" rel="stylesheet" />
<script src="http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.11/summernote.js"></script>
<script src="https://unpkg.com/popper.js/dist/umd/popper.min.js"></script>

View File

@ -44,10 +44,10 @@
<div class="bloc-filter">
<h3>Plus d'articles</h3>
<p class="title-small">Catégories</p>
<div class="filtre dev-color">dev</div>
<div class="filtre digi-color">digi</div>
<div class="filtre ops-color">ops</div>
<div class="filtre devops-color">devops</div>
<a data-category="3" class="filtre dev-color">dev</a>
<a data-category="4" class="filtre digi-color">digi</a>
<a data-category="2" class="filtre ops-color">ops</a>
<a data-category="1" class="filtre devops-color">devops</a>
<p class="title-small">Tags</p>
<tag type="tags" />
</div>
@ -58,6 +58,11 @@
<a href="./edit" class="contenue-recent next">Editer l'article</a>
</if>
</tag>
<tag type="isLoggedIn" reol="ROLE_ADMIN">
<if true>
<a style="float: left" href="./delete" class="contenue-recent next">Supprimmer l'article</a>
</if>
</tag>
</div>
<h3 id="titre-between">Dans le même thème</h3>

View File

@ -17,16 +17,15 @@
<div class="cover-text">
<h2 id="titre-home">Créer un utilisateur</h2>
<div class="p-home">
<form name="login" id="name" method="POST" class="login" action="./edit">
<input name="username" id="username" type="text" placeholder="Nom d'utilisateur" />
<form name="login" id="name" method="POST" class="login" action="./">
<tag type="userEditor" element="username" />
<input name="password" id="password" type="password" placeholder="Mot de passe" />
<select name="ROLE_ADMIN">
<tag type="userEditor" el="role" />
<option value="ROLE_USER">Utilisateur</option>
<option value="ROLE_EDITOR">Editeur</option>
<option value="ROLE_ADMIN">Administrateur</option>
<input name="job" id="job" type="text" placeholder="apprenant" />
<select name="role">
<tag type="userEditor" element="role" />
</select>
<input type="submit" class="bloc-button" value="Créer"/>
<a style="border: none" class="bloc-button" href="../delete/">Supprimmer</a>
</form>
</div>
</div>

View File

@ -107,19 +107,6 @@ var submit = () => {
}
}
http.send(data);
// var url = './';
// var params = "title="+ title.value +"&category=" + category.value + "&content=" + major.innerHTML + "&tags=" + tglst;
// http.open('POST', url, true);
// //Send the proper header information along with the request
// http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
// console.log(major.innerHTML);
// http.send(params);
}
if(document.querySelector(".addTag") != null) {
@ -131,13 +118,13 @@ document.querySelector("#search + button").addEventListener("click", function()
window.location = window.location.pathname + "?term=" + document.querySelector("#search").value;
});
document.querySelectorAll(".int-search .filtre").forEach(function(el) {
document.querySelectorAll(".filtre").forEach(function(el) {
el.addEventListener("click", function() {
var tagW = new URL(window.location).searchParams.get("tag");
var tag = (tagW != null ? "&tag=" + tagW : "");
var termW = new URL(window.location).searchParams.get("term");
var term = (termW != null ? "&term=" + termW : "");
window.location = window.location.pathname + "?category=" + this.getAttribute("data-category") + tag + term;
window.location = "/search/?category=" + this.getAttribute("data-category") + tag + term;
})
})

View File

@ -40,9 +40,9 @@ class Controller {
// return $instance->$function();
}
} elseif ($arr[0] === "editor" && isset($cl) && $cl == $class) {
if(!isset($_SESSION["author"]) || (isset($_SESSION["author"]) && ($_SESSION["author"]->getRole() != "ROLE_EDITOR" && $_SESSION["author"]->getRole() != "ROLE_ADMIN"))) header("Location: /login/?redirect=".$_SERVER["REQUEST_URI"]);
if(!isset($_SESSION["author"]) || (isset($_SESSION["author"]) && ($_SESSION["author"]->getRole() != "ROLE_EDITOR" && $_SESSION["author"]->getRole() != "ROLE_ADMIN"))) header("Location: /login/");
} elseif($arr[0] === "admin" && isset($cl) && $cl ==$class) {
if(!isset($_SESSION["author"]) || (isset($_SESSION["author"]) && $_SESSION["author"]->getRole() != "ROLE_ADMIN")) header("Location: /login/?redirect=".$_SERVER["REQUEST_URI"]);
if(!isset($_SESSION["author"]) || (isset($_SESSION["author"]) && $_SESSION["author"]->getRole() != "ROLE_ADMIN")) header("Location: /login/");
} elseif($arr[0] === "title" && isset($cl) && $cl == $class) {
array_shift($arr);
$_GET['page_title'] = join(" ", $arr);

View File

@ -19,7 +19,6 @@ class LoginController extends Controller {
$user = Author::getByUsername($_POST["username"]);
if($user->checkPassword($_POST["password"])) {
$_SESSION["author"] = $user;
if(isset($_GET["redirect"])) header("Location: " . $_GET["redirect"]);
header("Location: /");
}
else var_dump("login incorreect");

View File

@ -81,6 +81,15 @@ class PostController extends Controller {
return file_get_contents(DIR."/html/post.html");
}
/**
* @route /^\/post\/[0-9]+\/delete\/$/
* @title Article
*/
public function delete() {
Post::remove(Post::get($_GET["post"]));
header("Location: /");
}
/**
* @route /^\/post\/[0-9]+\/upload\/$/
*/

View File

@ -36,13 +36,35 @@ class UserController extends Controller {
}
/**
* @route /\/users\/edit\/[0-9]+\/$/
* @route /\/users\/[0-9]+\/edit\/$/
* @admin
* @title Modifier un utilisateur
*/
public function editUser() {
$_GET['edit_user'] = explode("/", $_GET["page"])[3];
return \file_get_contents(DIR."/html/user_edit.html");
var_dump($_POST);
$_GET['edit_user'] = explode("/", $_GET["page"])[2];
if(isset($_POST["username"]) && isset($_POST["password"]) && isset($_POST["job"]) && isset($_POST["role"])) {
$user = Author::get($_GET["edit_user"]);
$user->setUsername($_POST["username"]);
if($_POST["password"] != '') $user->setPassword($_POST["password"]);
$user->setRole($_POST["role"]);
var_dump($user);
Author::update($user);
// header("Location: /users/");
}
return file_get_contents(DIR."/html/user_edit.html");
}
/**
* @route /\/users\/[0-9]+\/delete\/$/
* @admin
* @title Modifier un utilisateur
*/
public function deleteUser() {
$_GET['edit_user'] = explode("/", $_GET["page"])[2];
Author::remove(Author::get($_GET["edit_user"]));
header("Location: /users/");
}

View File

@ -6,80 +6,41 @@ use App\DB\Category;
use DateTime;
use App\DB\Tag;
use App\DB\Post;
use App\DB\Author;
class UserEditor extends \App\Tags\Tag {
public function render() {
if($_GET["post"] == "new") $_GET["post"] = null;
elseif(isset($_GET["post"])) $post = Post::get($_GET["post"]);
$user = Author::get($_GET["edit_user"]);
//recuperation de la balise de base (<tag type="bold">pouet</tag>)
$pok = $this->getElement();
$el = $this->getElement();
//recuperation du document (necessaire a la création de balises
$doc = $this->getDoc();
$type = $pok->getAttribute("element");
$type = $el->getAttribute("element");
switch ($type) {
case 'role':
foreach (array("Utilisateur" => "ROLE_USER", "Editeur" =>"ROLE_EDITOR", "Admin" => "ROLE_ADMIN") as $key => $value) {
$opt = $doc->createElement("option");
$opt->setAttribute("value", $value);
if($user->getRole() == $value) $opt->setAttribute("selected", "selected");
$opt->appendChild($doc->createTextNode($key));
$el->parentNode->appendChild();
}
$option = $doc->createElement("option");
$text = $doc->createTextNode("Categorie");
$option->setAttribute("value", "1");
$option->setAttribute("disabled", "true");
if(!isset($post)) $option->setAttribute("selected", "selected");
$option->appendChild($text);
$pok->parentNode->insertBefore($option, $pok);
foreach (Category::list() as $cat) {
$option = $doc->createElement("option");
$text = $doc->createTextNode($cat->getName());
$option->appendChild($text);
$option->setAttribute("value", $cat->getId());
if(isset($post) && $post->getCategory()->getId() == $cat->getId()) $option->setAttribute("selected", "selected");
$pok->parentNode->insertBefore($option, $pok);
$el->parentNode->appendChild($opt);
}
break;
case 'datetime':
if(isset($post)) $txt = $post->getDateTime();
else $txt = (new DateTime())->format('d/m/Y H:i:s');
$pok->parentNode->insertBefore($doc->createTextNode($txt), $pok);
break;
case 'content':
$tarea = $doc->createElement("textarea");
if(isset($post)) $tarea->appendChild($doc->createTextNode($post->getContent()));
$tarea->setAttribute("style", "width: 100%; min-height: 200px");
$pok->parentNode->insertBefore($tarea, $pok);
break;
case 'title':
case 'username':
$input = $doc->createElement("input");
$input->setAttribute("style", "width: 100%");
$input->setAttribute("placeholder", "titre");
if(isset($post)) $input->setAttribute("value", $post->getTitle());
$pok->parentNode->insertBefore($input, $pok);
$input->setAttribute("value", $user->getUsername());
$input->setAttribute("name", "username");
$el->parentNode->insertBefore($input, $el);
break;
case 'job':
$input = $doc->createElement("input");
$input->setAttribute("value", $user->getJob());
$input->setAttribute("name", "job");
$el->parentNode->insertBefore($input, $el);
break;
case 'tags':
foreach (Tag::list() as $el) {
$tg = $doc->createElement("input");
$tg->setAttribute("id", $el->getId());
$tg->setAttribute("type", "checkbox");
$tg->setAttribute("data-text", $el->getName());
if(isset($post)) {
if(in_array($el, $post->getTags())) $tg->setAttribute("checked", "checked");
}
$txt = $doc->createElement("label");
$txt->appendChild($doc->createTextNode($el->getName()));
$txt->setAttribute("for", $el->getId());
$pok->parentNode->insertBefore($tg, $pok);
$pok->parentNode->insertBefore($txt, $pok);
}
$btn = $doc->createElement("button");
$btn->appendChild($doc->createTextNode("Add Tag"));
$btn->setAttribute("class", "addTag");
$pok->parentNode->insertBefore($btn, $pok);
default:
# code...
break;

View File

@ -12,6 +12,7 @@ class Users extends Tag {
$parent = $el->parentNode;
foreach (Author::list(true, 1000) as $user) {
$pok = $el->childNodes->item(0)->cloneNode(true);
$pok->setAttribute("onclick", "window.location = window.location + '" . $user->getId() . "/edit/'");
$parent->insertBefore($pok, $el);

View File

@ -12,7 +12,7 @@ class Author {
private $password;
private $job;
private $job = "Aprenant";
private $role = "ROLE_USER";
@ -134,15 +134,16 @@ class Author {
}
public static function remove(Author $author) {
Functions::connect()->prepare("DELETE FROM author WHERE id=:id")->execute(array(":id" => $author->getId()));
Functions::connect()->prepare("DELETE FROM users WHERE id=:id")->execute(array(":id" => $author->getId()));
}
public static function update(Author $author) {
Functions::connect()->prepare("UPDATE author SET name=':name', password=':password', job=':job' WHERE id=:id")->execute(array(
Functions::connect()->prepare("UPDATE users SET username=:username, password=:password, job=:job, role=:role WHERE id=:id")->execute(array(
":username" => $author->getUsername(),
":password" => $author->getPassword(),
":job" => $author->getJob(),
":role" => $author->getRole(),
":id" => $author->getId()
));
}

View File

@ -286,7 +286,16 @@ class Post {
*
*/
public static function remove(Post $post) {
Functions::connect()->prepare("DELETE FROM posts WHERE id=:id")->execute(array(":id" => $post->getId()));
$id = $post->getId();
$prepared = Functions::connect()->prepare("DELETE FROM post_tag WHERE post_id=:id");
$prepared->bindValue(":id", $id, PDO::PARAM_INT);
$prepared->execute();
$prepared = Functions::connect()->prepare("DELETE FROM posts WHERE id=:id");
$prepared->bindValue(":id", $id, PDO::PARAM_INT);
$prepared->execute();
}