<?php 
require '../conn/conn.php';
require '../conn/function.php';
if(checkauth()<2){
    die("<script>alert(\"会员中心仅限授权版用户使用！\");window.location.href=\"../\"</script>");
}

$from = $_GET["from"];
$action = $_GET["action"];
$genkey=gen_key(20);

$D_domain=splitx($_SERVER["HTTP_HOST"].$_SERVER["PHP_SELF"],"/member",0);

if($from==""){
    $from="index.php";
}

if ($action == "unlogin") {
    $_SESSION["M_login"] = "";
    $_SESSION["M_id"] = "";
    $_SESSION["M_pwd"] = "";
    $_SESSION["M_pwdcode"] = "";
    die("<script>window.location.href=\"login.php\"</script>");
}

if ($action == "login") {
    $M_email = t($_POST["M_email"]);
    $M_pwd = $_POST["M_pwd"];
    $M_code = $_POST["M_code"];
    
    if((xcode($_POST["M_code"],'DECODE',$_SESSION["CmsCode"],0)!=$_SESSION["CmsCode"] || $_POST["M_code"]=="" || $_SESSION["CmsCode"]=="") && $C_slide==1){
        box("请重新拖动滑块进行验证！", "back", "error");
    } else {
        $_SESSION["CmsCode"]="refresh";
        $sql = member("login",$_POST);

        $result = mysqli_query($conn, $sql);
        $row = mysqli_fetch_assoc($result);
        if (mysqli_num_rows($result) > 0) {
            $_SESSION["M_login"] = $row["M_login"];
            $_SESSION["M_id"] = $row["M_id"];
            $_SESSION["M_pwd"] = md5($M_pwd);
            Header("Location:".$from);
        } else {
            box("帐号或密码错误!", "back", "error");
        }
    }
}

if($_SESSION["M_login"]!=="" && $_SESSION["M_pwd"]!="" && $_SESSION["M_id"]!=""){
    die("<script>window.location.href=\"$from\"</script>");
}
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>会员登录 - <?php echo $C_title?></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">  
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link href="../media/<?php echo $C_ico?>" rel="shortcut icon" type="image/x-icon" />
    <link rel='stylesheet' type='text/css' href="../css/css/font-awesome.min.css">
    <style type="text/css">
        body{background: #62a8ea}
        .box{max-width: 400px;width: 90%;margin:0 auto;background: #fff;border-radius: 10px;text-align: center;margin-top:10%;padding: 50px;box-shadow: 0 1px 1px rgb(0 0 0 / 5%);}
        .buttons{text-align: center;margin-top: 20px}
        .form-control{border:none;border-bottom: solid 1px #DDD;border-radius: 0px;-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,0);
    box-shadow: inset 0 1px 1px rgba(0,0,0,0);
    -webkit-transition: border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;}
        p{margin-top: 30px}
    </style>
</head>
<body>
<div class="box">
    <a href="../"><img  src="../media/<?php echo $C_logo?>" style="max-width: 100%"></a>
    <h2 class="h3">会员登录</h2>
    <div style="text-align: left;">

        <form method="post" class="met-form-validation" action="?action=login&from=<?php echo urlencode($from)?>">

        <p><input type="text" name="M_email" class="form-control" placeholder="账号"></p>

        <p><input type="password" name="M_pwd" class="form-control" placeholder="密码"></p>
        <p><iframe id="slide" src="../conn/code_1.php?name=M_code" scrolling="no" frameborder="0" width="100%" height="40"></iframe></p>
        <p><button type="submit" class="btn btn-block btn-primary">登录</button></p>
        </form>


        <p style="font-size: 12px;color: #AAA;text-align: center;">还没有账号? 去 <a href="reg.php?from=<?php echo urlencode($from)?>">注册</a> <a href="forget.php">忘记密码</a> <a href="../">返回首页</a></p>
    </div>
</div>


</body>
</html>