<?php

namespace WpBookingProFrontend\app\controllers;

use WpBookingPro\Factory;
use WpBookingPro\Filesystem\Support\StringController;
use WpBookingPro\Mvc\Controller\ControllerFrontend;
use WpBookingPro\Mvc\Model\Model;
use WpBookingPro\Utilities\Utility;
use WpBookingProFrontend\app\helpers\ConfigHelper;
use WpBookingProFrontend\app\helpers\EmailHelper;

defined('_WPBOOKINGPRO_EXEC') or die;

/**
 * Class BlockController
 */
class SignupController extends ControllerFrontend
{
    public function create_user_account() {
        $input = Factory::getInput();
        $data = $input->getData();
        $link_redirect = isset($data['link_redirect'])?$data['link_redirect']:'';
        $modelSignup = Model::getInstance('signup');
        $user_id = $modelSignup->createUserAccount($data);
        if($user_id) {
            Utility::redirect($link_redirect.'/?status_signup=success');
        }
    }
    public function check_exist_email() {
        $input = Factory::getInput();
        $data = $input->getData();
        $dataObj = isset($data['dataObj'])?$data['dataObj']:array();
        $email = isset($dataObj['email'])?$dataObj['email']:'';
        global $wpdb;
        $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->users WHERE user_email  LIKE  %s", $email));

        if($count == 1){
            return true;
        }
        else{
            return false;
        }
    }
    public function check_exist_username() {
        $input = Factory::getInput();
        $data = $input->getData();
        $dataObj = isset($data['dataObj'])?$data['dataObj']:array();
        $user_name = isset($dataObj['user_name'])?$dataObj['user_name']:'';

        global $wpdb;
        $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->users WHERE user_login  LIKE %s", $user_name));

        if($count == 1){
            return true;
        }
        else{
            return false;
        }
    }

}
