<?php namespace App\Models;

use CodeIgniter\Model;

class User_model extends Model
{
    protected $table      = 'users';
    protected $primaryKey = 'id';
	
	protected $allowedFields = ['role','name', 'mobile', 'profile' , 'email', 'password', 'address' , 'city' , 'state' , 'country' , 'pincode' , 'new_mail' , 'is_active' ,'created_at','updated_at','country_code'];
	
	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,is_active");
		$builder -> where('email',$email);
		$result = $builder->get();
		if(count($result->getResultArray()) ==1)
		{
			return $result->getRowArray();
		}else{
			return false;
		}
	}

  
}