<?php
namespace App\Controllers;
// use App\Models\VinDescriptionModel;
use Config\Services;
//use Firebase\JWT\JWT;

class Registeruser extends BaseController{
    private $dbx;

    public function index(){
    	$error = 1 ;
        $this->dbx   = \Config\Database::connect();
        $email = $this->request->getVar('email');
		$data = [
		    'uid'               => md5(uniqid(rand(), true)),
			'firstname' 		=> $this->request->getVar('firstname'),
			'phone' 			=> $this->request->getVar('phone'),
			'email' 			=> $email,
			'password' 			=> $this->request->getVar('password'),
			'level' 		    => 'user',
			'dateregistered' 	=> date('Y-m-d H:i:s'),
			'machineip'			=> $this->request->getIPAddress()
		];

		$users = $this->dbx->table('fans');
		$c = $users->getWhere(['email'=>$email], 1, 0);
		if($c->getNumRows()>0){
			$error = 2;
		}else{
			$users->insert($data);
			$E = $this->dbx->error(); $error = $E['code'];
		}
		
		$W = [];
		$W['status'] = $error;
		return json_encode($W, JSON_HEX_APOS | JSON_HEX_QUOT);
    }
}