chengxun 7 lat temu
rodzic
commit
89032a8b27

+ 2 - 2
application/edit/controller/Base.php

@@ -13,9 +13,9 @@ use think\Request;
 class Base extends Controller{
     public function _initialize()
     {
-        $aid=is_login(config('myconfig.admin_cookie_key'),db('AdminUser'),model('common/AdminUser'));
+        $aid = is_login(config('myconfig.admin_cookie_key'),db('AdminUser'),model('common/AdminUser'));
 
-        if( !$aid ){// 还没登录 跳转到登录页面
+        if( !$aid && $aid == 1){// 还没登录 跳转到登录页面
             $this->redirect(url('User/login'));
         }
         //权限验证

+ 28 - 0
application/index/controller/Base.php

@@ -0,0 +1,28 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: chengxun
+ * Date: 2018/5/14
+ * Time: 17:48
+ */
+
+namespace app\index\controller;
+
+
+class Base extends Common
+{
+    public function _initialize()
+    {
+        $aid = is_login(config('myconfig.admin_cookie_key'),db('AdminUser'),model('common/AdminUser'));
+
+        if( !$aid ){// 还没登录 跳转到登录页面
+            $this->redirect(url('User/login'));
+        }
+        //权限验证
+        $this->aid=$aid;
+        $request=Request::instance();
+//        if (!authCheck($request->module(),$request->controller(),$request->action(),$this->aid))        {
+//            $this->error('你没有权限!');
+//        }
+    }
+}

+ 17 - 0
application/index/controller/Common.php

@@ -0,0 +1,17 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: chengxun
+ * Date: 2018/5/14
+ * Time: 17:48
+ */
+
+namespace app\index\controller;
+
+
+use think\Controller;
+
+class Common extends Controller
+{
+
+}

+ 12 - 2
application/index/controller/Index.php

@@ -1,14 +1,24 @@
 <?php
 namespace app\index\controller;
 
+use app\common\model\AdminUser;
 use think\Controller;
 
-class Index extends Controller
+class Index extends Base
 {
     public function index()
     {
         $model=model('common/Project');
-        $data=$model->select();
+        $model_user = new AdminUser();
+        $user_data = $model_user->field('project_id')->where(['id'=>$this->aid])->find();
+        if($this->aid != 1){
+            $where = [
+                'id'=>['in',$user_data['project_id']],
+            ];
+        }else{
+            $where = [];
+        }
+        $data=$model->where($where)->select();
         $this->assign('data',$data);
         return $this->fetch('index');
     }

+ 1 - 1
application/index/controller/Project.php

@@ -11,7 +11,7 @@ namespace app\index\controller;
 
 use think\Controller;
 
-class Project extends Controller
+class Project extends Base
 {
     public function show(){
         $project_id=input('param.project_id');

+ 115 - 0
application/index/controller/User.php

@@ -0,0 +1,115 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: 珣
+ * Date: 2016/7/30
+ * Time: 16:13
+ */
+
+namespace app\index\controller;
+use think\Controller;
+
+class User extends Controller{
+    public function login(){
+        if(request()->isPost()){
+            $user_mobile=input('post.user_mobile');
+            $user_password=input('post.user_password');
+            $verify=input('post.verify');
+            $remember=input('post.remember');
+            $data=[
+                'user_mobile' =>   $user_mobile,
+                'user_password' => $user_password,
+                'verify'        =>  $verify,
+            ];
+            $result=$this->validate($data,'AdminUser.login');
+//            if($result!==true){
+//                $this->error($result);
+//            }else{
+                $model=model('common/AdminUser');
+                $uid=$model->login($user_mobile,$user_password,$type = 1,$remember);
+                if (0 < $uid) { // UC登录成功
+                    /* 登录用户 */
+                    return $this->success('登陆成功!','Index/index');
+                } else { // 登录失败
+                    switch ($uid) {
+                        case - 1 :
+                            $error = '用户不存在或被禁用!';
+                            break; // 系统级别禁用
+                        case - 2 :
+                            $error = '密码错误!';
+                            break;
+                        default :
+                            $error = '未知错误!';
+                            break; // 0-接口参数错误(调试阶段使用)
+                    }
+                    $this->error ( $error );
+                }
+
+//            }
+        }else{
+            return $this->fetch('login');
+        }
+    }
+    public function logout(){
+        $model=model('common/AdminUser');
+        $model->logout();
+        return $this->success('退出成功','index/index/index');
+    }
+
+    public function register(){
+        if(request()->isAjax()){
+            $data=input('param.');
+            $result=$this->validate($data,'SayUser.add');
+            if(true !== $result){
+                // 验证失败 输出错误信息
+                json_send([],$result,0);
+            }
+
+            verify(input('param.verify'),input('param.user_mobile'),1,60*5);
+
+            $user_model=model('common/SayUser');
+            $add_data=[
+                'user_name' => input('param.user_mobile'),
+                'user_mobile' =>input('param.user_mobile'),
+                'user_password' =>input('param.user_password'),
+            ];
+
+            if($user_model->data($add_data)->save()){
+                clear_verify(input('param.user_mobile'),1);
+                json_send();
+            }else{
+                json_send([],40023,0);
+            }
+        }else{
+            return $this->fetch('register');
+        }
+
+    }
+
+    public function forget_password(){
+        if(request()->isAjax()){
+            $data=input('param.');
+            $result=$this->validate($data,'SayUser.add');
+            if(true !== $result){
+                // 验证失败 输出错误信息
+                json_send([],$result,0);
+            }
+
+            verify(input('param.verify'),input('param.user_mobile'),2,60*5);
+
+            $user_model=model('common/SayUser');
+            $update_data=[
+                'user_password' =>input('param.user_password'),
+            ];
+
+            if($user_model->save($update_data,['user_mobile'=>input('param.user_mobile')])){
+                clear_verify(input('param.user_mobile'),2);
+                json_send();
+            }else{
+                json_send([],40023,0);
+            }
+        }else{
+            return $this->fetch('forget_password');
+        }
+    }
+}

+ 88 - 0
application/index/view/user/login.html

@@ -0,0 +1,88 @@
+
+<!DOCTYPE html>
+<html  style="background-color: #3b8ab8;">
+
+<head>
+    <meta charset="utf-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <title>登录</title>
+    <!-- Tell the browser to be responsive to screen width -->
+    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
+    <!-- Bootstrap 3.3.5 -->
+    <link rel="stylesheet" href="{:config('admin_static')}/bootstrap/css/bootstrap.min.css">
+    <!-- Font Awesome -->
+    <link rel="stylesheet" href="{:config('admin_static')}/adminLTE/css/font-awesome.min.css">
+    <!-- Ionicons -->
+    <link rel="stylesheet" href="{:config('admin_static')}/adminLTE/css/ionicons.min.css">
+    <!-- Theme style -->
+    <link rel="stylesheet" href="{:config('admin_static')}/adminLTE/css/AdminLTE.min.css">
+    <!-- iCheck -->
+    <link rel="stylesheet" href="{:config('admin_static')}/plugins/iCheck/square/blue.css">
+
+    <link rel="stylesheet" href="{:config('admin_static')}/adminLTE/css/skins/skin-blue.min.css">
+
+    <!--[if lt IE 9]>
+    <script src="{:config('admin_static')}/adminLTE/js/html5shiv.min.js"></script>
+    <script src="{:config('admin_static')}/adminLTE/js/respond.min.js"></script>
+    <![endif]-->
+</head>
+<body style="
+background-color: transparent;
+" class="hold-transition">
+<div  class="login-box">
+    <div class="login-logo">
+        <a style="color: #ffffff;" href=""><b>管理</b>系统</a>
+    </div><!-- /.login-logo -->
+    <div class="login-box-body">
+        <p class="login-box-msg">请输入信息</p>
+        <form action="{:url('User/login')}" method="post">
+            <div class="form-group has-feedback">
+                <input type="text" class="form-control" placeholder="账户" name="user_mobile">
+                <span class="glyphicon glyphicon-user form-control-feedback"></span>
+            </div>
+            <div class="form-group has-feedback">
+                <input type="password" class="form-control" placeholder="密码" name="user_password">
+                <span class="glyphicon glyphicon-lock form-control-feedback"></span>
+            </div>
+            <div class="form-group has-feedback">
+                <input type="password" class="form-control" placeholder="验证码" name="verify">
+                <span >
+                    <img style="margin-top: 15px;" id="verify" alt="验证码" onClick="show()" src="{:captcha_src()}" />
+                </span>
+
+            </div>
+            <div class="row">
+                <div class="col-xs-8">
+                    <div class="checkbox icheck">
+                        <label>
+                            <input name="remember" type="checkbox"> 记住我
+                        </label>
+                    </div>
+                </div><!-- /.col -->
+                <div class="col-xs-4">
+                    <button type="submit" class="btn btn-primary btn-block btn-flat">登录</button>
+                </div><!-- /.col -->
+            </div>
+        </form>
+    </div>
+</div><!-- /.login-box -->
+
+<!-- jQuery 2.1.4 -->
+<script src="{:config('admin_static')}/plugins/jQuery/jQuery-2.1.4.min.js"></script>
+<!-- Bootstrap 3.3.5 -->
+<script src="{:config('admin_static')}/bootstrap/js/bootstrap.min.js"></script>
+<script src="{:config('admin_static')}/plugins/iCheck/icheck.min.js"></script>
+<script>
+    $(function () {
+        $('input').iCheck({
+            checkboxClass: 'icheckbox_square-blue',
+            radioClass: 'iradio_square-blue',
+            increaseArea: '20%' // optional
+        });
+    });
+    function show(){
+        $('#verify').attr('src','{:captcha_src()}');
+    }
+</script>
+</body>
+</html>