返回 登录模块了解和...... 登陆

登录模块了解和编写代码

Levin 2018-12-02 20:00:58 232

完成了登录模块,对构造函数有一点了解。

login控制器

<?php
namespace app\admin\controller;
use think\Controller;
use app\admin\model\Admins;
use think\facade\Request;
use think\facade\Session;
class Login extends Controller
{
    public function login()
    {
        // if(request()->isPost())
        // {

        // }
        return $this->fetch();
    }

    public function dologin()
    {
        $res=input('post.');
        // dump($res);
        $res1 = $res['name'];
        $admins = admins::get(function($suib)use($res1){
            $suib->where('name',$res1);
        });
        // dump($admins);die;
        if ($admins) {
            if ($res['password']==$admins['password'])
            {
                // dump('11111');die;
                $info=['res'=>1,'msg'=>'登录成功'];
                Session::set('name', $res['name']);
            }else{

               $info=['res'=>2,'msg'=>'密码不正确'];
            }
        }else{
               $info=['res'=>3,'msg'=>'账户不存在'];

        }
        // dump($info);die;
        return $info;

    }

    public function Logout()
    {
        Session::delete('name');
        $this->redirect('login');
    }
}

common控制器

<?php

/**

 *

 */


namespace app\admin\controller;


use think\Controller;

use think\facade\Session;


class Common extends Controller

{

    public function __construct()

    {

        parent::__construct();

        if (!Session::has('name')) {

            $this->error('您还未登录!请返回登录!','Login/Login');

        }

    }

}



最新手记推荐

• 用composer安装thinkphp框架的步骤 • 省市区接口说明 • 用thinkphp,后台新增栏目 • 管理员添加编辑删除 • 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消 回复 发送
  • PHP中文网