Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Error: SQLSTATE[42703]: Undefined column: 7 ERROR: Column users.username doesn't exist LINE 1: SELECT Users.id AS "Users__id", Users.username AS "Users__us... ^
- public function change()
- {
- $table = $this->table('users', ['id' => false, 'primary_key' => ['id']]);
- $table->addColumn('id', 'uuid');
- $table->addColumn('email', 'string', [
- 'default' => null,
- 'limit' => 254,
- 'null' => false,
- ]);
- $table->addColumn('password', 'binary', [
- 'default' => null,
- 'null' => false,
- ]);
- $table->addColumn('created', 'datetime', [
- 'default' => null,
- 'null' => false,
- ]);
- $table->addColumn('modified', 'datetime', [
- 'default' => null,
- 'null' => false,
- ]);
- $table->create();
- }
- public function beforeFilter(Event $event)
- {
- parent::beforeFilter($event);
- $this->loadComponent('Auth', [
- 'authenticate' => [
- 'Digest' => [
- 'fields' => ['username' => 'email'],
- 'userModel' => 'Users',
- 'finder' => 'auth'
- ],
- ],
- 'loginAction' => [
- 'controller' => 'Users',
- 'action' => 'login'
- ],
- 'authError' => 'Dazu hast du keine Rechte...',
- 'storage' => 'Memory',
- 'unauthorizedRedirect' => false
- ]);
- }
- public function beforeFilter(Event $event)
- {
- parent::beforeFilter($event);
- // Load the Type using the 'Elastic' provider.
- $this->loadModel('Users', 'Elastic');
- $this->Auth->allow(['index', 'view']);
- if (!$this->Auth->user()){
- $this->Auth->allow('add');
- }
- }
- public function edit($id = null)
- {
- $user = $this->Users->get($id, [
- 'contain' => []
- ]);
- if ($this->request->is(['patch', 'post', 'put'])) {
- $user = $this->Users->patchEntity($user, $this->request->data);
- if ($this->Users->save($user)) {
- $this->Flash->success(__('The user has been saved.'));
- return $this->redirect(['action' => 'index']);
- } else {
- $this->Flash->error(__('The user could not be saved. Please, try again.'));
- }
- }
- $this->set(compact('user'));
- $this->set('_serialize', ['user']);
- }
- class User extends Entity
- {
- protected function _setPassword($password)
- {
- if (strlen($password) > 0) {
- return (new DefaultPasswordHasher)->hash($password);
- }
- }
- }
- public function initialize(array $config)
- {
- $this->addBehavior('Timestamp', [
- 'events' => [
- 'Model.beforeSave' => [
- 'created_at' => 'new',
- 'modified_at' => 'always'
- ]
- ]
- ]);
- }
- public function beforeSave(Event $event)
- {
- $entity = $event->data['entity'];
- // Make a password for digest auth.
- $entity->password = DigestAuthenticate::password(
- $entity->email, //maybe change to username
- $entity->plain_password,
- env('SERVER_NAME')
- );
- $entity->created = Time::now();
- return true;
- }
- public function findAuth(CakeORMQuery $query, array $options)
- {
- $query
- ->select(['id', 'username', 'password'])
- ->where(['Users.active' => 1]);
- return $query;
- }
- <nav class="large-3 medium-4 columns" id="actions-sidebar">
- <ul class="side-nav">
- <li class="heading"><?= __('Actions') ?></li>
- <li><?= $this->Form->postLink(
- __('Delete'),
- ['action' => 'delete', $user->id],
- ['confirm' => __('Are you sure you want to delete # {0}?', $user->id)]
- )
- ?></li>
- <li><?= $this->Html->link(__('List Users'), ['action' => 'index']) ?> </li>
- </ul>
- </nav>
- <div class="users form large-9 medium-8 columns content">
- <?= $this->Form->create($user) ?>
- <fieldset>
- <legend><?= __('Edit User') ?></legend>
- <?php
- echo $this->Form->input('email');
- ?>
- </fieldset>
- <?= $this->Form->button(__('Submit')) ?>
- <?= $this->Form->end() ?>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement