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

/**
 * User_myinfo
 */


class User_myinfo extends CI_Controller
{

    private $CI;

    function __construct()
    {
        $this->CI = & get_instance();

    }

	function main()
	{

		if ( ! $this->CI->input->post_get('token')) {
			$this->CI->apilib->make_error("토큰 값이 넘어오지 않았습니다");
        }
		$token = $this->CI->input->post_get('token');


        $app_id = (int) trim($this->CI->input->post_get('app_id'));
        if (empty($app_id)) {
			$this->CI->apilib->make_error("어플 아이디가 넘어오지 않았습니다");
        }

		$sessionuser = $this->CI->User_model->get_by_token($app_id, $token);
		if ( ! element('user_id', $sessionuser)) {
			$this->CI->apilib->make_error("로그인 한 회원만 회원정보를 열람할 수 있습니다");
		}

		$user_id = element('user_id', $sessionuser);
		$this->CI->load->model(array('User_model'));

		$user = $this->CI->User_model->get_one(element('user_id', $sessionuser));
		
		$arr = array(
			'result' => 'ok',
			'token' => $token,
			'user_id' => element('user_id', $user),
			'user_email' => element('user_email', $user),
			'user_username' => element('user_username', $user),
			'user_photo' => user_photo_url(element('user_photo', $user)),
		);

		return $arr;
	}
}
