<?php

/* ========================================================================
 * $Id: login.php 3480 2020-07-02 23:29:18Z onez $
 * 
 * Email: www@onez.cn
 * QQ: 6200103
 * HomePage: http://www.onez.cn
 * ========================================================================
 * Copyright 2016-2017 佳蓝科技.
 * 
 * ======================================================================== */

!defined('IN_ONEZ') && exit('Access Denied');
$action=onez()->gp('action');
if($action=='login'){
  $username=onez()->gp('username');
  $password=onez()->gp('password');
  $or=array();
  $or[]="key2='$username'";
  $T=$G['this']->userdb()->open('member')->one(implode(' or ',$or));
  if(!$T){
    $T2=$G['this']->userdb()->open('member')->one("1");
    if(!$T2){
      $item=array();
      $item['key1']='admin';
      $item['key2']='admin';
      $item['key3']=md5('admin');
      $item['key4']='超级管理员';
      $item['key5']='首个用户自动生成';
      $item['index11']=$G['this']->site['userid'];
      $item['index12']=$G['this']->siteId;
      $G['this']->userdb()->open('member')->insert($item);
      $T=$G['this']->userdb()->open('member')->one(implode(' or ',$or));
    }
  }
  !$T && onez()->error('账号不存在');
  #$password_md5=hash_hmac('md5',$password,$T['rndkey']);
  $password_md5=md5($password);
  $T['key3']!=$password_md5 && onez()->error('密码不正确');
  onez('cache')->cookie($G['this']->cname,"$T[id]\t$T[username]\t".time(),0);
  onez()->ok('登录成功','reload');
}
$plugin=onez('www.2020');
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>管理中心</title>
<link rel="stylesheet" type="text/css" href="<?php echo $plugin->url?>/www/login/css/onez.css" media="all">
<link rel="stylesheet" type="text/css" href="<?php echo $plugin->url?>/www/login/css/login.css" media="all">
<link href="<?php echo $plugin->url?>/www/login/css/animate.min.css" rel="stylesheet">
<link href="<?php echo $plugin->url?>/www/login/css/font-awesome.min.css" rel="stylesheet">	 
<style> body { background-image: url(<?php echo $plugin->url?>/www/login/images/bg.jpg);}</style>
<?php onez('layui')->head();?>
</head>
<body>
<div id="main-box"></div>
<div id="main-content"> 
<div class="login-body  animated fadeInLeft">
    <div class="login-main pr">
        <form action="javascript:;" method="post" class="login-form">
        <h3> 管理中心 </h3>
        <h5 style="padding-bottom: 10px"> System Management Center </h5>
        <div id="MobileBox" class="item-box"  >
            <div class="input-group user-name"> <span class="input-group-addon"><i class="icon-user"></i></span>
            <input type="text" id="username" name="username" class="form-control" placeholder="用户名">
         </div>
         <div class="input-group password"> <span class="input-group-addon"><i class="icon-lock"></i></span>
            <input type="password" id="password" name="password" class="form-control" placeholder="密码">
         </div>
          <div class="login_btn_panel">
            <button class=" btn btn-primary btn-block btn-lg" data-ajax="post" type="submit" data-callback="success">登录</button>
            <div class="check-tips"></div>
          </div>
          <input type="hidden" name="action" value="login" />
          <input type="hidden" name="noVue" value="1" />
      </form>
     </div>
  </div>
</div>
<script type="text/javascript">
layui.$('.login-form').bind('submit',function(){
  if(layui.$('#username').val().length<1){
    layer.alert('请填写您的登录账号');
    return;
  }
  if(layui.$('#password').val().length<1){
    layer.alert('请填写您的登录密码');
    return;
  }
  layui.$.post(window.location.href,layui.$(this).serialize()+'&ajax=1',function(data){
    if(data.error){
      layer.alert(data.error);
    }else{
      location.reload();
    }
  },'json');
  return false;
});
</script>
</body>
</html>
