thinkphp框架下的登录、注册、找密码

thinkphp框架下使用ajax表单提交的登录、注册、找密码。注册后的用户需后台审核。user表的字段为id、
num、password、name、email、addtime、status

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 <?php namespace Home\Controller; use Think\Controller; class LoginController extends Controller {     //处理登录     public function signin(){          if(IS_GET){              $this->display();         }         if(IS_POST){             /* 调用登录接口登录 */             $User = M('user') ;               //I方法接收页面传递来的值             $num = I('num') ;             $password = I('password') ;             //查找user表中num等于$num的值             $datanum = $User->where(array('num'=>$num))->find();             //判断$datanum的值             if ($datanum){                 if (md5($password) === $datanum['password']) {                     if ($datanum['status'] == 0) {                         $this->error('用户处于未审核状态,请联系管理员');                     }elseif($datanum['status'] == 2){                         $this->error('用户处于禁用状态,请联系管理员');                     }else{                         $this->autoLogin($datanum) ; //调用私有方法自动登录.                          $uid = $datanum['id'];                         if($_SESSION['user_auth']['uid'] && $_SESSION['user_auth']['role'] == 'user'){                             $this->success('登录成功!', U('Index/index'));                         }else{                             $this->error('存储错误.');                         }                     }                 }else{                     $this->error('密码填写不正确,请重新填写');                     exit();                 }             }else{                 $this->error('用户不存在,请注册',U('signup'));             }         }     }       public function autoLogin($user){           /* 记录登录SESSION */         $auth = array(             'uid'             => $user['id'],             'num'        => $user['num'],             'role'            => 'user' //记录用户类型         );         session('user_auth', $auth);         session('user_auth_sign', data_auth_sign($auth));     }       /*     * 用户注册     */     public function signup(){         if(is_user_login()){             $this->redirect('Index/index');         }         if(IS_GET){             //注册页面             $this->display();         }         if(IS_POST){             //判断用户             $data['num'] = I('num') ;             $User = M('user') ;             $datanum = $User->where($data)->find();             if ($datanum){                 $this->success('您已经注册过,请直接登录',U('signin'));             }else{                 $data['password'] = md5(I('password'));                 $data['name']   = I('name');                 $data['email']   = I('email');                 $data['addtime'] = time();                 $uid = $User->add($data);                 if($uid)                     $this->success('注册成功',U('signin')) ;                 else                         $this->error('注册失败') ;             }         }     }       public function logout(){         if(is_user_login()){             $User = M('user') ;             session('user_auth', null);             session('user_auth_sign', null);             session('[destroy]');             $this->success('登出成功!', U('signin'));         } else {             $this->redirect('signin');         }     }       //忘记密码     public function wjpas(){          if(IS_GET){              $this->display();         }         if(IS_POST){             $User = M('user') ;             $num = I('num') ;             $data['password'] = md5(I('password')) ;             $email = I('email') ;             $datanum = $User->where(array('num'=>$num))->find();             if ($datanum){                 if ($email === $datanum['email']) {                     $User->where(array('num'=>$num))->save($data); // 根据条件更新记录                     $this->success('密码修改成功',U('signin')) ;                 }else{                     $this->error('邮箱填写不正确,请重新填写');                     exit();                 }             }else{                 $this->error('用户不存在,请注册',U('signup'));             }         }     } } ?>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 <!DOCTYPE html> <html lang="en">   <head>     <meta charset="utf-8">     <title>Bootstrap Admin</title>     <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">     <meta name="viewport" content="width=device-width, initial-scale=1.0">     <meta name="description" content="">     <meta name="author" content="">     <link rel="stylesheet" type="text/css" href="__PUBLIC__/bootstrap/css/bootstrap.css">     <link rel="stylesheet" type="text/css" href="__PUBLIC__/stylesheets/theme.css">     <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.css">     <script src="__PUBLIC__/jquery-1.8.1.min.js" type="text/javascript"></script>     <script type="text/javascript" src="__PUBLIC__/layer/layer.min.js"></script>     <script src="__PUBLIC__/bootstrap/js/bootstrap.js"></script>     <script type="text/javascript" src='__PUBLIC__/layer/extend/layer.ext.js'></script>       <!-- Demo page code -->     <style type="text/css">         #line-chart {             height:300px;             width:800px;             margin: 0px auto;             margin-top: 1em;         }         .brand { font-family: georgia, serif; }         .brand .first {             color: #ccc;             font-style: italic;         }         .brand .second {             color: #fff;             font-weight: bold;         }     </style>       <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->     <!--[if lt IE 9]>       <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>     <![endif]-->       <!-- Le fav and touch icons -->     <link rel="shortcut icon" href="__PUBLIC__/assets/ico/favicon.ico">     <link rel="apple-touch-icon-precomposed" sizes="144x144" href="__PUBLIC__/assets/ico/apple-touch-icon-144-precomposed.png">     <link rel="apple-touch-icon-precomposed" sizes="114x114" href="__PUBLIC__/assets/ico/apple-touch-icon-114-precomposed.png">     <link rel="apple-touch-icon-precomposed" sizes="72x72" href="__PUBLIC__/assets/ico/apple-touch-icon-72-precomposed.png">     <link rel="apple-touch-icon-precomposed" href="__PUBLIC__/assets/ico/apple-touch-icon-57-precomposed.png">   </head>     <!--[if lt IE 7 ]> <body class="ie ie6"> <![endif]-->   <!--[if IE 7 ]> <body class="ie ie7"> <![endif]-->   <!--[if IE 8 ]> <body class="ie ie8"> <![endif]-->   <!--[if IE 9 ]> <body class="ie ie9"> <![endif]-->   <!--[if (gt IE 9)|!(IE)]><!-->   <body>   <!--<![endif]-->        <div class="navbar">         <div class="navbar-inner">             <div class="container-fluid">                 <ul class="nav pull-right">                                       </ul>                 <a class="brand" href=""><span class="first">CSV</span> <span class="second">&nbsp;drawing &nbsp;tool</span></a>             </div>         </div>     </div>             <div class="container-fluid">                   <div class="row-fluid">     <div class="dialog span4">         <div class="block">             <div class="block-heading">登录</div>             <div class="block-body">                 <form name="signin" id="form1" method="post" action="{:U('Login/signin')}">                     <label>工号</label>                     <input type="text" class="span12" name="num" value="" id="num">                     <label>密码</label>                     <input type="password" class="span12" name="password" value="" id="psw">                     <button type="submit" target-form="form1" class="am-btn am-btn-primary am-btn-block ajax-post" style="display:none;">提交</button>                    <button type="button" onclick="sub(this.form,this)" class="btn btn-primary pull-right" >登录</button>                     <label class="remember-me"><input type="checkbox"> 记住我</label>                     <div class="clearfix"></div>                 </form>             </div>         </div>         <p class="pull-right" style=""><a href="{:U('Login/signup')}" target="_blank">注册</a></p>                   <p><a href="{:U('Login/wjpas')}" target="_blank">忘记密码?</a></p>     </div> </div>   <script type="text/javascript" src="__PUBLIC__/Js/login.js"></script> <script type="text/javascript"> function sub(o){     //表单验证部分     if($("#num").val() == ""){         layer.alert('工号不能为空') ;         $("#num").focus();         return false ;     }     if($("#psw").val() == ""){         layer.alert('密码不能为空') ;         $("#psw").focus();         return false ;     }     $(".ajax-post").trigger('click') ; } </script>                             <!-- Le javascript     ================================================== -->     <!-- Placed at the end of the document so the pages load faster -->                                                                             </body> </html>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 <!DOCTYPE html> <html lang="en">   <head>     <meta charset="utf-8">     <title>Bootstrap Admin</title>     <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">     <meta name="viewport" content="width=device-width, initial-scale=1.0">     <meta name="description" content="">     <meta name="author" content="">     <link rel="stylesheet" type="text/css" href="__PUBLIC__/bootstrap/css/bootstrap.css">     <link rel="stylesheet" type="text/css" href="__PUBLIC__/stylesheets/theme.css">     <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.css">     <script src="__PUBLIC__/jquery-1.8.1.min.js" type="text/javascript"></script>     <script type="text/javascript" src="__PUBLIC__/layer/layer.min.js"></script>     <script src="__PUBLIC__/bootstrap/js/bootstrap.js"></script>     <script type="text/javascript" src='__PUBLIC__/layer/extend/layer.ext.js'></script>       <!-- Demo page code -->           <style type="text/css">         #line-chart {             height:300px;             width:800px;             margin: 0px auto;             margin-top: 1em;         }         .brand { font-family: georgia, serif; }         .brand .first {             color: #ccc;             font-style: italic;         }         .brand .second {             color: #fff;             font-weight: bold;         }         .block-heading font{             font-weight: lighter;             margin-left: 10px;             font-size: 13px;             color: #0088cc;             font-family: serif;         }     </style>       <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->     <!--[if lt IE 9]>       <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>     <![endif]-->       <!-- Le fav and touch icons -->     <link rel="shortcut icon" href="__PUBLIC__/assets/ico/favicon.ico">     <link rel="apple-touch-icon-precomposed" sizes="144x144" href="__PUBLIC__/assets/ico/apple-touch-icon-144-precomposed.png">     <link rel="apple-touch-icon-precomposed" sizes="114x114" href="__PUBLIC__/assets/ico/apple-touch-icon-114-precomposed.png">     <link rel="apple-touch-icon-precomposed" sizes="72x72" href="__PUBLIC__/assets/ico/apple-touch-icon-72-precomposed.png">     <link rel="apple-touch-icon-precomposed" href="__PUBLIC__/assets/ico/apple-touch-icon-57-precomposed.png">   </head>   <!--[if lt IE 7 ]> <body class="ie ie6"> <![endif]-->   <!--[if IE 7 ]> <body class="ie ie7"> <![endif]-->   <!--[if IE 8 ]> <body class="ie ie8"> <![endif]-->   <!--[if IE 9 ]> <body class="ie ie9"> <![endif]-->   <!--[if (gt IE 9)|!(IE)]><!-->   <body>   <!--<![endif]-->        <div class="navbar">         <div class="navbar-inner">             <div class="container-fluid">                 <ul class="nav pull-right">                                       </ul>                 <a class="brand" href=""><span class="first">CSV</span> <span class="second">&nbsp;drawing &nbsp;tool</span></a>             </div>         </div>     </div>             <div class="container-fluid">                   <div class="row-fluid">     <div class="span4 offset4 dialog">         <div class="block">             <div class="block-heading">注册<font>带*的为必填项</font></div>             <div class="block-body">                 <form name="signup" id="form1" method="post" action="{:U('Login/signup')}">                     <label>*工号</label>                     <input type="text" class="span12" name="num" value="" id="num">                     <label>*姓名</label>                     <input type="text" class="span12" name='name' value="" id="name">                     <label>*邮箱</label>                     <input type="text" class="span12" name="email" value="" id="email">                     <label>*密码</label>                     <input type="password" class="span12" name="password" value="" id="psw">                     <button type="submit" target-form="form1" class="am-btn am-btn-primary am-btn-block ajax-post" style="display:none;">提交</button>                    <button type="button" onclick="sub(this.form,this)"class="btn btn-primary pull-right" >注册</button>                     <!-- <a href="" class="btn btn-primary pull-right">注册</a> -->                     <label class="remember-me"><input type="checkbox"> 我同意<a href="terms-and-conditions.html">该网站使用协议</a></label>                     <div class="clearfix"></div>                 </form>             </div>         </div>         <p><a href="{:U('Login/signin')}">已注册过,立即登录</a></p>     </div> </div> <script type="text/javascript" src="__PUBLIC__/Js/login.js"></script> <script type="text/javascript"> function sub(o){     if($("#num").val() == ""){         layer.alert('工号不能为空') ;         $("#num").focus();         return false ;     }     if($("#name").val() == ""){         layer.alert('姓名不能为空') ;         $("#name").focus();         return false ;     }     if ($("#email").val() == "") {         layer.alert('邮箱不能为空') ;         $("#email").focus();         return false ;     }     if (!$("#email").val().match(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)) {         layer.alert("邮箱格式不正确");          $("#email").focus();         return false;     }       if($("#psw").val() == ""){         layer.alert('密码不能为空') ;         $("#psw").focus();         return false ;     }     //表单验证部分     $(".ajax-post").trigger('click') ; } </script>   </body> </html>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 <!DOCTYPE html> <html lang="en">   <head>     <meta charset="utf-8">     <title>Bootstrap Admin</title>     <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">     <meta name="viewport" content="width=device-width, initial-scale=1.0">     <meta name="description" content="">     <meta name="author" content="">     <link rel="stylesheet" type="text/css" href="__PUBLIC__/bootstrap/css/bootstrap.css">     <link rel="stylesheet" type="text/css" href="__PUBLIC__/stylesheets/theme.css">     <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.css">     <script src="__PUBLIC__/jquery-1.8.1.min.js" type="text/javascript"></script>     <script type="text/javascript" src="__PUBLIC__/layer/layer.min.js"></script>     <script src="__PUBLIC__/bootstrap/js/bootstrap.js"></script>     <script type="text/javascript" src='__PUBLIC__/layer/extend/layer.ext.js'></script>       <!-- Demo page code -->     <style type="text/css">         #line-chart {             height:300px;             width:800px;             margin: 0px auto;             margin-top: 1em;         }         .brand { font-family: georgia, serif; }         .brand .first {             color: #ccc;             font-style: italic;         }         .brand .second {             color: #fff;             font-weight: bold;         }         .block-heading font{             font-weight: lighter;             font-size: 13px;             color: #0088cc;             font-family: serif;         }     </style>       <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->     <!--[if lt IE 9]>       <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>     <![endif]-->       <!-- Le fav and touch icons -->     <link rel="shortcut icon" href="__PUBLIC__/assets/ico/favicon.ico">     <link rel="apple-touch-icon-precomposed" sizes="144x144" href="__PUBLIC__/assets/ico/apple-touch-icon-144-precomposed.png">     <link rel="apple-touch-icon-precomposed" sizes="114x114" href="__PUBLIC__/assets/ico/apple-touch-icon-114-precomposed.png">     <link rel="apple-touch-icon-precomposed" sizes="72x72" href="__PUBLIC__/assets/ico/apple-touch-icon-72-precomposed.png">     <link rel="apple-touch-icon-precomposed" href="__PUBLIC__/assets/ico/apple-touch-icon-57-precomposed.png">   </head>     <!--[if lt IE 7 ]> <body class="ie ie6"> <![endif]-->   <!--[if IE 7 ]> <body class="ie ie7"> <![endif]-->   <!--[if IE 8 ]> <body class="ie ie8"> <![endif]-->   <!--[if IE 9 ]> <body class="ie ie9"> <![endif]-->   <!--[if (gt IE 9)|!(IE)]><!-->   <body>   <!--<![endif]-->        <div class="navbar">         <div class="navbar-inner">             <div class="container-fluid">                 <ul class="nav pull-right">                                       </ul>                 <a class="brand" href=""><span class="first">CSV</span> <span class="second">&nbsp;drawing &nbsp;tool</span></a>             </div>         </div>     </div>             <div class="container-fluid">                   <div class="row-fluid">     <div class="dialog span4">         <div class="block">             <div class="block-heading">忘记密码<font>(输入注册时填写的工号和邮箱)</font></div>             <div class="block-body">                 <form name="signin" id="form1" method="post" action="{:U('Login/wjpas')}">                     <label>工号</label>                     <input type="text" class="span12" name="num" value="" id="num">                     <label>邮箱</label>                     <input type="text" class="span12" name="email" value="" id="email">                     <label>新密码</label>                     <input type="password" class="span12" name="password" value="" id="psw">                     <button type="submit" target-form="form1" class="am-btn am-btn-primary am-btn-block ajax-post" style="display:none;">提交</button>                    <button type="button" onclick="sub(this.form,this)" class="btn btn-primary pull-right" >提交</button>                     <div class="clearfix"></div>                 </form>             </div>         </div>     </div> </div>   <script type="text/javascript" src="__PUBLIC__/Js/login.js"></script> <script type="text/javascript"> function sub(o){     //表单验证部分     if($("#num").val() == ""){         layer.alert('工号不能为空') ;         $("#num").focus();         return false ;     }     if($("#email").val() == ""){         layer.alert('邮箱不能为空') ;         $("#email").focus();         return false ;     }     if($("#psw").val() == ""){         layer.alert('新密码不能为空') ;         $("#psw").focus();         return false ;     }     $(".ajax-post").trigger('click') ; } </script>   </body> </html>

原文地址:https://www.cnblogs.com/yuanscn/p/11032312.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


(1)创建数据表: CREATE TABLE IF NOT EXISTS `think_form` (   `id` smallint(4) unsigned NOT NULL AUTO_INCREMENT,
组合查询的主体还是采用数组方式查询,只是加入了一些特殊的查询支持,包括字符串模式查询(_string)、复合查询(_complex)、请求字符串查询(_query),混合查询中的特殊查询每次查询只能定义一个,由于采用数组的
(1)创建模版:/App/Home/View/Form/edit.html   <FORM method=\"post\" action=\"__URL__/update\">
自定义配置文件user.php: <?php return array(    \'sex\'=>\'man\', ); config.php: <?php return array(
在一些成熟的CMS系统中,后台一般都包含一个配置中心(如织梦后台中系统设置),以方便站长在后台修改配置文件;那么这个功能是如果实现的呢?在ThinkPHP中有没有捷径可走呢?答案肯定是有的。下面大概说一下这个功能
废话不多说先上图预览下,即本博客的分页; 这个分页类是在thinkphp框架内置的分页类的基础上修改而来,原分页类的一些设计,在实际运用中感觉不是很方便;
在php中截取字符串的函数有很多,而在thinkphp中也可以直接使用php的函数,本文给大家简单的介绍thinkPHP模板中截取字符串的具体用法,希望能对各位有所帮助。
thinkphp开发图片上传,图片异步上传是目前比较方便的功能,这里我就不写css文件了,将代码写出来。
配置数据库:/app/Common/Conf/config.php 方法一: // 添加数据库配置信息 \'DB_TYPE\'   => \'mysql\',// 数据库类型
/app/Home/Controller/IndexController.class.php
(1)创建数据表: CREATE TABLE IF NOT EXISTS `think_data` (   `id` int(8) unsigned NOT NULL AUTO_INCREMENT,
(1)控制器设置:/app/Home/Controller/IndexController.class.php <?php namespace HomeController; use ThinkController;
(1)普通模式 http://localhost/index.php?m=module&a=action&var=value m参数表示模块,a操作表示操作(模块和操作的URL参数名称是可以配置的),后面的表示其他GET参数。
入库的时候用htmlspecialchars()处理含有html代码的内容 输出的时候用htmlspecialchars_decode()处理含有html代码的内容
<?php define(\'APP_NAME\',\'app\'); define(\'APP_PATH\',\'./app/\'); define(\'APP_DEBUG\',TRUE); // 开启调试模式
(1)创建控制器中定义read方法:/App/Home/Controller/FormController.class.php public function read($id=0){
一、实现不同字段相同的查询条件 $User = M(\"User\"); // 实例化User对象 $map[\'name|title\'] = \'thinkphp\';
如果你的数据完全是内部操作写入而不是通过表单的话(也就是说可以充分信任数据的安全),那么可以直接使用add方法,如:
查询表达式的使用格式: $map[\'字段名\'] = array(\'表达式\',\'查询条件\'); 表达式不分大小写,支持的查询表达式有下面几种,分别表示的含义是:
一、使用字符串作为查询条件 $User = M(\"User\"); // 实例化User对象 $User->where(\'type=1 AND status=1\')->select();