<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Admin extends Api_Controller
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * addUser
     */
    public function addUser()
    {
        $email = $this->input->get('email');
        $password = $this->input->get('password');

        if (!isset( $email, $password )) {
            $this->FailedResponse('Invalid Param');
        }

        if ($this->getUserModel()->get_by_email($email)) {
            $this->FailedResponse('This email has been registered already');
        }


        $data = array(
            EMAIL => $email,
            PASSWORD => $password,
            DATE_CREATED => $this->currentTime(),
        );

        $user_id = $this->getUserModel()->save($data);
        if ($user_id) {
            $user_data = $this->getUserModel()->get($user_id);
            $this->SuccessResponse($user_data);
        } else {
            $this->FailedResponse('Something went wrong.');
        }
    }

    public function getIP(){
        $ip = $this->getIPModel()->getAddress();
        if (!$ip){
            $this->FailedResponse('There is no ip registered yet');
        }
        $this->TextResponse($ip);
    }
}