<?php
session_start();
if( !defined('IN') ) die('bad request!');
include_once( AROOT . 'controller' . DS . 'app.class.php');
header("Content-Type: text/html; charset=utf-8");

class loginController extends appController
{
	public function __construct(){
		parent::__construct();
	}

	//发送错误结果集
	public function send_error($number,$msg)
	{
		$obj = array();
		$obj['code'] = intval($number);
		$obj['result'] = $msg;

		if( g('API_EMBED_MODE') == 1 ){
			return json_encode($obj);
		}else{
			header("Content-Type: application/json");
			die(json_encode($obj));
		}
	}

	//发送结果集
	public function send_result($data)
	{
		$obj = array();
		$obj['code'] = 0;
		$obj['result'] = 'success';
		$obj['data'] = $data;

		if( g('API_EMBED_MODE') == 1 ){
			return json_encode($obj);
		}else{
			header("Content-Type: application/json");
			die(json_encode($obj));
		}
	}

	/*
	*  验证用户登录
	*  
	*/ 
	public function postCheckLogin()
	{
		$account      = $_POST['account'];
		$password     = $_POST['password'];
		$current_time = date("Y-m-d H:i:s",time()); 

		$sql = prepare("select id,project_id,account,password,token,name,mobile,role_id from user where account = ?s and password = ?s limit 1",array($account,md5($password)));
		$data = get_line($sql);

		return self::send_result($data);	
	}


	/*
	* token的生成
	* MD5
	*/
	public function createdToken($account,$password)
	{
		$current_time = date('Y-m-d H:i:s',time());
		$token = md5($account.$password.$current_time);
		return $token;
	}
	
	public function test()
	{
		$sql = "select * from user";
		$data= get_data($sql);

		var_dump($data);
	}
}	
?>
