<?php
!defined('WAP') && exit('FORBIDDEN');
define('CURSCRIPT','login');

$returnurl = isset($_REQUEST['returnurl']) ? mhtmlspecialchars($_REQUEST['returnurl']) : '';

if($action == 'logout'){

	$member_log->out('noredirect');
	redirectmsg('你已成功退出',$returnurl ? $returnurl : 'index.php?mod=index');
	
} elseif($action == 'login') {
	
	$userid = isset($_POST['userid']) ? mhtmlspecialchars(trim($_POST['userid'])) : '';
	$userpwd = isset($_POST['userpwd']) ? mhtmlspecialchars(md5(trim($_POST['userpwd']))) : '';
	$checkcode = isset($_POST['checkcode']) ? mhtmlspecialchars(trim($_POST['checkcode'])) : '';

	if($mobile_settings['authcode'] == 1 && !mymps_chk_randcode($checkcode)){
		redirectmsg('验证码输入错误，请返回重新输入','index.php?mod=login');
	}
	if($userid == '' || $userpwd == '') redirectmsg('用户帐号或密码不能为空','index.php?mod=login');

	if($s_uid  = $db -> getOne("SELECT userid FROM `{$db_mymps}member` WHERE userid='$userid' AND userpwd='$userpwd'")){
		$member_log -> in($s_uid,$userpwd,'off','noredirect');
		redirectmsg($s_uid.' 欢迎回来!',$returnurl ? $returnurl : 'index.php?mod=index');
	}else{
		redirectmsg('登录失败，您输入了错误的帐号或密码!',$returnurl ? $returnurl : 'index.php?mod=login');
	}

} else{

	if($iflogin == 1){
		redirectmsg('您已登录',$returnurl ? $returnurl : 'index.php');
	}else{
		include mymps_tpl('member_login');
	}
}

?>