博客系统开发_用户登录(二)

用户登录过程实质上是数据库查询的功能

一、页面设计

进入Admin模块下View中新建Login文件夹,新建index.php文件,在index.php中进行用户登录页面设计

代码如下

DOCTYPE HTML>
<html>
    <head>
        <title>管理员登录title>
        <script src="/Public/js/jquery-3.2.1.js">script>
        <link rel="stylesheet" href="/Public/bootstrap-3.3.7/css/bootstrap.css" />     
        <script src="/Public/bootstrap-3.3.7/js/bootstrap.js">script>        
    head>
    <body>
        <div class="container">
            <div class="row" style="margin-top:200px;">
                <div class="col-md-3">
                div>
                <div class="col-md-6">
                    <div class="panel panel-primary">
                        <div class="panel-heading">
                            <h3 class="panel-title">管理员登陆h3>
                        div>
                        <div class="panel-body">
                            <form class="form-horizontal" action="" method="post">
                                <div class="form-group">
                                    <label  class="col-sm-2 control-label">用户label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name= "auser" id="auser" placeholder="请输入用户名">
                                div>
                                div>
                                <div class="form-group">
                                    <label  class="col-sm-2 control-label">密码label>
                                    <div class="col-sm-8">
                                        <input type="password" class="form-control" name="apass" id="apass" placeholder="请输入密码">
                                    div>
                                div>                        
                                <div class="form-group">
                                    <div class="col-sm-offset-2 col-sm-8">
                                        <button type="submit" class="btn btn-primary">点击登陆button>
                                    div>
                                div>
                            form>
                        div>
                        <div class="panel-footer text-right">版权所有 侵权必究div>
                    div>
                div>
                <div class="col-md-3">
                div>
            div>
            
        div>
    body>
html>
View Code

效果如下所示

博客系统开发_用户登录(二)_第1张图片

表单提交:

 二、业务编写

进入Admin 模块下,Controller下新建用户登录控制器LoginController.class.php

php
namespace Admin\Controller;
use Think\Controller;
class LoginController extends Controller {

    /**
     *后台登陆业务逻辑
     *
     */
    public function index(){ 

        $do = I("get.do");     
        if($do=="chk"){
            //获取用户输入
            $auser = I("post.auser"); 
            $apass = I("post.apass");        

            $where =array(
                'auser' => $auser,
                'apass' => $apass,            
            );
            //实例化数据模型
            $admin = D('admin'); 
            $user=$admin->where($where)->find();
        
            if(!$user){
                return $this->error("账号或密码错误!","/Admin/Login/index",5);
            }
            else{
                session('aid',$user['aid']);
                return $this->success("登陆成功","/Admin/Index/index");
            }
        }
        $this->display();        
    } 
        
}
View Code

 

注意:

 

转载于:https://www.cnblogs.com/3309-whp/p/8018718.html

你可能感兴趣的:(博客系统开发_用户登录(二))