<?php
namespace Admin\Controller;
use Think\Controller;

class LoginController extends Controller {
	function index() {
		set_theme();
		$this->display('tpl/login');
	}
	function do_login() {
		$username          = $_POST['username'];
		$password          = $_POST['password'];
		$m                 = M('Users');
		$where['username'] = $username;
		$where['password'] = md5($password);
		$i                 = $m->where($where)->find();

		if (null != $i) {

			$_SESSION['userid']   = $i['id'];
			$_SESSION['username'] = $username;
			$_SESSION['email']    = $i['email'];
			$_SESSION['url']      = $i['url'];
			$rtnArr               = array(
				'status' => 'success',
			);
			echo json_encode($rtnArr);
		} else {
			$rtnArr = array(
				'status' => 'fail',
			);
			echo json_encode($rtnArr);
		}
	}

	function do_logout() {
		session_destroy();
		$this->redirect('Index/index');
	}
}