golf_backend/app/Models/User_model.php
2023-05-06 10:58:49 +05:30

47 lines
1.1 KiB
PHP

<?php namespace App\Models;
use CodeIgniter\Model;
class User_model extends Model
{
protected $table = 'users';
protected $primaryKey = 'id';
protected $allowedFields = ['role','name', 'mobile','email','user_name', 'password','created_at','updated_at'];
protected $beforeInsert = ['beforeInsert'];
protected $beforeUpdate = ['beforeUpdate'];
protected function beforeInsert(array $data){
$data= $this->passwordHash($data);
return $data;
}
protected function beforeUpdate(array $data){
$data= $this->passwordHash($data);
return $data;
}
protected function passwordHash(array $data)
{
if(isset($data['data']['password']))
$data['data']['password'] = password_hash($data['data']['password'],PASSWORD_DEFAULT);
return $data;
}
public function verifyEmail($email)
{
$builder = $this->db->table('users');
$builder -> select("id,mobile,email,password");
$builder -> where('email',$email);
$result = $builder->get();
if(count($result->getResultArray()) ==1)
{
return $result->getRowArray();
}else{
return false;
}
}
}