Browse Source

PC端基础

lizhen_gitee 8 months ago
parent
commit
ba4c58fc3a

+ 9 - 15
application/api/controller/company/User.php → application/api/controller/company/Index.php

@@ -12,7 +12,7 @@ use think\Db;
 /**
  * 会员接口
  */
-class User extends Apic
+class Index extends Apic
 {
     protected $noNeedLogin = ['login'];
     protected $noNeedRight = '*';
@@ -26,29 +26,23 @@ class User extends Apic
     //员工账号+密码登录
     public function login()
     {
-        $account = input('account');
+        $username = input('username');
         $password = input('password');
-        if (!$account || !$password) {
+        if (!$username || !$password) {
             $this->error(__('Invalid parameters'));
         }
 
-        //找员工
-        $userstaff = Db::name('pc_admin')->where('username',$account)->find();
-        if($userstaff)
-        {
-            $user = \app\common\model\Company::get($userstaff['company_id']);
-            if($user)
-            {
-                $ret = $this->auth->direct($user->id,$userstaff['id']);
-            }
-        }
+        PcAdminLog::setTitle(__('Login'));
 
-        $ret = $this->auth->login($account, $password);
+        //找员工
+        $ret = $this->auth->login($username, $password);
         if ($ret) {
             $data = $this->auth->getUserinfo_simple();
             $this->success(__('Logged in successful'), $data);
         } else {
-            $this->error($this->auth->getError());
+            $msg = $this->auth->getError();
+            $msg = $msg ? $msg : __('Username or password is incorrect');
+            $this->error($msg);
         }
     }
 

+ 1 - 1
application/common/controller/Apiw.php

@@ -427,7 +427,7 @@ class Apiw
         if ($this->logType === 1){
             //日志统一写入
             register_shutdown_function([new LogUtil, 'close']);
-            LogUtil::getInstance('Api/'); //设置日志存入通道
+            LogUtil::getInstance('Apiw/'); //设置日志存入通道
 
             LogUtil::info('uid', 'Api-Middleware-Log', 'request_log', $this->auth->id);
             LogUtil::info('api', 'Api-Middleware-Log', 'request_log', $modulename . '/' . $controllername . '/' . $actionname);

File diff suppressed because it is too large
+ 23 - 91
application/common/library/Authcompany.php


+ 117 - 0
application/common/model/PcAdminLog.php

@@ -0,0 +1,117 @@
+<?php
+
+namespace app\common\model;
+
+use app\common\library\Authcompany as Auth;
+use think\Model;
+use think\Loader;
+
+class PcAdminLog extends Model
+{
+
+    // 开启自动写入时间戳字段
+    protected $autoWriteTimestamp = 'int';
+    // 定义时间戳字段名
+    protected $createTime = 'createtime';
+    protected $updateTime = '';
+    //自定义日志标题
+    protected static $title = '';
+    //自定义日志内容
+    protected static $content = '';
+    //忽略的链接正则列表
+    protected static $ignoreRegex = [
+        '/^(.*)\/(selectpage|index)$/i',
+    ];
+
+    public static function setTitle($title)
+    {
+        self::$title = $title;
+    }
+
+    public static function setContent($content)
+    {
+        self::$content = $content;
+    }
+
+    public static function setIgnoreRegex($regex = [])
+    {
+        $regex = is_array($regex) ? $regex : [$regex];
+        self::$ignoreRegex = array_merge(self::$ignoreRegex, $regex);
+    }
+
+    /**
+     * 记录日志
+     * @param string $title   日志标题
+     * @param string $content 日志内容
+     */
+    public static function record($title = '', $content = '')
+    {
+        $auth = Auth::instance();
+        $admin_id = $auth->isLogin() ? $auth->id : 0;
+        $username = $auth->isLogin() ? $auth->username : __('Unknown');
+
+        // 设置过滤函数
+        request()->filter('trim,strip_tags,htmlspecialchars');
+
+        $controllername = Loader::parseName(request()->controller());
+        $actionname = strtolower(request()->action());
+        $path = str_replace('.', '/', $controllername) . '/' . $actionname;
+        if (self::$ignoreRegex) {
+            foreach (self::$ignoreRegex as $index => $item) {
+                if (preg_match($item, $path)) {
+                    return;
+                }
+            }
+        }
+        $content = $content ?: self::$content;
+        if (!$content) {
+            $content = request()->param('') ?: file_get_contents("php://input");
+            $content = self::getPureContent($content);
+        }
+        $title = $title ?: self::$title;
+        if (!$title) {
+            $title = [];
+            $breadcrumb = Auth::instance()->getBreadcrumb($path);
+            foreach ($breadcrumb as $k => $v) {
+                $title[] = $v['title'];
+            }
+            $title = implode(' / ', $title);
+        }
+        self::create([
+            'title'     => $title,
+            'content'   => !is_scalar($content) ? json_encode($content, JSON_UNESCAPED_UNICODE) : $content,
+            'url'       => substr(xss_clean(strip_tags(request()->url())), 0, 1500),
+            'admin_id'  => $admin_id,
+            'username'  => $username,
+            'useragent' => substr(request()->server('HTTP_USER_AGENT'), 0, 255),
+            'ip'        => xss_clean(strip_tags(request()->ip()))
+        ]);
+    }
+
+    /**
+     * 获取已屏蔽关键信息的数据
+     * @param $content
+     * @return array
+     */
+    protected static function getPureContent($content)
+    {
+        if (!is_array($content)) {
+            return $content;
+        }
+        foreach ($content as $index => &$item) {
+            if (preg_match("/(password|salt|token)/i", $index)) {
+                $item = "***";
+            } else {
+                if (is_array($item)) {
+                    $item = self::getPureContent($item);
+                }
+            }
+        }
+        return $content;
+    }
+
+    public function admin()
+    {
+        return $this->belongsTo('PcAdmin', 'admin_id')->setEagerlyType(0);
+    }
+}

+ 5 - 0
application/config.php

@@ -372,4 +372,9 @@ return [
     //默认头像
     'user_default_avatar' => '/assets/img/avatar.png',
 
+    //公司管理员
+    'pc_admin' => [
+        'login_failure_retry'   => true,
+    ],
+
 ];

Some files were not shown because too many files changed in this diff