Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
SunWuyuan committed Apr 4, 2024
1 parent 5280f66 commit b767b66
Show file tree
Hide file tree
Showing 18 changed files with 186 additions and 105 deletions.
5 changes: 5 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ app.all("*", function (req, res, next) {
userid: "",
username: "",
nickname: "",
avatar: "",
is_admin: 0,
};
//console.log("JWT验证失败: " + err.message);
Expand All @@ -135,6 +136,8 @@ app.all("*", function (req, res, next) {
res.locals.userid = userInfo.userid;
res.locals.username = userInfo.username;
res.locals.nickname = userInfo.nickname;
res.locals.avatar = userInfo.avatar;

res.locals["is_admin"] = 0;
if (userInfo.username == process.env.adminuser) {
res.locals["is_admin"] = 1;
Expand All @@ -147,6 +150,7 @@ app.all("*", function (req, res, next) {
userid: res.locals.userid,
username: res.locals.username,
nickname: res.locals.nickname,
avatar: res.locals.avatar,
is_admin: res.locals["is_admin"],
};

Expand All @@ -162,6 +166,7 @@ app.all("*", function (req, res, next) {
userid: "",
username: "",
nickname: "",
avatar: "",
is_admin: 0,
};
//console.log("未找到JWT Token");
Expand Down
Binary file added data/upload_tmp/zy7zrPBTO5lbF1LDcL9XGaDe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/user/1
Binary file not shown.
Binary file modified data/user/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 3 additions & 7 deletions server/lib/fuck.js → server/lib/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const s3 = new S3Client({
// Create a bucket and upload something into it


exports.S3update = function S3update(name, file,username) {
exports.S3update = function ow(name, file,username) {
console.log(name);
try {
s3.send(new PutObjectCommand({
Expand Down Expand Up @@ -81,13 +81,9 @@ exports.jwt = function (data) {
console.log(token);
return token;
};
exports.GenerateJwt = function (id, email, nickname) {
exports.GenerateJwt = function (json) {
token = jwt.sign(
{
userid: id,
username: email,
nickname: nickname,
},
json,
process.env.jwttoken
);
return token;
Expand Down
2 changes: 1 addition & 1 deletion server/router_admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var router = express.Router();
var fs = require('fs');

//功能函数集
var I = require('./lib/fuck.js');
var I = require('./lib/global.js');

//数据库
var DB = require("./lib/database.js");
Expand Down
2 changes: 1 addition & 1 deletion server/router_ads.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var express = require('express');
var router = express.Router();
var fs = require('fs');
//功能函数集
var I = require('./lib/fuck.js');
var I = require('./lib/global.js');
//数据库
var DB = require("./lib/database.js");

Expand Down
4 changes: 2 additions & 2 deletions server/router_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var router = express.Router();
var fs = require('fs');

//功能函数集
var I = require('./lib/fuck.js');
var I = require('./lib/global.js');
//数据库
var DB = require("./lib/database.js");

Expand Down Expand Up @@ -127,7 +127,7 @@ router.get('/usertx', function (req, res) {
}


res.redirect(302, process.env.S3staticurl+'/user/'+USER[0].images+'.png');
res.redirect(302, process.env.S3staticurl+'/user/'+USER[0].images);
});
});

Expand Down
14 changes: 10 additions & 4 deletions server/router_my.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var router = express.Router();
var fs = require('fs');
var crypto = require('crypto');
//功能函数集
var I = require('./lib/fuck.js');
var I = require('./lib/global.js');
//数据库
var DB = require("./lib/database.js");

Expand Down Expand Up @@ -257,7 +257,7 @@ router.post('/set/avatar', function (req, res) {
}

tmppath = req['files']['file']['path'];
newpath = `./data/user/${res.locals.userid}.png`;
newpath = `./data/user/${res.locals.userid}`;
fs.rename(tmppath, newpath,function (err) {
if (err) {
res.status(200).send( {'status':'文件上传失败'} );
Expand All @@ -273,7 +273,7 @@ router.post('/set/avatar', function (req, res) {
chunks.on('end', () => {
const hashValue = hash.digest('hex');
// 上传到七牛云
I.S3update(`user/${hashValue}.png`,newpath,res.locals.username);
I.S3update(`user/${hashValue}`,newpath,res.locals.username);
var UPDATE = `UPDATE user SET ? WHERE id=${res.locals.userid} LIMIT 1`;
var SET = {
'images':hashValue,
Expand Down Expand Up @@ -317,7 +317,13 @@ router.post('/set/userinfo', function (req, res) {
return;
}

res.cookie("token",I.GenerateJwt(res.locals["userid"],res.locals["username"],res.locals["nickname"]),{maxAge: 604800000,});
res.cookie("token",I.GenerateJwt({
userid: res.locals["userid"],
username: res.locals["username"],
nickname: res.locals["nickname"],
avatar: res.locals["avatar"],

}),{maxAge: 604800000,});
res.status(200).send( {'status': '个人信息修成成功'});
});

Expand Down
6 changes: 3 additions & 3 deletions server/router_scratch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var fs = require("fs");
var DB = require("./lib/database.js"); // 数据库

//功能函数集
var I = require("./lib/fuck.js");
var I = require("./lib/global.js");

router.all("*", function (req, res, next) {
next();
Expand Down Expand Up @@ -664,7 +664,7 @@ router.post("/getMyProjectLibrary", function (req, res) {
// 获取优秀作品列表
router.post("/getYxProjectLibrary", function (req, res) {
var SELECT =
` SELECT s.id, s.title, s.view_count, s.authorid, u.nickname FROM scratch s ` +
` SELECT s.id, s.title, s.view_count, s.authorid, u.nickname, u.images FROM scratch s ` +
" LEFT JOIN user u ON u.id=s.authorid " +
` WHERE s.state=2 ORDER BY s.view_count DESC LIMIT ${req.body.l},${req.body.n}`;
DB.query(SELECT, function (err, SCRATCH) {
Expand Down Expand Up @@ -902,7 +902,7 @@ router.post("/getSession", (req, res) => {
userid: parseInt(res.locals["userid"]),
username: res.locals["username"],
nickname: res.locals["nickname"],
avatar: `${process.env.S3staticurl}/user/${res.locals.userid}.png`,
avatar: `${process.env.S3staticurl}/user/${res.locals["avatar"]}`,
};
}

Expand Down
11 changes: 8 additions & 3 deletions server/router_user.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var jwt = require("jsonwebtoken");
//数据库
var DB = require("./lib/database.js");
//功能函数集
var I = require("./lib/fuck.js");
var I = require("./lib/global.js");
let cryptojs = require("crypto-js");
router.all("*", function (req, res, next) {
next();
Expand Down Expand Up @@ -140,15 +140,20 @@ router.post("/login", function (req, res) {
});
res.cookie(
"token",
I.GenerateJwt(User["id"], User["username"], User["nickname"]),
I.GenerateJwt({
userid: User["id"],
username: User["username"],
nickname: User["nickname"],
avatar: User["images"]
}),
{ maxAge: 604800000 }
);
res.status(200).send({
status: "OK",
userid: parseInt(User["id"]),
username: User["username"],
nickname: User["nickname"],
avatar: `/user/${User["id"]}.png`,
avatar: User["images"],
});
}
});
Expand Down
4 changes: 2 additions & 2 deletions views/404.ejs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<%- include('./html-head.ejs', {pageTitle: '首页'}); %>
<mdui-icon name='error'></mdui-icon><h1>404 此页面未找到</h1>
<h6>页面不存在或已被删除,请勿禁止,这与您的浏览器无关,您的设备运行正常</h6>
<h6>页面不存在或已被删除,无需紧张,这与您的设备及浏览器无关</h6>
<h6>如果由他人向您分享了此链接,请联系与您分享此链接的人</h6>
<h6>如果您认为此问题与OurWorld本身有关,请点击左上角横杠后点击反馈</h6><br/>
<h6>如果您认为此问题与OurWorld本身有关,请在左上角菜单中选择反馈</h6><br/>
<mdui-button href="/">首页</mdui-button>
<mdui-button onclick="window.history.go(-1);">返回上一页</mdui-button>

Expand Down
89 changes: 72 additions & 17 deletions views/html-footer.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -98,27 +98,82 @@ style="min-height: calc(100vh - 208px);min-width: 497px;width: 100%;border-radiu
S3staticurl = "<%= process.env.S3staticurl %>"
</script>
<!--<script src="https://registry.npmmirror.com/jwt-decode/4.0.0/files/build/cjs/index.js"></script>
<script src="https://registry.npmmirror.com/jwt-decode/4.0.0/files/build/cjs/index.js"></script>
<script>
function userinfo() {
const token = getCookie('token');
if (Cookies.get('token')){
try {
const token = Cookies.get('token');
const decoded = jwtDecode(token);
if (decoded && decoded.userid) {
$('#usernick').text(decoded.nickname);
$('#usernick').attr("href", "/user?id=" + decoded.userid);
$('#userbox').html('<img class=" md3botton mdui-img-fluid " src="/api/usertx?id=' + decoded.userid + '" style="pointer-events: none;" />')
$('#userbox').attr('mdui-menu', '{target: "#userlist"}');
$('#userbox').attr('class', 'mdui-btn mdui-btn-icon webkit-app-region-no mdui-hoverable mdui-ripple md3botton');
$('#userbox').attr('href', '#');
$('.ow-username').text(decoded.username);
$('.ow-userlink').attr("href", "/user?id=" + decoded.userid);
$('.ow-usernick').text(decoded.nickname);
$('.ow-userid').text(decoded.userid);
$('.ow-useravatar').attr("src", "/api/usertx?id=" + decoded.userid);
$('.ow-useravatar').attr("alt", decoded.nickname);
}
}
catch (error) {
console.log(error)
}
}}
$(function () {
userinfo()
function getCookie(name) {
const value = "; " + document.cookie;
const parts = value.split("; " + name + "=");
if (parts.length === 2) return parts.pop().split(";").shift();
}
</script>-->
})
</script>
<script>if (Cookies.get('token') == undefined) {
document.getElementById('user-drawer-list').innerHTML = '<mdui-list-item rounded href="/user/login">注册</mdui-list-item> <mdui-list-item rounded href="/user/login">登录</mdui-list-item><mdui-list-item rounded class="close-user" icon="arrow_left">关闭</mdui-list-item>' }
</script>
<script>
$(function () {
document.querySelector('mdui-navigation-rail').setAttribute('value', window.location.pathname);
const AddDialog = document.querySelector("#newproject");
const openAddButtons = document.querySelectorAll(".open-add");
openAddButtons.forEach(button => {
button.addEventListener("click", () => AddDialog.open = true);
});
const UserDrawer = document.querySelector(".user-drawer");
const openUserButton = document.querySelectorAll(".open-user");
const closeUserButton = document.querySelector(".close-user");
openUserButton.forEach(button => {
button.addEventListener("click", () => UserDrawer.open = true);
});
closeUserButton.addEventListener("click", () => UserDrawer.open = false);
const ToolsDrawer = document.querySelector(".tools-drawer");
const openToolsButton = document.querySelectorAll(".open-tools");
const closeToolsButton = document.querySelector(".close-tools");
openToolsButton.forEach(button => {
button.addEventListener("click", () => ToolsDrawer.open = true);
});
closeToolsButton.addEventListener("click", () => ToolsDrawer.open = false);
const SwitcDialog = document.querySelector(".switch-dialog");
const openanSwitcButton = document.querySelector(".open-switch");
openanSwitcButton.addEventListener("click", () => SwitcDialog.open = true);
const TypesDrawer = document.querySelector(".types-drawer");
const openTypesButton = document.querySelectorAll(".open-types");
const closeTypesButton = document.querySelector(".close-types");
openTypesButton.forEach(button => {
button.addEventListener("click", () => TypesDrawer.open = true);
});
closeTypesButton.addEventListener("click", () => TypesDrawer.open = false);
const FeedBackDialog = document.querySelector(".feedback-dialog");
const openanFeedBackButton = document.querySelector("#open-feedback-dialog");
openanFeedBackButton.addEventListener("click", () => FeedBackDialog.open = true);
});
</script>
</html>
Loading

0 comments on commit b767b66

Please sign in to comment.