|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
namespace App\Model\Table; |
|
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
use Cake\ORM\Query; |
|
|
|
|
|
|
5
|
|
|
use Cake\ORM\RulesChecker; |
|
6
|
|
|
use Cake\ORM\Table; |
|
7
|
|
|
use Cake\Validation\Validator; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Users Model |
|
11
|
|
|
* |
|
12
|
|
|
* @method \App\Model\Entity\User get($primaryKey, $options = []) |
|
13
|
|
|
* @method \App\Model\Entity\User newEntity($data = null, array $options = []) |
|
14
|
|
|
* @method \App\Model\Entity\User[] newEntities(array $data, array $options = []) |
|
15
|
|
|
* @method \App\Model\Entity\User|bool save(\Cake\Datasource\EntityInterface $entity, $options = []) |
|
16
|
|
|
* @method \App\Model\Entity\User patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = []) |
|
17
|
|
|
* @method \App\Model\Entity\User[] patchEntities($entities, array $data, array $options = []) |
|
18
|
|
|
* @method \App\Model\Entity\User findOrCreate($search, callable $callback = null, $options = []) |
|
19
|
|
|
* |
|
20
|
|
|
* @mixin \Cake\ORM\Behavior\TimestampBehavior |
|
21
|
|
|
*/ |
|
|
|
|
|
|
22
|
|
|
class UsersTable extends Table |
|
23
|
|
|
{ |
|
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Initialize method |
|
27
|
|
|
* |
|
28
|
|
|
* @param array $config The configuration for the Table. |
|
|
|
|
|
|
29
|
|
|
* @return void |
|
|
|
|
|
|
30
|
|
|
*/ |
|
31
|
3 |
|
public function initialize(array $config) : void |
|
|
|
|
|
|
32
|
|
|
{ |
|
|
|
|
|
|
33
|
3 |
|
parent::initialize($config); |
|
34
|
|
|
|
|
35
|
3 |
|
$this->setTable('users'); |
|
36
|
3 |
|
$this->setDisplayField('id'); |
|
37
|
3 |
|
$this->setPrimaryKey('id'); |
|
38
|
|
|
|
|
39
|
3 |
|
$this->addBehavior('Timestamp'); |
|
40
|
3 |
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Default validation rules. |
|
44
|
|
|
* |
|
45
|
|
|
* @param \Cake\Validation\Validator $validator Validator instance. |
|
|
|
|
|
|
46
|
|
|
* @return \Cake\Validation\Validator |
|
|
|
|
|
|
47
|
|
|
*/ |
|
48
|
|
|
public function validationDefault(Validator $validator) : Validator |
|
|
|
|
|
|
49
|
|
|
{ |
|
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
$validator |
|
52
|
|
|
->email('email') |
|
|
|
|
|
|
53
|
|
|
->requirePresence('email', 'create') |
|
|
|
|
|
|
54
|
|
|
->notEmpty('email'); |
|
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
$validator |
|
57
|
|
|
->requirePresence('password', 'create') |
|
|
|
|
|
|
58
|
|
|
->notEmpty('password'); |
|
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
return $validator; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Returns a rules checker object that will be used for validating |
|
65
|
|
|
* application integrity. |
|
|
|
|
|
|
66
|
|
|
* |
|
67
|
|
|
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified. |
|
|
|
|
|
|
68
|
|
|
* @return \Cake\ORM\RulesChecker |
|
|
|
|
|
|
69
|
|
|
*/ |
|
70
|
1 |
|
public function buildRules(RulesChecker $rules) : RulesChecker |
|
|
|
|
|
|
71
|
|
|
{ |
|
|
|
|
|
|
72
|
1 |
|
$rules->add($rules->isUnique(['email'])); |
|
73
|
|
|
|
|
74
|
1 |
|
return $rules; |
|
75
|
|
|
} |
|
|
|
|
|
|
76
|
|
|
} |
|
77
|
|
|
|