75 lines
2.1 KiB
PHP
75 lines
2.1 KiB
PHP
<?php
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class User extends Model
|
|
{
|
|
protected $DBGroup = 'default';
|
|
protected $table = 'users3';
|
|
protected $primaryKey = 'id';
|
|
protected $useAutoIncrement = true;
|
|
protected $insertID = 0;
|
|
protected $returnType = 'array';
|
|
protected $useSoftDelete = false;
|
|
protected $protectFields = true;
|
|
protected $allowedFields = [
|
|
"username",
|
|
"firstname",
|
|
"lastname",
|
|
"email",
|
|
"profile",
|
|
"mobile_no",
|
|
"password",
|
|
"is_active",
|
|
"updated_by",
|
|
"created_by",
|
|
];
|
|
|
|
// Dates
|
|
protected $useTimestamps = false;
|
|
protected $dateFormat = 'datetime';
|
|
protected $createdField = 'created_at';
|
|
protected $updatedField = 'updated_at';
|
|
protected $deletedField = 'deleted_at';
|
|
|
|
// Validation
|
|
protected $validationRules = [];
|
|
protected $validationMessages = [];
|
|
protected $skipValidation = false;
|
|
protected $cleanValidationRules = true;
|
|
|
|
// Callbacks
|
|
protected $allowCallbacks = true;
|
|
protected $beforeInsert = ["beforeInsert"];
|
|
protected $afterInsert = [];
|
|
protected $beforeUpdate = [];
|
|
protected $afterUpdate = [];
|
|
protected $beforeFind = ["removePassword"];
|
|
protected $afterFind = ["removePassword"];
|
|
protected $beforeDelete = [];
|
|
protected $afterDelete = [];
|
|
|
|
protected function beforeInsert(array $data)
|
|
{
|
|
$data = $this->passwordHash($data);
|
|
return $data;
|
|
}
|
|
|
|
protected function removePassword(array $data)
|
|
{
|
|
// $data =
|
|
unset($data['data']['password']);
|
|
return $data;
|
|
}
|
|
|
|
protected function passwordHash(array $data)
|
|
{
|
|
if (isset($data['data']['password'])) {
|
|
$data['data']['password'] = password_hash($data['data']['password'], PASSWORD_DEFAULT);
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
}
|
|
?>
|