TP51使用Jquery-登陆界面及validate登陆用户验证

htaccess设置index.php?s=$1
使用env进行设置
带角色权限,角色组,会员
login.html执行登录
\admin\controller\Login.php文件

think\Request;
think\facade\Session;
think\facade\Config;
admin\model\AuthRule as AuthModel;
admin\model\Member as MemberModel;
common\controller\Base as CommonBase;

class Login extends CommonBase{
function index(){$this->redirect(“login”); }

function login(){
    $member = login_member();
    if($member){
        if($this->request->isGet()){
            $this->redirect("index/index");
        }else{
            $this->success("登录成功", "index/index", '', 0);
        }
    }

    if($this->request->isPost()){
        $param = $this->request->param();
        $Model = new MemberModel();
        $login_res = $Model->doLogin($param["name"], $param["password"]);
        if(!$login_res['status']){
            $this->error($login_res['msg']);
        }else{
            if(isset($param["is_remember"])){
                $expire = 7*24*3600;
                Session::setConfig(["expire" => $expire]);
            }
            Session::set("member", $login_res['data']);

            $back_url = Session::pull('back_url');
            if(empty($back_url)){
                $back_url = url("index/index");
            }
            $this->success("登录成功", $back_url);
        }
    }else{return $this->fetch("login"); }  }
function logout(){
    $AuthModel = new AuthModel;
    $AuthModel->clearMemberSession();
    Session::delete("member");
    $this->redirect("login");  }                }

\admin\view\login\login.html文件
{:url(‘login’)} index.php/admin/login/login.html

<div class="main-container">
  <div class="main-content login">
    <div class="row">
      <div class="col-sm-10 col-sm-offset-1">
        <div class="login-container">
          <div class="center">
            <h1>
              <i class="ace-icon fa fa-leaf green"></i>
              <span class="red">{$seo.site_name}</span>
              <span class="white" id="id-text2">管理后台</span>
            </h1>
            <h4 class="blue" id="id-company-text">&copy; 管理后台</h4>
          </div>

          <div class="space-6"></div>

          <div class="position-relative">
            <div id="login-box" class="login-box visible widget-box no-border">
              <div class="widget-body">
                <div class="widget-main">
                  <h4 class="header blue lighter bigger">
                    <i class="ace-icon fa fa-coffee green"></i>
                    登录信息
                  </h4>

                  <div class="space-6"></div>

                 
				 <form action="{:url('login')}" method="post">
				  

                    <fieldset>
                      <label class="block clearfix">
                        <span class="block input-icon input-icon-right">
                          <input type="text" class="form-control" name="name" placeholder="登录名" />
                          <i class="ace-icon fa fa-user"></i>
                        </span>
                      </label>

                      <label class="block clearfix">
                        <span class="block input-icon input-icon-right">
                          <input type="password" class="form-control" name="password" placeholder="密码" />
                          <i class="ace-icon fa fa-lock"></i>
                        </span>
                      </label>

                      <div class="space"></div>

                      <div class="clearfix">
                        <label class="inline">
                          <input type="checkbox" class="ace" name="is_remember" value="1" />
                          <span class="lbl"> 记住密码</span>
                        </label>

                        <button type="submit" class="width-35 pull-right btn btn-sm btn-primary">
                          <i class="ace-icon fa fa-key"></i>
                          <span class="bigger-110">登录</span>
                        </button>
                      </div>

                      <div class="space-4"></div>
                    </fieldset>
                  </form>
                </div><!-- /.widget-main -->
              </div><!-- /.widget-body -->
            </div><!-- /.login-box -->
          </div><!-- /.position-relative -->
        </div>
      </div><!-- /.col -->
    </div><!-- /.row -->
  </div><!-- /.main-content -->
</div><!-- /.main-container -->



<script src="{$site_root}/static/ace1.4/assets/js/jquery-2.1.4.min.js"></script>
<script src="{$site_root}/static/plugins/jquery-validate/jquery.validate.min.js"></script>
<script type="text/javascript">
  $(document).ready(function(){
    $("form").validate({
      rules:{
        "name":{
          required: true,
          maxlength: 30
        },"password":{
          required: true,
          minlength: 6,
          maxlength: 20
        }
      },
      messages:{
        "name":{
          required: "登录名不能为空",
          maxlength: "登录名不正确"
        },"password":{
          required: "登录密码不能为空",
          minlength: "登录密码不正确",
          maxlength: "登录密码不正确"
        }
      },
      errorClass: "help-inline input-error",
      errorElement: "span",
      highlight:function(element, errorClass, validClass) {
        $(element).parents('.block').addClass('has-error');
      },
      unhighlight: function(element, errorClass, validClass) {
        $(element).parents('.block').removeClass('has-error');
      },
      submitHandler: function(form){
        var $form = $(form);
        $form.ajax({
          url: $form.attr("action"),
          type: $form.attr("method"),
          dataType: "JSON",
          data: $form.serialize(),
          success: function(data){
            if(data.code){
              location.href = data["url"];
            }else{
              alert(data["msg"]);
            }
          }, error: function () {
            alert("数据执行错误!");
          }
        });
      }
    });
  });
</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值