diff --git a/log/SQL.log b/log/SQL.log index cc60971..959fbe3 100644 --- a/log/SQL.log +++ b/log/SQL.log @@ -704,3 +704,375 @@ inMemory: 0, readWriteMode: 6 } +[2022-02-24T23:23:08.717] [DEBUG] SQL - Executing (default): SELECT `id`, `username`, `password`, `email`, `createdAt`, `updatedAt` FROM `Users` AS `User` WHERE `User`.`username` = 'xieyaxin' LIMIT 1; { + plain: true, + raw: false, + logging: [Function: bound ], + where: "`User`.`username` = 'xieyaxin'", + limit: 1, + hooks: true, + rejectOnEmpty: false, + originalAttributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + attributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + tableNames: [ 'Users' ], + type: 'SELECT', + model: User, + uuid: 'default', + storage: '/home/dash/code/demo/hapi-demo/source/db/data.db', + inMemory: 0, + readWriteMode: 6 +} +[2022-02-24T23:23:08.810] [DEBUG] SQL - Executing (default): INSERT INTO `Users` (`id`,`username`,`password`,`createdAt`,`updatedAt`) VALUES (NULL,$1,$2,$3,$4); { + plain: false, + raw: false, + logging: [Function: bound ], + hooks: true, + validate: true, + fields: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + defaultFields: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + returning: true, + hasTrigger: undefined, + dialect: 'sqlite', + dialectModule: null, + dialectModulePath: null, + protocol: 'tcp', + define: {}, + query: {}, + sync: {}, + timezone: '+00:00', + clientMinMessages: 'warning', + standardConformingStrings: true, + omitNull: false, + native: false, + replication: false, + ssl: undefined, + pool: {}, + quoteIdentifiers: true, + retry: { max: 5, match: [ 'SQLITE_BUSY: database is locked' ] }, + transactionType: 'DEFERRED', + isolationLevel: null, + databaseVersion: 0, + typeValidation: false, + benchmark: false, + minifyAliases: false, + logQueryParameters: false, + storage: '/home/dash/code/demo/hapi-demo/source/db/data.db', + type: 'INSERT', + instance: User { + dataValues: { + id: null, + username: 'xieyaxin', + password: '$2b$10$YLkPy2gcnuP6vY7THjm/AOY2ep7qdybqP6T6hZbK3/Hd9ZzOAiyYa', + email: undefined, + updatedAt: 2022-02-24T15:23:08.805Z, + createdAt: 2022-02-24T15:23:08.805Z + }, + _previousDataValues: { username: undefined, password: undefined }, + _changed: Set(2) { 'username', 'password' }, + _options: { + isNewRecord: true, + _schema: null, + _schemaDelimiter: '', + attributes: undefined, + include: undefined, + raw: undefined, + silent: undefined + }, + isNewRecord: true + }, + model: User, + bind: [ + 'xieyaxin', + '$2b$10$YLkPy2gcnuP6vY7THjm/AOY2ep7qdybqP6T6hZbK3/Hd9ZzOAiyYa', + '2022-02-24 15:23:08.805 +00:00', + '2022-02-24 15:23:08.805 +00:00' + ], + uuid: 'default', + inMemory: 0, + readWriteMode: 6 +} +[2022-02-24T23:38:02.696] [DEBUG] SQL - Executing (default): SELECT `id`, `username`, `password`, `email`, `createdAt`, `updatedAt` FROM `Users` AS `User` WHERE `User`.`username` = 'xieyaxin' LIMIT 1; { + plain: true, + raw: false, + logging: [Function: bound ], + where: "`User`.`username` = 'xieyaxin'", + limit: 1, + hooks: true, + rejectOnEmpty: false, + originalAttributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + attributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + tableNames: [ 'Users' ], + type: 'SELECT', + model: User, + uuid: 'default', + storage: '/home/dash/code/demo/hapi-demo/source/db/data.db', + inMemory: 0, + readWriteMode: 6 +} +[2022-02-24T23:38:25.085] [DEBUG] SQL - Executing (default): SELECT `id`, `username`, `password`, `email`, `createdAt`, `updatedAt` FROM `Users` AS `User` WHERE `User`.`username` = '' LIMIT 1; { + plain: true, + raw: false, + logging: [Function: bound ], + where: "`User`.`username` = ''", + limit: 1, + hooks: true, + rejectOnEmpty: false, + originalAttributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + attributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + tableNames: [ 'Users' ], + type: 'SELECT', + model: User, + uuid: 'default', + storage: '/home/dash/code/demo/hapi-demo/source/db/data.db', + inMemory: 0, + readWriteMode: 6 +} +[2022-02-25T00:42:11.614] [DEBUG] SQL - Executing (default): SELECT `id`, `username`, `password`, `email`, `createdAt`, `updatedAt` FROM `Users` AS `User` WHERE `User`.`username` = 'xieyain' LIMIT 1; { + plain: true, + raw: false, + logging: [Function: bound ], + where: "`User`.`username` = 'xieyain'", + limit: 1, + hooks: true, + rejectOnEmpty: false, + originalAttributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + attributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + tableNames: [ 'Users' ], + type: 'SELECT', + model: User, + uuid: 'default', + storage: '/home/dash/code/demo/hapi-demo/source/db/data.db', + inMemory: 0, + readWriteMode: 6 +} +[2022-02-25T00:42:43.985] [DEBUG] SQL - Executing (default): SELECT `id`, `username`, `password`, `email`, `createdAt`, `updatedAt` FROM `Users` AS `User` WHERE `User`.`username` = 'xieyain' LIMIT 1; { + plain: true, + raw: false, + logging: [Function: bound ], + where: "`User`.`username` = 'xieyain'", + limit: 1, + hooks: true, + rejectOnEmpty: false, + originalAttributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + attributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + tableNames: [ 'Users' ], + type: 'SELECT', + model: User, + uuid: 'default', + storage: '/home/dash/code/demo/hapi-demo/source/db/data.db', + inMemory: 0, + readWriteMode: 6 +} +[2022-02-25T00:42:51.365] [DEBUG] SQL - Executing (default): SELECT `id`, `username`, `password`, `email`, `createdAt`, `updatedAt` FROM `Users` AS `User` WHERE `User`.`username` = 'xieyain' LIMIT 1; { + plain: true, + raw: false, + logging: [Function: bound ], + where: "`User`.`username` = 'xieyain'", + limit: 1, + hooks: true, + rejectOnEmpty: false, + originalAttributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + attributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + tableNames: [ 'Users' ], + type: 'SELECT', + model: User, + uuid: 'default', + storage: '/home/dash/code/demo/hapi-demo/source/db/data.db', + inMemory: 0, + readWriteMode: 6 +} +[2022-02-25T00:46:08.419] [DEBUG] SQL - Executing (default): SELECT `id`, `username`, `password`, `email`, `createdAt`, `updatedAt` FROM `Users` AS `User` WHERE `User`.`username` = 'xieyain' LIMIT 1; { + plain: true, + raw: false, + logging: [Function: bound ], + where: "`User`.`username` = 'xieyain'", + limit: 1, + hooks: true, + rejectOnEmpty: false, + originalAttributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + attributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + tableNames: [ 'Users' ], + type: 'SELECT', + model: User, + uuid: 'default', + storage: '/home/dash/code/demo/hapi-demo/source/db/data.db', + inMemory: 0, + readWriteMode: 6 +} +[2022-02-25T00:47:27.299] [DEBUG] SQL - Executing (default): SELECT `id`, `username`, `password`, `email`, `createdAt`, `updatedAt` FROM `Users` AS `User` WHERE `User`.`username` = 'xieyain' LIMIT 1; { + plain: true, + raw: false, + logging: [Function: bound ], + where: "`User`.`username` = 'xieyain'", + limit: 1, + hooks: true, + rejectOnEmpty: false, + originalAttributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + attributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + tableNames: [ 'Users' ], + type: 'SELECT', + model: User, + uuid: 'default', + storage: '/home/dash/code/demo/hapi-demo/source/db/data.db', + inMemory: 0, + readWriteMode: 6 +} +[2022-02-25T00:47:32.928] [DEBUG] SQL - Executing (default): SELECT `id`, `username`, `password`, `email`, `createdAt`, `updatedAt` FROM `Users` AS `User` WHERE `User`.`username` = 'xieyain' LIMIT 1; { + plain: true, + raw: false, + logging: [Function: bound ], + where: "`User`.`username` = 'xieyain'", + limit: 1, + hooks: true, + rejectOnEmpty: false, + originalAttributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + attributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + tableNames: [ 'Users' ], + type: 'SELECT', + model: User, + uuid: 'default', + storage: '/home/dash/code/demo/hapi-demo/source/db/data.db', + inMemory: 0, + readWriteMode: 6 +} +[2022-02-25T00:47:45.311] [DEBUG] SQL - Executing (default): SELECT `id`, `username`, `password`, `email`, `createdAt`, `updatedAt` FROM `Users` AS `User` WHERE `User`.`username` = 'xieyain' LIMIT 1; { + plain: true, + raw: false, + logging: [Function: bound ], + where: "`User`.`username` = 'xieyain'", + limit: 1, + hooks: true, + rejectOnEmpty: false, + originalAttributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + attributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + tableNames: [ 'Users' ], + type: 'SELECT', + model: User, + uuid: 'default', + storage: '/home/dash/code/demo/hapi-demo/source/db/data.db', + inMemory: 0, + readWriteMode: 6 +} +[2022-02-25T00:47:50.265] [DEBUG] SQL - Executing (default): SELECT `id`, `username`, `password`, `email`, `createdAt`, `updatedAt` FROM `Users` AS `User` WHERE `User`.`username` = 'xieyain' LIMIT 1; { + plain: true, + raw: false, + logging: [Function: bound ], + where: "`User`.`username` = 'xieyain'", + limit: 1, + hooks: true, + rejectOnEmpty: false, + originalAttributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + attributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + tableNames: [ 'Users' ], + type: 'SELECT', + model: User, + uuid: 'default', + storage: '/home/dash/code/demo/hapi-demo/source/db/data.db', + inMemory: 0, + readWriteMode: 6 +} +[2022-02-25T00:48:07.598] [DEBUG] SQL - Executing (default): SELECT `id`, `username`, `password`, `email`, `createdAt`, `updatedAt` FROM `Users` AS `User` WHERE `User`.`username` = 'xieyain' LIMIT 1; { + plain: true, + raw: false, + logging: [Function: bound ], + where: "`User`.`username` = 'xieyain'", + limit: 1, + hooks: true, + rejectOnEmpty: false, + originalAttributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + attributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + tableNames: [ 'Users' ], + type: 'SELECT', + model: User, + uuid: 'default', + storage: '/home/dash/code/demo/hapi-demo/source/db/data.db', + inMemory: 0, + readWriteMode: 6 +} +[2022-02-25T00:48:40.361] [DEBUG] SQL - Executing (default): SELECT `id`, `username`, `password`, `email`, `createdAt`, `updatedAt` FROM `Users` AS `User` WHERE `User`.`username` = 'xieyain' LIMIT 1; { + plain: true, + raw: false, + logging: [Function: bound ], + where: "`User`.`username` = 'xieyain'", + limit: 1, + hooks: true, + rejectOnEmpty: false, + originalAttributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + attributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + tableNames: [ 'Users' ], + type: 'SELECT', + model: User, + uuid: 'default', + storage: '/home/dash/code/demo/hapi-demo/source/db/data.db', + inMemory: 0, + readWriteMode: 6 +} +[2022-02-25T00:48:47.563] [DEBUG] SQL - Executing (default): SELECT `id`, `username`, `password`, `email`, `createdAt`, `updatedAt` FROM `Users` AS `User` WHERE `User`.`username` = 'xieyaxin' LIMIT 1; { + plain: true, + raw: false, + logging: [Function: bound ], + where: "`User`.`username` = 'xieyaxin'", + limit: 1, + hooks: true, + rejectOnEmpty: false, + originalAttributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + attributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + tableNames: [ 'Users' ], + type: 'SELECT', + model: User, + uuid: 'default', + storage: '/home/dash/code/demo/hapi-demo/source/db/data.db', + inMemory: 0, + readWriteMode: 6 +} +[2022-02-25T00:48:47.657] [DEBUG] SQL - Executing (default): SELECT `id`, `username`, `password`, `email`, `createdAt`, `updatedAt` FROM `Users` AS `User` WHERE `User`.`id` = 4; { + plain: true, + raw: false, + logging: [Function: bound ], + where: '`User`.`id` = 4', + hooks: true, + rejectOnEmpty: false, + originalAttributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + attributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + tableNames: [ 'Users' ], + type: 'SELECT', + model: User, + uuid: 'default', + storage: '/home/dash/code/demo/hapi-demo/source/db/data.db', + inMemory: 0, + readWriteMode: 6 +} +[2022-02-25T00:50:19.830] [DEBUG] SQL - Executing (default): SELECT `id`, `username`, `password`, `email`, `createdAt`, `updatedAt` FROM `Users` AS `User` WHERE `User`.`id` = 4; { + plain: true, + raw: false, + logging: [Function: bound ], + where: '`User`.`id` = 4', + hooks: true, + rejectOnEmpty: false, + originalAttributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + attributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + tableNames: [ 'Users' ], + type: 'SELECT', + model: User, + uuid: 'default', + storage: '/home/dash/code/demo/hapi-demo/source/db/data.db', + inMemory: 0, + readWriteMode: 6 +} +[2022-02-25T19:44:28.822] [DEBUG] SQL - Executing (default): SELECT `id`, `username`, `password`, `email`, `createdAt`, `updatedAt` FROM `Users` AS `User` WHERE `User`.`id` = 4; { + plain: true, + raw: false, + logging: [Function: bound ], + where: '`User`.`id` = 4', + hooks: true, + rejectOnEmpty: false, + originalAttributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + attributes: [ 'id', 'username', 'password', 'email', 'createdAt', 'updatedAt' ], + tableNames: [ 'Users' ], + type: 'SELECT', + model: User, + uuid: 'default', + storage: '/home/dash/code/demo/hapi-demo/source/db/data.db', + inMemory: 0, + readWriteMode: 6 +} diff --git a/source/validate.ts b/source/auth/index.ts similarity index 100% rename from source/validate.ts rename to source/auth/index.ts diff --git a/source/db/data.db b/source/db/data.db index 9e6c176..6355ccc 100644 Binary files a/source/db/data.db and b/source/db/data.db differ diff --git a/source/db/index.ts b/source/db/index.ts index 4776b7d..f5c58ad 100644 --- a/source/db/index.ts +++ b/source/db/index.ts @@ -6,7 +6,6 @@ export const sequelize = new Sequelize({ logging: loggerSQL.debug.bind(loggerSQL) // Alternative way to use custom logger, displays all messages }); - export async function connect(){ try { await sequelize.authenticate(); diff --git a/source/route/api/user/index.ts b/source/route/api/user/index.ts index 1413501..103b293 100644 --- a/source/route/api/user/index.ts +++ b/source/route/api/user/index.ts @@ -11,7 +11,7 @@ import User from "@/model/User"; import * as bcrypt from "bcrypt"; import * as jwt from "jsonwebtoken"; import * as Joi from "joi"; -import { UserSchema } from "@/validateSchema"; +import { UserSchema } from "@/schema"; export default class { @validate({ diff --git a/source/route/index/index.ts b/source/route/index/index.ts index f18a1be..ae1f63d 100644 --- a/source/route/index/index.ts +++ b/source/route/index/index.ts @@ -40,7 +40,7 @@ export default class { const account = await User.findOne({ where: { username: username } }); if (!account || !(await bcrypt.compare(password, account.password))) { - return h.view("/login"); + return h.redirect("/login"); } request.cookieAuth.set({ id: account.id }); @@ -49,7 +49,7 @@ export default class { } @route("/about") - @auth() + @auth(false) about(request, h) { console.log(request.auth); return h.view("views/about.ejs"); diff --git a/source/route/route.txt b/source/route/route.txt index 3291b13..0c059a9 100644 --- a/source/route/route.txt +++ b/source/route/route.txt @@ -16,4 +16,4 @@ 需要权限: GET / 不需权限: GET /login 不需权限: POST /login - 需要权限: GET /about \ No newline at end of file + 不需权限: GET /about \ No newline at end of file diff --git a/source/run.ts b/source/run.ts index 934c546..6f9337c 100644 --- a/source/run.ts +++ b/source/run.ts @@ -2,7 +2,7 @@ import plugins from "@/plugins"; import path from "path"; import { baseDir, templateDir } from "@/util"; -import { validateJwt, validateSession } from "./validate"; +import { validateJwt, validateSession } from "./auth"; import Hapi, {Server} from "@hapi/hapi" // const Hapi = require("@hapi/hapi"); // const HapiSwagger = require("hapi-swagger"); diff --git a/source/validateSchema/index.ts b/source/schema/index.ts similarity index 100% rename from source/validateSchema/index.ts rename to source/schema/index.ts diff --git a/template/views/color.pug b/template/views/color.pug index 2136921..20372cd 100644 --- a/template/views/color.pug +++ b/template/views/color.pug @@ -15,7 +15,7 @@ block content { color:"#999999",title: "辅助色",describe:"灰色灰色灰色灰色灰色灰色灰色灰色灰色灰色灰色灰色灰色灰色灰色"}, { color:"#999999",title: "辅助色",describe:"灰色灰色灰色灰色灰色灰色灰色灰色灰色灰色灰色灰色灰色灰色灰色"}, { color:"#999999",title: "辅助色",describe:"灰色灰色灰色灰色灰色灰色灰色灰色灰色灰色灰色灰色灰色灰色灰色"}, - { color:"#999999",title: "辅助色",describe:""}, + { color:"#000000",title: "辅助色",describe:""}, { color:"#999999",title: "辅助色",describe:""}, { color:"#999999",title: "辅助色",describe:""}, { color:"#999999",title: "辅助色",describe:""}, @@ -35,7 +35,7 @@ block content ] each item in list div(class="color_item") - div(class="color_item_bg") + div(class="color_item_bg" style=`background: ${item.color}`) div(class="color_toggle_list") div(class="color_toggle_item") hex div(class="color_toggle_item") rgba diff --git a/template/views/demo.ejs b/template/views/demo.ejs index cd6b412..1ac7866 100644 --- a/template/views/demo.ejs +++ b/template/views/demo.ejs @@ -1,4 +1,4 @@ -
+
@@ -23,7 +23,7 @@ // code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } - xmlhttp.open("POST", "/upload", true); + xmlhttp.open("POST", "/demo/upload", true); // 这里不需要自己加,会自己处理 // xmlhttp.setRequestHeader("Content-Type", "multipart/form-data");