Browse Source

refactor: 登录时任何登录方式都会记录存库,副密码登录的查询时过滤

lanjianrong 4 năm trước cách đây
mục cha
commit
a369924bbc
4 tập tin đã thay đổi với 35 bổ sung52 xóa
  1. 6 2
      app/service/login_logging.js
  2. 2 4
      app/service/project_account.js
  3. 23 46
      app/view/profile/safe.ejs
  4. 4 0
      sql/update.sql

+ 6 - 2
app/service/login_logging.js

@@ -34,8 +34,10 @@ module.exports = app => {
         /**
          * 创建登录日志
          * @return {Boolean} 日志是否创建成功
+         * @param {Number} type - 登录类型
+         * @param {Number} status - 是否显示记录
          */
-        async addLoginLog() {
+        async addLoginLog(type, status) {
             const { ctx } = this;
             const ip = ctx.request.ip ? ctx.request.ip : '';
             const ipInfo = await this.getIpInfoFromApi(ip);
@@ -50,6 +52,8 @@ module.exports = app => {
                 address: ipInfo,
                 uid: ctx.session.sessionUser.accountId,
                 pid: ctx.session.sessionProject.id,
+                type,
+                show: status,
             };
             return await this.createLog(payload);
         }
@@ -122,7 +126,7 @@ module.exports = app => {
          */
         async getLoginLogs(pid, uid) {
             return this.db.select(this.tableName, {
-                where: { pid, uid },
+                where: { pid, uid, show: 0 },
                 orders: [['create_time', 'desc']],
                 columns: ['browser', 'create_time', 'ip', 'os', 'address'],
                 limit: 10, offset: 0,

+ 2 - 4
app/service/project_account.js

@@ -243,10 +243,8 @@ module.exports = app => {
                     }
                     this.ctx.session.sessionProject = projectInfo;
                     this.ctx.session.sessionProjectList = projectList;
-                    if (loginStatus === loginWay.normalPsw) {
-                        // 正常登录-记录登录日志
-                        await this.ctx.service.loginLogging.addLoginLog();
-                    }
+                    // 记录登录日志
+                    await this.ctx.service.loginLogging.addLoginLog(loginType, loginStatus);
 
                 }
             } catch (error) {

+ 23 - 46
app/view/profile/safe.ejs

@@ -23,54 +23,31 @@
                             <% } %>
                         </form>
                         <!-- 访问日志 -->
-                        <% if(ctx.session.sessionUser.loginStatus === loginWay.normalPsw) { %>
-                            <div class="col-12 mt-5">
-                                <h4>访问日志</h4>
-                                <table class="table table-hover">
-                                    <thead>
+                        <div class="col-12 mt-5">
+                            <h4>访问日志</h4>
+                            <table class="table table-hover">
+                                <thead>
+                                    <tr>
+                                        <th></th>
+                                        <th>系统</th>
+                                        <th>浏览器</th>
+                                        <th>登录时间</th>
+                                        <th>登录地址</th>
+                                    </tr>
+                                </thead>
+                                <tbody>
+                                    <% loginLogging.forEach((item, idx) => { %>
                                         <tr>
-                                            <th></th>
-                                            <th>系统</th>
-                                            <th>浏览器</th>
-                                            <th>登录时间</th>
-                                            <th>登录地址</th>
+                                            <td><%- idx + 1 %></td>
+                                            <td><%- item.os %></td>
+                                            <td><%- item.browser %></td>
+                                            <td><%- ctx.helper.formatFullDate(item.create_time) %></td>
+                                            <td><%- item.address %></td>
                                         </tr>
-                                    </thead>
-                                    <tbody>
-                                        <% loginLogging.forEach((item, idx) => { %>
-                                            <tr>
-                                                <td><%- idx + 1 %></td>
-                                                <td><%- item.os %></td>
-                                                <td><%- item.browser %></td>
-                                                <td><%- ctx.helper.formatFullDate(item.create_time) %></td>
-                                                <td><%- item.address %></td>
-                                            </tr>
-                                        <% }) %>
-                                        <!-- <tr>
-                                            <td>1</td>
-                                            <td>Windows NT 10.0 64-bit</td>
-                                            <td>Chrome 55.0.2883.87 m (64-bit)</td>
-                                            <td>2017-01-12 09:09</td>
-                                            <td>广东省珠海市 电信(116.19.86.133)</td>
-                                        </tr>
-                                        <tr>
-                                            <td>2</td>
-                                            <td>Windows NT 10.0 64-bit</td>
-                                            <td>Chrome 55.0.2883.87 m (64-bit)</td>
-                                            <td>2017-01-12 09:09</td>
-                                            <td>广东省珠海市 电信(116.19.86.133)</td>
-                                        </tr>
-                                        <tr>
-                                            <td>3</td>
-                                            <td>Windows NT 10.0 64-bit</td>
-                                            <td>Chrome 55.0.2883.87 m (64-bit)</td>
-                                            <td>2017-01-12 09:09</td>
-                                            <td>广东省珠海市 电信(116.19.86.133)</td>
-                                        </tr> -->
-                                    </tbody>
-                                </table>
-                            </div>
-                        <% } %>
+                                    <% }) %>
+                                </tbody>
+                            </table>
+                        </div>
                     </div>
                 </div>
             </div>

+ 4 - 0
sql/update.sql

@@ -1,3 +1,7 @@
 ALTER TABLE `zh_project` CHANGE `page_show` `page_show` VARCHAR(5000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT '{\"bwtz\":\"1\"}' COMMENT '前台页面或功能展示与隐藏';
 
 ALTER TABLE `zh_change_audit_list` ADD `xmj_code` VARCHAR(500) NULL DEFAULT NULL COMMENT '项目节编号' AFTER `detail`, ADD `xmj_jldy` VARCHAR(500) NULL DEFAULT NULL COMMENT '细目' AFTER `xmj_code`;
+
+ALTER TABLE `zh_login_logging`
+ADD COLUMN `type` INT(1) NOT NULL COMMENT '登录类型 1(sso登录) | 2(正常或副密码登录) | 3(接口登录或微信登录)' AFTER `pid`, ADD `show` INT(1) NOT NULL COMMENT '是否显示: 0-显示,1-不显示' AFTER `TYPE`;
+