<?php
namespace App\Controller;
use App\Controller\AppController;

class CheckemailsController extends AppController {
	public function initialize() {
        parent::initialize();
        $this->Auth->allow('checkemail');
    }
    public function checkemail(){
		// die('jjjjj');
		$this->autoRender = false;
		if ($this->request->is('post')) {
            $this->loadModel('UserPersonals');
			$emails = $this->UserPersonals->find('all',[
                'conditions' => [
                    'email' => $this->request->data['email']
                ]
			])->first();
			if(!empty($emails)&&$emails['email']!=''&&$emails['email']!='-'){
				if(!empty($this->request->data['userId'])){
					if($this->request->data['userId'] == $emails['user_id']){
						$emails['chk'] = 'true';
						$data = json_encode($emails);
						echo $data;
					}
					$emails['chk'] = 'false';
					$data = json_encode($emails);
					echo $data;
				}
				$emails['chk'] = 'false';
				$data = json_encode($emails);
				echo $data;
			}else{
				$emails['chk'] = 'true';
				$data = json_encode($emails);
				echo $data;
			}
		}
	}
}