diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2018-12-23 18:20:57 +0100 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2018-12-23 18:20:57 +0100 |
commit | e8566a57cf1b9cc2eed10429f27840d17da945ef (patch) | |
tree | 9902d9f4dc2e871819af21ede642e50aaab1518b | |
parent | 532cdf4bb82ab7cc6fa7659d9aec3ce122b2ec52 (diff) | |
download | wcms-e8566a57cf1b9cc2eed10429f27840d17da945ef.tar.gz wcms-e8566a57cf1b9cc2eed10429f27840d17da945ef.zip |
feature users
-rw-r--r-- | app/class/art2.php | 2 | ||||
-rw-r--r-- | app/class/controlleradmin.php | 2 | ||||
-rw-r--r-- | app/class/controllerart.php | 5 | ||||
-rw-r--r-- | app/class/controllerhome.php | 2 | ||||
-rw-r--r-- | app/class/controllerinfo.php | 2 | ||||
-rw-r--r-- | app/class/controlleruser.php | 33 | ||||
-rw-r--r-- | app/class/model.php | 2 | ||||
-rw-r--r-- | app/class/modelart.php | 33 | ||||
-rw-r--r-- | app/class/modeldb.php | 29 | ||||
-rw-r--r-- | app/class/modelhome.php | 2 | ||||
-rw-r--r-- | app/class/modeluser.php | 62 | ||||
-rw-r--r-- | app/class/routes.php | 4 | ||||
-rw-r--r-- | app/class/user.php | 64 | ||||
-rw-r--r-- | app/view/templates/backtopbar.php | 1 | ||||
-rw-r--r-- | app/view/templates/home.php | 16 | ||||
-rw-r--r-- | app/view/templates/user.php | 88 | ||||
-rw-r--r-- | assets/css/home.css | 13 | ||||
-rw-r--r-- | assets/css/read/003.css | 9 | ||||
-rw-r--r-- | assets/css/read/base.css | 8 | ||||
-rw-r--r-- | assets/css/read/blanc.css | 9 | ||||
-rw-r--r-- | assets/css/read/deux.css | 8 |
21 files changed, 301 insertions, 93 deletions
diff --git a/app/class/art2.php b/app/class/art2.php index 6f2d4d8..524caf6 100644 --- a/app/class/art2.php +++ b/app/class/art2.php @@ -424,7 +424,7 @@ class Art2 public function setid($id) { - if (strlen($id) < self::LEN and is_string($id)) { + if (strlen($id) < Model::MAX_ID_LENGTH and is_string($id)) { $this->id = strip_tags(strtolower(str_replace(" ", "", $id))); } } diff --git a/app/class/controlleradmin.php b/app/class/controlleradmin.php index fd33158..f01fbe5 100644 --- a/app/class/controlleradmin.php +++ b/app/class/controlleradmin.php @@ -23,6 +23,8 @@ class Controlleradmin extends Controller $admin = ['artlist' => $artlist, 'defaultartexist' => $defaultartexist, 'globalcss' => $globalcss, 'faviconlist' => $faviconlist]; $this->showtemplate('admin', $admin); + } else { + $this->routedirect('home'); } } diff --git a/app/class/controllerart.php b/app/class/controllerart.php index 7bc8c23..c097df4 100644 --- a/app/class/controllerart.php +++ b/app/class/controllerart.php @@ -24,8 +24,9 @@ class Controllerart extends Controller $cleanid = idclean($id); if ($cleanid !== $id) { $this->routedirect($route, ['art' => $cleanid]); + } else { + $this->art = new Art2(['id' => $cleanid]); } - $this->art = new Art2(['id' => $cleanid]); } public function importart() @@ -33,7 +34,6 @@ class Controllerart extends Controller $art = $this->artmanager->get($this->art); if ($art !== false) { $this->art = $art; - //$this->art->autotaglistupdate($this->artmanager->taglist($this->artmanager->getlister(['id', 'title', 'description', 'tag']), $this->art->autotaglist())); return true; } else { return false; @@ -149,7 +149,6 @@ class Controllerart extends Controller { $this->setart($id, 'artlog'); $this->importart(); - var_dump($this->art); } public function add($id) diff --git a/app/class/controllerhome.php b/app/class/controllerhome.php index 1309adb..c9ae8d4 100644 --- a/app/class/controllerhome.php +++ b/app/class/controllerhome.php @@ -2,7 +2,7 @@ class Controllerhome extends Controller { - + /** @var Modelhome */ protected $modelhome; protected $opt; diff --git a/app/class/controllerinfo.php b/app/class/controllerinfo.php index 306c818..82d247d 100644 --- a/app/class/controllerinfo.php +++ b/app/class/controllerinfo.php @@ -5,8 +5,6 @@ class Controllerinfo extends Controller public function __construct($render) { parent::__construct($render); - - } public function desktop() diff --git a/app/class/controlleruser.php b/app/class/controlleruser.php new file mode 100644 index 0000000..78dd6c1 --- /dev/null +++ b/app/class/controlleruser.php @@ -0,0 +1,33 @@ +<?php + +class Controlleruser extends Controller +{ + + public function __construct($render) { + parent::__construct($render); + } + + public function desktop() + { + if($this->user->isadmin()) { + $userlist = $this->usermanager->getlister(); + $this->showtemplate('user', ['userlist' => $userlist]); + } else { + $this->routedirect('home'); + } + } + + public function add() + { + if(isset($_POST['id'])) { + $user = new User($_POST); + if(!$this->usermanager->get($user)) { + $this->usermanager->add($user); + } + } + } +} + + + +?>
\ No newline at end of file diff --git a/app/class/model.php b/app/class/model.php index ee8de26..770a8f5 100644 --- a/app/class/model.php +++ b/app/class/model.php @@ -17,6 +17,8 @@ abstract class Model const TEXT_ELEMENTS = ['header', 'nav', 'main', 'aside', 'footer']; const EDIT_SYMBOLS = ['pen', 'tool', 'none']; + const MAX_ID_LENGTH = 64; + public static function dirtopath($dir) { $basepath = ''; diff --git a/app/class/modelart.php b/app/class/modelart.php index ac4f91e..f80826a 100644 --- a/app/class/modelart.php +++ b/app/class/modelart.php @@ -10,6 +10,31 @@ class Modelart extends Modeldb public function __construct() { parent::__construct(); + $this->storeinit(Config::arttable()); + } + + public function getlister() + { + $artlist = []; + $list = $this->repo->findAll(); + foreach ($list as $artdata) { + $artlist[$artdata->id] = new Art2($artdata); + } + return $artlist; + } + + + public function getlisterid(array $idlist = []) + { + $artdatalist = $this->repo->query() + ->where('__id', 'IN', $idlist) + ->execute(); + + $artlist = []; + foreach ($artdatalist as $id => $artdata) { + $artlist[$id] = new Art2($artdata); + } + return $artlist; } public function add(Art2 $art) @@ -17,7 +42,7 @@ class Modelart extends Modeldb $artdata = new \JamesMoss\Flywheel\Document($art->dry()); $artdata->setId($art->id()); - $this->artstore->store($artdata); + $this->repo->store($artdata); } @@ -27,7 +52,7 @@ class Modelart extends Modeldb $id = $id->id(); } if (is_string($id)) { - $artdata = $this->artstore->findById($id); + $artdata = $this->repo->findById($id); if ($artdata !== false) { return new Art2($artdata); } else { @@ -52,7 +77,7 @@ class Modelart extends Modeldb public function delete(Art2 $art) { - $this->artstore->delete($art->id()); + $this->repo->delete($art->id()); $this->unlink($art->id()); } @@ -71,7 +96,7 @@ class Modelart extends Modeldb { $artdata = new \JamesMoss\Flywheel\Document($art->dry()); $artdata->setId($art->id()); - $this->artstore->store($artdata); + $this->repo->store($artdata); } public function artcompare($art1, $art2, $method = 'id', $order = 1) diff --git a/app/class/modeldb.php b/app/class/modeldb.php index bc2a0c7..ef1d351 100644 --- a/app/class/modeldb.php +++ b/app/class/modeldb.php @@ -1,10 +1,9 @@ <?php class Modeldb extends Model { - protected $arttable; protected $database; /** @var \WFlywheel\Repository */ - protected $artstore; + protected $repo; public function __construct() @@ -19,37 +18,19 @@ class Modeldb extends Model 'query_class' => "\WFlywheel\Query", 'formatter' => new \WFlywheel\Formatter\JSON, ]); - $this->artstore = new \WFlywheel\Repository(Config::arttable(), $this->database); } - - public function getlister() + public function storeinit(string $repo) { - $artlist = []; - $list = $this->artstore->findAll(); - foreach ($list as $artdata) { - $artlist[$artdata->id] = new Art2($artdata); - } - return $artlist; + $this->repo = new \WFlywheel\Repository($repo, $this->database); } public function list() { - return $this->artstore->getAllIds(); + return $this->repo->getAllIds(); } - public function getlisterid(array $idlist = []) - { - $artdatalist = $this->artstore->query() - ->where('__id', 'IN', $idlist) - ->execute(); - - $artlist = []; - foreach ($artdatalist as $id => $artdata) { - $artlist[$id] = new Art2($artdata); - } - return $artlist; - } + diff --git a/app/class/modelhome.php b/app/class/modelhome.php index bb271d6..07c89d8 100644 --- a/app/class/modelhome.php +++ b/app/class/modelhome.php @@ -1,6 +1,6 @@ <?php -class Modelhome extends Modeldb +class Modelhome extends Modelart { public function __construct() { diff --git a/app/class/modeluser.php b/app/class/modeluser.php index a0f0966..e9474e0 100644 --- a/app/class/modeluser.php +++ b/app/class/modeluser.php @@ -1,6 +1,6 @@ <?php -class Modeluser extends Model +class Modeluser extends Modeldb { const ADMIN = 10; const EDITOR = 3; @@ -8,6 +8,13 @@ class Modeluser extends Model const READ = 1; const FREE = 0; + const USER_REPO_NAME = 'user'; + + public function __construct() + { + parent::__construct(); + $this->storeinit(self::USER_REPO_NAME); + } public function writesession(User $user) { @@ -60,6 +67,59 @@ class Modeluser extends Model $user = new User(['level' => self::FREE]); return $user; } + + + + public function getlister() + { + $userlist = []; + $list = $this->repo->findAll(); + foreach ($list as $userdata) { + $userlist[$userdata->id] = new User($userdata); + } + return $userlist; + } + + + public function getlisterid(array $idlist = []) + { + $userdatalist = $this->repo->query() + ->where('__id', 'IN', $idlist) + ->execute(); + + $userlist = []; + foreach ($userdatalist as $id => $userdata) { + $userlist[$id] = new User($userdata); + } + return $userlist; + } + + public function add(User $user) + { + $userdata = new \JamesMoss\Flywheel\Document($user->dry()); + $userdata->setId($user->id()); + $this->repo->store($userdata); + } + + + public function get($id) + { + if ($id instanceof User) { + $id = $id->id(); + } + if (is_string($id)) { + $userdata = $this->repo->findById($id); + if ($userdata !== false) { + return new User($userdata); + } else { + return false; + } + } else { + return false; + } + } + + } diff --git a/app/class/routes.php b/app/class/routes.php index c222445..811422f 100644 --- a/app/class/routes.php +++ b/app/class/routes.php @@ -24,6 +24,10 @@ class Routes ['GET', '/!font', 'Controllerfont#desktop', 'font'], ['POST', '/!admin', 'Controlleradmin#update', 'adminupdate'], ['GET', '/!admin', 'Controlleradmin#desktop', 'admin'], + ['GET', '/!user', 'Controlleruser#desktop', 'user'], + ['POST', '/!user/add', 'Controlleruser#add', 'useradd'], + ['POST', '/!user/update', 'Controlleruser#update', 'userupdate'], + ['POST', '/!user/delete', 'Controlleruser#delete', 'userdelete'], ['GET', '/!info', 'Controllerinfo#desktop', 'info'], ['GET', '/!font/render', 'Controllerfont#render', 'fontrender'], ['POST', '/!font/add', 'Controllerfont#add', 'fontadd'], diff --git a/app/class/user.php b/app/class/user.php index fc5a665..fa6589c 100644 --- a/app/class/user.php +++ b/app/class/user.php @@ -2,7 +2,9 @@ class User { + protected $id; protected $level = 0; + protected $signature = ''; protected $password; public function __construct($datas = []) { @@ -11,7 +13,7 @@ class User } } - public function hydrate(array $datas = []) + public function hydrate($datas = []) { foreach ($datas as $key => $value) { $method = 'set' . $key; @@ -21,10 +23,19 @@ class User } } } + + public function dry() + { + $array = []; + foreach (get_class_vars(__class__) as $var => $value) { + $array[$var] = $this->$var(); + } + return $array; + } - public function setlevel($level) + public function id() { - $this->level = $level; + return $this->id; } public function level() @@ -32,6 +43,53 @@ class User return $this->level; } + public function password($type = 'string') + { + if($type === 'int') { + return strlen($this->password); + } elseif ($type = 'string') { + return $this->password; + } + } + + public function signature() + { + return $this->signature; + } + + public function setid($id) + { + if (strlen($id) < Model::MAX_ID_LENGTH and is_string($id)) { + $this->id = idclean($id); + } + } + + public function setlevel($level) + { + $level = intval($level); + if($level >= 0 && $level <= 10) { + $this->level = $level; + } + } + + public function setpassword(string $password) + { + if(strlen($password) >= 4 && strlen($password) <= 32) { + $this->password = $password; + } + } + + public function setsignature(string $signature) + { + if(strlen($signature) <= 128) { + $this->signature = $signature; + } + } + + + + + public function isvisitor() { return $this->level === Modeluser::FREE; diff --git a/app/view/templates/backtopbar.php b/app/view/templates/backtopbar.php index d769993..1243a17 100644 --- a/app/view/templates/backtopbar.php +++ b/app/view/templates/backtopbar.php @@ -48,6 +48,7 @@ <?php if($user->isadmin()) { ?> +<a href="<?= $this->url('user') ?>" <?= $tab == 'user' ? 'class="actualpage"' : '' ?>>user</a> <a href="<?= $this->url('admin') ?>" <?= $tab == 'admin' ? 'class="actualpage"' : '' ?>>admin</a> <?php } diff --git a/app/view/templates/home.php b/app/view/templates/home.php index 521d985..a59fddf 100644 --- a/app/view/templates/home.php +++ b/app/view/templates/home.php @@ -27,12 +27,11 @@ <div id="main"> -<h2>Articles</h2> +<h2>Pages</h2> <form action="/massedit" method="post"> <div id="massedit"> - <h3>Mass Edit</h3> <select name="massedit" required> <option value="public">set as public</option> <option value="private">set as private</option> @@ -45,19 +44,6 @@ <input type="submit" name="massaction" value="do" onclick="confirmSubmit(event, 'Are you sure')" > - <input type="text" name="targettag" placeholder="add tag"> - <input type="submit" name="massaction" value="add tag" onclick="confirmSubmit(event, 'Are you sure')" > - - <select name="masstemplate"> - <?php - foreach ($table2 as $art) { - echo '<option value="' . $art->id() . '">' . $art->id() . '</option>'; - } - ?> - </select> - - <input type="submit" name="massaction" value="set template" onclick="confirmSubmit(event, 'Are you sure')" > - <input type="hidden" name="action" value="massedit"> </div> diff --git a/app/view/templates/user.php b/app/view/templates/user.php new file mode 100644 index 0000000..8615f3d --- /dev/null +++ b/app/view/templates/user.php @@ -0,0 +1,88 @@ +<?php $this->layout('layout', ['title' => 'user', 'css' => $css . 'home.css']) ?> + + +<?php $this->start('page') ?> + +<body> + + <?php $this->insert('backtopbar', ['user' => $user, 'tab' => 'user']) ?> + + +<main class="user"> + +<table> +<tr> +<th>id</th><th>password</th><th>level</th><th>action</th> +</tr> + +<tr> + <form action="<?= $this->url('useradd') ?>" method="post"> + <td> + <input type="text" name="id" required> + </td> + <td> + <input type="password" name="password" minlength="4" maxlenght="64" required> + </td> + <td> + <select name="level" id="level"> + <option value="1">reader</option> + <option value="2">invite</option> + <option value="3">editor</option> + <option value="4">super editor</option> + </select> + </td> + <td> + <input type="submit" value="add"> + </td> + </form> +</tr> + + +<?php +foreach ($userlist as $user ) { + ?> + + <tr> + <form action="<?= $this->url('userupdate') ?>"> + + <td> + <?= $user->id() ?> + </td> + + <td> + <input type="password" name="password" placeholder="<?= str_repeat('°', $user->password('int')) ?>" min="4" max="64" required> + </td> + + <td> + <select name="level" id="level"> + <option value="1" <?= $user->level() === 1 ? 'selected' : '' ?>>reader</option> + <option value="2" <?= $user->level() === 2 ? 'selected' : '' ?>>invite</option> + <option value="3" <?= $user->level() === 3 ? 'selected' : '' ?>>editor</option> + <option value="4" <?= $user->level() === 4 ? 'selected' : '' ?>>super editor</option> + </select> + </td> + + <td> + <input type="submit" value="update"> + </form> + + <form action="<?= $this->url('userdelete') ?>" method="post"> + <input type="submit" value="delete"> + </form> + </td> + + </tr> + + <?php + } +?> + +</table> + +<?php var_dump($userlist); ?> + + +</main> +</body> + +<?php $this->stop('page') ?>
\ No newline at end of file diff --git a/assets/css/home.css b/assets/css/home.css index 540651a..8ce48ca 100644 --- a/assets/css/home.css +++ b/assets/css/home.css @@ -52,10 +52,6 @@ a:hover { color: white; } -div#massedit { - display: none; -} - #options ul { list-style: none; padding-inline-start: 0; @@ -227,6 +223,15 @@ main.media code { padding: 1px; } + + +main.user table form { + display: inline-block; +} + + + + @media (max-width: 600px) { main.home .summary, main.home .linkfrom, main.home .linkto, main.home .delete, main.home .datecreation, main.home .date, main.home .log, main.home .secure, main.home .tag { display: none; diff --git a/assets/css/read/003.css b/assets/css/read/003.css deleted file mode 100644 index 7dd8f17..0000000 --- a/assets/css/read/003.css +++ /dev/null @@ -1,9 +0,0 @@ -body { - font-family: serif; - background-color: white; -} - -span.alert { - background-color: #d00000; - color: white; -}
\ No newline at end of file diff --git a/assets/css/read/base.css b/assets/css/read/base.css deleted file mode 100644 index 561963a..0000000 --- a/assets/css/read/base.css +++ /dev/null @@ -1,8 +0,0 @@ -body { - font-family: sans-serif; -} - -span.alert { - background-color: #d00000; - color: white; -}
\ No newline at end of file diff --git a/assets/css/read/blanc.css b/assets/css/read/blanc.css deleted file mode 100644 index 7dd8f17..0000000 --- a/assets/css/read/blanc.css +++ /dev/null @@ -1,9 +0,0 @@ -body { - font-family: serif; - background-color: white; -} - -span.alert { - background-color: #d00000; - color: white; -}
\ No newline at end of file diff --git a/assets/css/read/deux.css b/assets/css/read/deux.css deleted file mode 100644 index cd44f4f..0000000 --- a/assets/css/read/deux.css +++ /dev/null @@ -1,8 +0,0 @@ -body { - font-family: serif; -} - -span.alert { - background-color: #d00000; - color: white; -}
\ No newline at end of file |