From a25f6e05de54f9c0386910641ddba555a87d6574 Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Fri, 13 Sep 2019 10:31:02 +0000 Subject: [PATCH] adding serverUsers --- mithril_client | 2 +- src/Controller/ServerUsersController.php | 106 +++++++++++++++++++++++ src/Model/Entity/ServerUser.php | 49 +++++++++++ src/Model/Table/ServerUsersTable.php | 101 +++++++++++++++++++++ src/Template/Pages/gradido.ctp | 14 +++ src/Template/ServerUsers/add.ctp | 28 ++++++ src/Template/ServerUsers/edit.ctp | 34 ++++++++ src/Template/ServerUsers/index.ctp | 61 +++++++++++++ src/Template/ServerUsers/view.ctp | 56 ++++++++++++ 9 files changed, 450 insertions(+), 1 deletion(-) create mode 100644 src/Controller/ServerUsersController.php create mode 100644 src/Model/Entity/ServerUser.php create mode 100644 src/Model/Table/ServerUsersTable.php create mode 100644 src/Template/Pages/gradido.ctp create mode 100644 src/Template/ServerUsers/add.ctp create mode 100644 src/Template/ServerUsers/edit.ctp create mode 100644 src/Template/ServerUsers/index.ctp create mode 100644 src/Template/ServerUsers/view.ctp diff --git a/mithril_client b/mithril_client index 132a1de23..055f2bb57 160000 --- a/mithril_client +++ b/mithril_client @@ -1 +1 @@ -Subproject commit 132a1de23b48f3b685e05fce6e1fbbb25b74671d +Subproject commit 055f2bb572244fbd5b4d71c2ca84d4493ae88dd1 diff --git a/src/Controller/ServerUsersController.php b/src/Controller/ServerUsersController.php new file mode 100644 index 000000000..7bc23e033 --- /dev/null +++ b/src/Controller/ServerUsersController.php @@ -0,0 +1,106 @@ +paginate($this->ServerUsers); + + $this->set(compact('serverUsers')); + } + + /** + * View method + * + * @param string|null $id Server User id. + * @return \Cake\Http\Response|null + * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + */ + public function view($id = null) + { + $serverUser = $this->ServerUsers->get($id, [ + 'contain' => [] + ]); + + $this->set('serverUser', $serverUser); + } + + /** + * Add method + * + * @return \Cake\Http\Response|null Redirects on successful add, renders view otherwise. + */ + public function add() + { + $serverUser = $this->ServerUsers->newEntity(); + if ($this->request->is('post')) { + $serverUser = $this->ServerUsers->patchEntity($serverUser, $this->request->getData()); + if ($this->ServerUsers->save($serverUser)) { + $this->Flash->success(__('The server user has been saved.')); + + return $this->redirect(['action' => 'index']); + } + $this->Flash->error(__('The server user could not be saved. Please, try again.')); + } + $this->set(compact('serverUser')); + } + + /** + * Edit method + * + * @param string|null $id Server User id. + * @return \Cake\Http\Response|null Redirects on successful edit, renders view otherwise. + * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + */ + public function edit($id = null) + { + $serverUser = $this->ServerUsers->get($id, [ + 'contain' => [] + ]); + if ($this->request->is(['patch', 'post', 'put'])) { + $serverUser = $this->ServerUsers->patchEntity($serverUser, $this->request->getData()); + if ($this->ServerUsers->save($serverUser)) { + $this->Flash->success(__('The server user has been saved.')); + + return $this->redirect(['action' => 'index']); + } + $this->Flash->error(__('The server user could not be saved. Please, try again.')); + } + $this->set(compact('serverUser')); + } + + /** + * Delete method + * + * @param string|null $id Server User id. + * @return \Cake\Http\Response|null Redirects to index. + * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. + */ + public function delete($id = null) + { + $this->request->allowMethod(['post', 'delete']); + $serverUser = $this->ServerUsers->get($id); + if ($this->ServerUsers->delete($serverUser)) { + $this->Flash->success(__('The server user has been deleted.')); + } else { + $this->Flash->error(__('The server user could not be deleted. Please, try again.')); + } + + return $this->redirect(['action' => 'index']); + } +} diff --git a/src/Model/Entity/ServerUser.php b/src/Model/Entity/ServerUser.php new file mode 100644 index 000000000..c180e060f --- /dev/null +++ b/src/Model/Entity/ServerUser.php @@ -0,0 +1,49 @@ + true, + 'password' => true, + 'email' => true, + 'role' => true, + 'activated' => true, + 'last_login' => true, + 'created' => true, + 'modified' => true + ]; + + /** + * Fields that are excluded from JSON versions of the entity. + * + * @var array + */ + protected $_hidden = [ + 'password' + ]; +} diff --git a/src/Model/Table/ServerUsersTable.php b/src/Model/Table/ServerUsersTable.php new file mode 100644 index 000000000..63b6fb2fe --- /dev/null +++ b/src/Model/Table/ServerUsersTable.php @@ -0,0 +1,101 @@ +setTable('server_users'); + $this->setDisplayField('id'); + $this->setPrimaryKey('id'); + + $this->addBehavior('Timestamp'); + } + + /** + * Default validation rules. + * + * @param \Cake\Validation\Validator $validator Validator instance. + * @return \Cake\Validation\Validator + */ + public function validationDefault(Validator $validator) + { + $validator + ->integer('id') + ->allowEmptyString('id', null, 'create'); + + $validator + ->scalar('username') + ->maxLength('username', 50) + ->requirePresence('username', 'create') + ->notEmptyString('username'); + + $validator + ->scalar('password') + ->maxLength('password', 255) + ->requirePresence('password', 'create') + ->notEmptyString('password'); + + $validator + ->email('email') + ->requirePresence('email', 'create') + ->notEmptyString('email'); + + $validator + ->scalar('role') + ->maxLength('role', 20) + ->notEmptyString('role'); + + $validator + ->boolean('activated') + ->notEmptyString('activated'); + + $validator + ->dateTime('last_login') + ->allowEmptyDateTime('last_login'); + + return $validator; + } + + /** + * Returns a rules checker object that will be used for validating + * application integrity. + * + * @param \Cake\ORM\RulesChecker $rules The rules object to be modified. + * @return \Cake\ORM\RulesChecker + */ + public function buildRules(RulesChecker $rules) + { + $rules->add($rules->isUnique(['username'])); + $rules->add($rules->isUnique(['email'])); + + return $rules; + } +} diff --git a/src/Template/Pages/gradido.ctp b/src/Template/Pages/gradido.ctp new file mode 100644 index 000000000..14d4bb3fc --- /dev/null +++ b/src/Template/Pages/gradido.ctp @@ -0,0 +1,14 @@ +layout = false;?> + + Web Assembly Test (CakePHP Single Node Version) + + + +
Wird geladen...
+ + + + + \ No newline at end of file diff --git a/src/Template/ServerUsers/add.ctp b/src/Template/ServerUsers/add.ctp new file mode 100644 index 000000000..668ea0fa0 --- /dev/null +++ b/src/Template/ServerUsers/add.ctp @@ -0,0 +1,28 @@ + + +
+ Form->create($serverUser) ?> +
+ + Form->control('username'); + echo $this->Form->control('password'); + echo $this->Form->control('email'); + echo $this->Form->control('role'); + echo $this->Form->control('activated'); + echo $this->Form->control('last_login', ['empty' => true]); + ?> +
+ Form->button(__('Submit')) ?> + Form->end() ?> +
diff --git a/src/Template/ServerUsers/edit.ctp b/src/Template/ServerUsers/edit.ctp new file mode 100644 index 000000000..b5045f45f --- /dev/null +++ b/src/Template/ServerUsers/edit.ctp @@ -0,0 +1,34 @@ + + +
+ Form->create($serverUser) ?> +
+ + Form->control('username'); + echo $this->Form->control('password'); + echo $this->Form->control('email'); + echo $this->Form->control('role'); + echo $this->Form->control('activated'); + echo $this->Form->control('last_login', ['empty' => true]); + ?> +
+ Form->button(__('Submit')) ?> + Form->end() ?> +
diff --git a/src/Template/ServerUsers/index.ctp b/src/Template/ServerUsers/index.ctp new file mode 100644 index 000000000..25ff72dd6 --- /dev/null +++ b/src/Template/ServerUsers/index.ctp @@ -0,0 +1,61 @@ + + +
+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Paginator->sort('id') ?>Paginator->sort('username') ?>Paginator->sort('password') ?>Paginator->sort('email') ?>Paginator->sort('role') ?>Paginator->sort('activated') ?>Paginator->sort('last_login') ?>Paginator->sort('created') ?>Paginator->sort('modified') ?>
Number->format($serverUser->id) ?>username) ?>password) ?>email) ?>role) ?>activated) ?>last_login) ?>created) ?>modified) ?> + Html->link(__('View'), ['action' => 'view', $serverUser->id]) ?> + Html->link(__('Edit'), ['action' => 'edit', $serverUser->id]) ?> + Form->postLink(__('Delete'), ['action' => 'delete', $serverUser->id], ['confirm' => __('Are you sure you want to delete # {0}?', $serverUser->id)]) ?> +
+
+
    + Paginator->first('<< ' . __('first')) ?> + Paginator->prev('< ' . __('previous')) ?> + Paginator->numbers() ?> + Paginator->next(__('next') . ' >') ?> + Paginator->last(__('last') . ' >>') ?> +
+

Paginator->counter(['format' => __('Page {{page}} of {{pages}}, showing {{current}} record(s) out of {{count}} total')]) ?>

+
+
diff --git a/src/Template/ServerUsers/view.ctp b/src/Template/ServerUsers/view.ctp new file mode 100644 index 000000000..1e16a1528 --- /dev/null +++ b/src/Template/ServerUsers/view.ctp @@ -0,0 +1,56 @@ + + +
+

id) ?>

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
username) ?>
password) ?>
email) ?>
role) ?>
Number->format($serverUser->id) ?>
last_login) ?>
created) ?>
modified) ?>
activated ? __('Yes') : __('No'); ?>
+