Advertisement
Guest User

Untitled

a guest
May 31st, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. 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... ^
  2.  
  3. public function change()
  4. {
  5. $table = $this->table('users', ['id' => false, 'primary_key' => ['id']]);
  6. $table->addColumn('id', 'uuid');
  7. $table->addColumn('email', 'string', [
  8. 'default' => null,
  9. 'limit' => 254,
  10. 'null' => false,
  11. ]);
  12. $table->addColumn('password', 'binary', [
  13. 'default' => null,
  14. 'null' => false,
  15. ]);
  16. $table->addColumn('created', 'datetime', [
  17. 'default' => null,
  18. 'null' => false,
  19. ]);
  20. $table->addColumn('modified', 'datetime', [
  21. 'default' => null,
  22. 'null' => false,
  23. ]);
  24. $table->create();
  25. }
  26.  
  27. public function beforeFilter(Event $event)
  28. {
  29. parent::beforeFilter($event);
  30.  
  31. $this->loadComponent('Auth', [
  32. 'authenticate' => [
  33. 'Digest' => [
  34. 'fields' => ['username' => 'email'],
  35. 'userModel' => 'Users',
  36. 'finder' => 'auth'
  37. ],
  38. ],
  39. 'loginAction' => [
  40. 'controller' => 'Users',
  41. 'action' => 'login'
  42. ],
  43. 'authError' => 'Dazu hast du keine Rechte...',
  44. 'storage' => 'Memory',
  45. 'unauthorizedRedirect' => false
  46. ]);
  47. }
  48.  
  49. public function beforeFilter(Event $event)
  50. {
  51. parent::beforeFilter($event);
  52. // Load the Type using the 'Elastic' provider.
  53. $this->loadModel('Users', 'Elastic');
  54.  
  55. $this->Auth->allow(['index', 'view']);
  56. if (!$this->Auth->user()){
  57. $this->Auth->allow('add');
  58. }
  59. }
  60.  
  61. public function edit($id = null)
  62. {
  63. $user = $this->Users->get($id, [
  64. 'contain' => []
  65. ]);
  66. if ($this->request->is(['patch', 'post', 'put'])) {
  67. $user = $this->Users->patchEntity($user, $this->request->data);
  68. if ($this->Users->save($user)) {
  69. $this->Flash->success(__('The user has been saved.'));
  70. return $this->redirect(['action' => 'index']);
  71. } else {
  72. $this->Flash->error(__('The user could not be saved. Please, try again.'));
  73. }
  74. }
  75. $this->set(compact('user'));
  76. $this->set('_serialize', ['user']);
  77. }
  78.  
  79. class User extends Entity
  80. {
  81. protected function _setPassword($password)
  82. {
  83. if (strlen($password) > 0) {
  84. return (new DefaultPasswordHasher)->hash($password);
  85. }
  86. }
  87. }
  88.  
  89. public function initialize(array $config)
  90. {
  91. $this->addBehavior('Timestamp', [
  92. 'events' => [
  93. 'Model.beforeSave' => [
  94. 'created_at' => 'new',
  95. 'modified_at' => 'always'
  96. ]
  97. ]
  98. ]);
  99. }
  100.  
  101. public function beforeSave(Event $event)
  102. {
  103. $entity = $event->data['entity'];
  104.  
  105. // Make a password for digest auth.
  106. $entity->password = DigestAuthenticate::password(
  107. $entity->email, //maybe change to username
  108. $entity->plain_password,
  109. env('SERVER_NAME')
  110. );
  111.  
  112. $entity->created = Time::now();
  113. return true;
  114. }
  115.  
  116. public function findAuth(CakeORMQuery $query, array $options)
  117. {
  118. $query
  119. ->select(['id', 'username', 'password'])
  120. ->where(['Users.active' => 1]);
  121.  
  122. return $query;
  123. }
  124.  
  125. <nav class="large-3 medium-4 columns" id="actions-sidebar">
  126. <ul class="side-nav">
  127. <li class="heading"><?= __('Actions') ?></li>
  128. <li><?= $this->Form->postLink(
  129. __('Delete'),
  130. ['action' => 'delete', $user->id],
  131. ['confirm' => __('Are you sure you want to delete # {0}?', $user->id)]
  132. )
  133. ?></li>
  134. <li><?= $this->Html->link(__('List Users'), ['action' => 'index']) ?> </li>
  135. </ul>
  136. </nav>
  137. <div class="users form large-9 medium-8 columns content">
  138. <?= $this->Form->create($user) ?>
  139. <fieldset>
  140. <legend><?= __('Edit User') ?></legend>
  141. <?php
  142. echo $this->Form->input('email');
  143. ?>
  144. </fieldset>
  145. <?= $this->Form->button(__('Submit')) ?>
  146. <?= $this->Form->end() ?>
  147. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement