<?php

require_once(dirname(dirname(__FILE__)) . '/app.php');

if($login_user) redirect(get_loginpage(WEB_ROOT . '/index.php'));

if ( $_POST ) {
    if(!Utility::CaptchaCheck($_POST['check-code'])){
		Session::Set('error', '验证码输入错误！');
		redirect(WEB_ROOT . '/account/login.php');
    }
	$login_user = OUser::GetLogin($_POST['email'], $_POST['password']);
	if ( !$login_user ) {
		Session::Set('error', '登录失败');
		redirect(WEB_ROOT . '/account/login.php');
    } elseif($login_user['enable']=='N'){
		Session::Set('error', '此账户已经暂停使用！请咨询管理员！');
		redirect(WEB_ROOT . '/account/login.php');
	} else {
        Table::UpdateCache('user', $login_user['id'], array('login_time'=>time()));
        if($login_user['manager']=='Y')Session::Set('admin_id',$login_user['id']);
		Session::Set('user_id', $login_user['id']);
		OLogin::Remember($login_user);
		redirect(get_loginpage(WEB_ROOT . '/index.php'));
	}
}


$pagetitle = '登录';
include template('account_login');

?>
