<?php
/**
 * login.php 登录
 * ----------------------------------------------------------------
 * OldCMS,site:http://www.oldcms.com
 */
if(!defined('IN_OLDCMS')) die('Access Denied');
$act=Val('act','GET');
switch($act){
	case 'submit':
		$username=Val('user','POST');
		if(empty($username)) ShowError('用户/邮箱不能为空',$url['login']);
		$userpwd=Val('pwd','POST');
		if(empty($userpwd)) ShowError('密码不能为空',$url['login']);
		/*
		// 如果登录时使用了验证码，取消此处注释
		$captcha=Val('captcha','POST');
		if(empty($captcha)) ShowError('请输入验证码',$url['login']);
		//判断验证码
		include(ROOT_PATH.'/source/class/Captcha.class.php');
		if(!Captcha::Check($captcha)) ShowError('验证码输入错误',$url['login']);
		*/
		$auto=Val('auto','POST',1);
		if($user->userId<=0){
			if($user->Login($username,$userpwd,$auto)){
                $adminLevels=$user->getAdminLevel($username);
                if(!empty($adminLevels)){
                    ShowSuccess('管理员登录成功',URL_ROOT.'/admin/main');
                }else {
                    ShowSuccess('用户登录成功', URL_ROOT . '/user/main');
                }
            }else{
				ShowError('登录失败,请检查用户/邮箱或密码',$url['login']);
			}
		}
		break;
	case 'logout':
		if($user->Logout()){
			ShowSuccess('成功退出');
		}
		break;
	default:
		if($user->userId>0){
			ShowError('已经登录');
		}
		$smarty=InitSmarty();
        $smarty->assign('do',$do);
        $smarty->assign('show',$show);
        $smarty->assign('url',$url);
		$smarty->display('admin/login.tpl');
		break;
}
?>