aboutsummaryrefslogtreecommitdiff
path: root/app/class
diff options
context:
space:
mode:
authorvincent-peugnet <v.peugnet@free.fr>2018-12-23 18:20:57 +0100
committervincent-peugnet <v.peugnet@free.fr>2018-12-23 18:20:57 +0100
commite8566a57cf1b9cc2eed10429f27840d17da945ef (patch)
tree9902d9f4dc2e871819af21ede642e50aaab1518b /app/class
parent532cdf4bb82ab7cc6fa7659d9aec3ce122b2ec52 (diff)
downloadwcms-e8566a57cf1b9cc2eed10429f27840d17da945ef.tar.gz
wcms-e8566a57cf1b9cc2eed10429f27840d17da945ef.zip
feature users
Diffstat (limited to 'app/class')
-rw-r--r--app/class/art2.php2
-rw-r--r--app/class/controlleradmin.php2
-rw-r--r--app/class/controllerart.php5
-rw-r--r--app/class/controllerhome.php2
-rw-r--r--app/class/controllerinfo.php2
-rw-r--r--app/class/controlleruser.php33
-rw-r--r--app/class/model.php2
-rw-r--r--app/class/modelart.php33
-rw-r--r--app/class/modeldb.php29
-rw-r--r--app/class/modelhome.php2
-rw-r--r--app/class/modeluser.php62
-rw-r--r--app/class/routes.php4
-rw-r--r--app/class/user.php64
13 files changed, 202 insertions, 40 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;