登录控制器代码

Original 2019-06-14 19:48:50 219
abstract:<?phpnamespace app\admin\controller;//use think\facade\View;  //view创建静态代理use app\admin\model\UserModel;use think\Controller;use think\facade\Request;use think\facade\Session;class Login exten

<?php
namespace app\admin\controller;
//use think\facade\View;  //view创建静态代理
use app\admin\model\UserModel;
use think\Controller;
use think\facade\Request;
use think\facade\Session;

class Login extends Controller
{
    //模板渲染
    public function login()
    {
        return $this->fetch();
    }
    public function DoLogin()
    {
        // 获取前台提交过来的数据
        $data = Request::param();
        $username = $data['username'];
        // 使用用户名来查询数据库是否有对应的数据
        $user = UserModel::where('username', $username)->find();
        if($user != true){
         $info = ['res'=>0,'msg'=>'用户名不存在!'];
        }elseif($data['password'] != $user['password']){
         $info = ['res'=>0,'msg'=>'密码有误!'];
        }else{
         $info = ['res'=>1,'msg'=>'登录成功!'];
            Session::set('username', $user['username']);
        }
        return $info;
    }

    public function LoginOut()
    {
        //删除Session中的用户名
        Session::delete('username');
        //退出跳转
        $this->redirect('login');
    }
}


Correcting teacher:查无此人Correction time:2019-06-15 09:13:24
Teacher's summary:完成的不错,后台cms管理系统,最重要的就是权限。继续加油。

Release Notes

Popular Entries