/var/www/vhosts/ihelp.ro/httpdocs/src/Model/Table
Edit: /var/www/vhosts/ihelp.ro/httpdocs/src/Model/Table/UsersTable.php (6672B)
setTable('users');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
$this->addBehavior('Timestamp');
$this->belongsTo('Roles', [
'foreignKey' => 'role_id',
'joinType' => 'INNER',
]);
$this->hasMany('Causes', [
'foreignKey' => 'user_id',
]);
$this->hasMany('Messages', [
'foreignKey' => 'user_id',
]);
$this->hasMany('Orders', [
'foreignKey' => 'user_id',
]);
$this->hasMany('PaymentLogs', [
'foreignKey' => 'user_id',
]);
$this->hasMany('ProductFavorites', [
'foreignKey' => 'user_id',
]);
$this->hasMany('Products', [
'foreignKey' => 'user_id',
]);
$this->hasMany('Causes', [
'foreignKey' => 'user_id',
]);
$this->hasOne('Profiles', [
'foreignKey' => 'user_id',
]);
$this->hasMany('UserAddresses', [
'foreignKey' => 'user_id',
]);
}
/**
* Default validation rules.
*/
public function validationDefault(Validator $validator): Validator
{
$validator
->integer('id')
->allowEmptyString('id', null, 'create');
$validator
->email('email')
->requirePresence('email', 'create')
->notEmptyString('email', __('Câmpul este obligatoriu.'));
$validator
->scalar('password')
->maxLength('password', 255)
->requirePresence('password', 'create')
->notEmptyString('password', __('Câmpul este obligatoriu.'))
->add('password', 'characters', [
//'rule' => ['custom', '/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}$/'],
'rule' => ['custom', '/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d@$!%*#?&]{8,}$/'],
'message' => __('Minim opt caractere, cel puțin o literă și o cifră. Poate conține caractere speciale.'),
]);
$validator
->boolean('gdpr_active')
->requirePresence('gdpr_active', 'create')
->notEmptyString('gdpr_active', __('Câmpul este obligatoriu.'))
->equals('gdpr_active', true, __('Câmpul este obligatoriu.'));
$validator
->boolean('is_active')
->requirePresence('is_active', null, 'create')
->notEmptyString('is_active');
return $validator;
}
/**
* validationNewPassword
*/
public function validationNewPassword($validator)
{
$validator
->scalar('new_password')
->maxLength('new_password', 255)
->requirePresence('new_password', ['create'])
->notEmptyString('new_password', __('Câmpul este obligatoriu.'))
->add('new_password', 'characters', [
//'rule' => ['custom', '/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}$/'],
'rule' => ['custom', '/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d@$!%*#?&]{8,}$/'],
'message' => __('Minim opt caractere, cel puțin o literă și o cifră. Poate conține caractere speciale.'),
]);
$validator
->requirePresence('confirm_password', 'create')
->notEmptyString('confirm_password', __('Câmpul este obligatoriu.'));
$validator->sameAs('confirm_password', 'new_password', 'Parola nu este identică.');
return $validator;
}
/**
* validationResetPassword
*/
public function validationResetPassword($validator)
{
$validator
->scalar('password')
->maxLength('password', 255)
->requirePresence('password', ['create'])
->notEmptyString('password', __('Câmpul este obligatoriu.'))
->add('password', 'characters', [
'rule' => ['custom', '/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d@$!%*#?&]{8,}$/'],
'message' => __('Minim opt caractere, cel puțin o literă și o cifră. Poate conține caractere speciale.'),
]);
return $validator;
}
/**
* validationVerifyEmail
*/
public function validationVerifyEmail($validator)
{
$validator
->email('email')
->notEmptyString('email', __('Câmpul este obligatoriu.'));
$validator
->email('email_send_forgort_password')
->notEmptyString('email_send_forgort_password', __('Câmpul este obligatoriu.'));
return $validator;
}
/**
* Used to get user by cookie token
*/
public function getUserByCookieToken($credentials = array())
{
$loginTokenTable = TableRegistry::getTableLocator()->get('LoginTokens');
$userId = $loginTokenTable->getUserIdByCookieToken($credentials);
if ($userId) {
$user = $this->getUserById($userId);
if (!empty($user) && $user['is_active'] && $user['is_email_verified']) {
return $user->toArray();
}
}
return [];
}
/**
* Used to get user by user email
*/
public function getUserByEmail($email)
{
if ($email) {
$user = $this->find()->where(['Users.email' => $email])->first();
if (!empty($user)) {
return $user;
}
}
return [];
}
/**
* Used to get user by user id
*/
public function getUserById($userId)
{
if ($userId) {
$user = $this->find()->where(['Users.id' => $userId])->contain(['Profiles'])->first();
if (!empty($user)) {
return $user;
}
}
return [];
}
/**
* Returns a rules checker object that will be used for validating
*/
public function buildRules(RulesChecker $rules): RulesChecker
{
$rules->add($rules->isUnique(['email']), ['errorField' => 'email']);
$rules->add($rules->isUnique(['uuid']), ['errorField' => 'uuid']);
$rules->add($rules->existsIn(['role_id'], 'Roles'), ['errorField' => 'role_id']);
return $rules;
}
}