linkedin + some css

This commit is contained in:
2019-03-07 16:32:27 +01:00
parent 081ed3a1de
commit a4d60d2f76
9 changed files with 89 additions and 18 deletions

View File

@ -19,6 +19,7 @@ class UserController extends Controller {
$user->setUsername($_POST["username"]);
$user->setPassword($_POST["password"]);
$user->setRole($_POST["role"]);
$user->setLinkedin($_POST["linkedin"]);
Author::add($user);
header("Location: /users/");
}
@ -49,12 +50,34 @@ class UserController extends Controller {
if($_POST["password"] != '') $user->setPassword($_POST["password"]);
$user->setRole($_POST["role"]);
$user->setJob($_POST["job"]);
$user->setLinkedin($_POST["linkedin"]);
Author::update($user);
header("Location: /users/");
}
return file_get_contents(DIR."/html/user_edit.html");
}
/**
* @route /\/user\/edit\/$/
* @editor
* @title Modifier un utilisateur
*/
public function userEdit() {
$_GET['edit_user'] = $_SESSION["author"]->getId();
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"]);
$user->setJob($_POST["job"]);
$user->setLinkedin($_POST["linkedin"]);
Author::update($user);
header("Location: /");
}
return file_get_contents(DIR."/html/user_edit.html");
}
/**
* @route /\/users\/[0-9]+\/delete\/$/
* @admin

View File

@ -21,9 +21,18 @@ class AuthorTag extends Tag {
$doc = $this->getDoc();
$col = "get" . ucfirst($attr);
if($attr == "username") {
$txt = $doc->createElement("a");
$txt->setAttribute("href", "https://www.linkedin.com/in/".$author->getLinkedin() . "/");
$txt->setAttribute("target", "_blank");
$txt->appendChild($doc->createTextNode($author->getUsername()));
} else {
$col = "get" . ucfirst($attr);
$txt = $doc->createTextNode($author->$col());
}
$txt = $doc->createTextNode($author->$col());
$pok->parentNode->insertBefore($txt, $pok);
}

View File

@ -36,6 +36,13 @@ class UserEditor extends \App\Tags\Tag {
$input->setAttribute("placeholder", "Nom d'utilisateur");
$el->parentNode->insertBefore($input, $el);
break;
case 'linkedin':
$input = $doc->createElement("input");
$input->setAttribute("value", $user->getLinkedin());
$input->setAttribute("name", "linkedin");
$input->setAttribute("placeholder", "https://www.linkedin.com/in/ton_nom_dutilisateur/");
$el->parentNode->insertBefore($input, $el);
break;
case 'job':
$input = $doc->createElement("input");
$input->setAttribute("value", $user->getJob());

View File

@ -16,6 +16,8 @@ class Author {
private $role = "ROLE_USER";
private $linkedin;
public function __construct(){}
public function getId() {
@ -42,6 +44,10 @@ class Author {
return $this->role;
}
public function getLinkedin() {
return $this->linkedin;
}
public function setId($id) {
$this->id = $id;
}
@ -66,6 +72,10 @@ class Author {
$this->role = $role;
}
public function setLinkedin($linkedin) {
$this->linkedin = $linkedin;
}
@ -80,6 +90,7 @@ class Author {
$au->setUsername($array["username"]);
$au->setHashedPassword($array["password"]);
$au->setJob($array["job"]);
$au->setLinkedin($array["linkedin"]);
$au->setRole($array["role"]);
return $au;
}
@ -113,13 +124,14 @@ class Author {
}
public static function add(Author $author) {
$query = "INSERT INTO users (id, username, password, job, role)
VALUES (NULL, :username, :password, :job, :role);";
$query = "INSERT INTO users (id, username, password, job, role, linkedin)
VALUES (NULL, :username, :password, :job, :role, :linkedin);";
$username = $author->getUsername();
$password = $author->getPassword();
$job = $author->getJob();
$role = $author->getRole();
$linkedin = $author->getLinkedin();
$pdo = Functions::connect();
$prepared = $pdo->prepare($query);
@ -127,6 +139,7 @@ class Author {
$prepared->bindParam(":password", $password);
$prepared->bindParam(":job", $job);
$prepared->bindParam(":role", $role);
$prepared->bindParam(":linkedin", $linkedin);
$prepared->execute();
// var_dump($prepared->errorInfo());
// die;
@ -139,11 +152,12 @@ class Author {
}
public static function update(Author $author) {
Functions::connect()->prepare("UPDATE users SET username=:username, password=:password, job=:job, role=:role WHERE id=:id")->execute(array(
Functions::connect()->prepare("UPDATE users SET username=:username, password=:password, job=:job, role=:role, linkedin=:linkedin WHERE id=:id")->execute(array(
":username" => $author->getUsername(),
":password" => $author->getPassword(),
":job" => $author->getJob(),
":role" => $author->getRole(),
":linkedin" => $author->getLinkedin(),
":id" => $author->getId()
));
}