• 用户登陆模块的后端实现


    前述两篇文章“使用BootStrap制作用户登录UI”和“使用BootStrapValidator来完成前端输入验证 ”已经将用户登陆的界面和验证进行了实现,现在看看后端要做的事情(基于ThinkPHP5)。举例来说,比如当学生登陆成功后则进入学生界面,在这个界面中,学生可以提交作业,查看自己作业的批改情况。当用户在前述界面中输入了用户名和密码,选择了学生用户后,点登陆,会进入dologin方法(位于controllerindexaccountdologin),代码如下:

    复制代码
    public function dologin()
        {
            $kind=$_POST['kind'];
            if($kind=='tea')
            {
                $user=UserModel::get(['username'=>$_POST['username'],'password'=>md5($_POST['pwd'])]);
                if($user)
                {
                    if($user->power=='common')
                        echo '教师登陆成功';
                    else 
                        echo '管理员登陆成功';
                }
                
            }else 
            {
                $stu=StuModel::get(['stu_no'=>$_POST['username'],'password'=>md5($_POST['pwd'])]);
                if($stu)
                {
                    $_SESSION['stuno']=$stu->stu_no;
                    $this->success('登陆成功','Student/'.$stu->stu_no);
                }
                else 
                {
                    $this->error('用户名或密码错误');
                }
            }
        }
    复制代码

    这里只对学生逻辑进行了简单的实现。当学生登陆成功后会进入 Student控制器的index方法中,当然需要在rote.php中配置如下路由:

    'index/student/:stuno'=>'index/student/index'

    在Student控制器中可以如下处理:

    复制代码
    <?php
    namespace appindexcontroller;
    use thinkController;
    use appindexmodelStudent as StuModel;
    class Student extends Controller{
        public function index($stuno)
        {
            $stu=StuModel::get(['stu_no'=>$stuno]);
            echo "欢迎登陆学生界面 ".$stu->stu_name;
        }
    }
    复制代码

    这里只是简单的阐述了处理和跳转逻辑,当然实际开发中肯定有更丰富的功能和逻辑,以点盖面吧,希望对你有所帮助。

    下面是登陆成功后的页面:

    本文首发顶求网,由作者原创,如需转载请注明出处。

  • 相关阅读:
    Fire and Motion[转载]
    HLSL2GLSL v0.9 Released
    CEGUI Release of 0.5.0 stable by CrazyEddie 6th November 2006
    MapInfo 连接Oracle
    MapInfo连接SQLServer
    视图的创建及使用(sql server 2005)
    MapInfo 建立永久表
    MapInfo Update Feature
    MapInfo导入.TAB和.mws的方法
    触发器的创建及使用(sqlserver 2000)
  • 原文地址:https://www.cnblogs.com/nerd/p/5943982.html
Copyright © 2020-2023  润新知