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

class CheckemailsController extends AppController {
    public function checkemailregister(){
		// 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['chk'] = 'false';
				$data = json_encode($emails);
				echo $data;
			}else{
				$emails['chk'] = 'true';
				$data = json_encode($emails);
				echo $data;
			}
		}
	}

	public function checkemailedit(){
		// 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)){
				if($this->request->data['userId'] == $emails['user_id']){
					$emails['chk'] = 'true';
					$data = json_encode($emails);
					echo $data;
				} else {
					$emails['chk'] = 'false';
					$data = json_encode($emails);
					echo $data;
				}
			}else{
				$emails['chk'] = 'true';
				$data = json_encode($emails);
				echo $data;
			}
		}
    }
}
