Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
SunWuyuan committed Jun 24, 2024
1 parent 64f7cd2 commit baafded
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 37 deletions.
42 changes: 9 additions & 33 deletions server/router_user.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,9 @@ router.all("*", function (req, res, next) {
const request = require("request");
var nodemailer = require("nodemailer");
router.get("/", function (req, res) {
//获取已分享的作品总数:1:普通作品,2:推荐的优秀作品
var SQL =
`SELECT ` +
` (SELECT count(id) FROM scratch WHERE authorid=${req.query.id} AND state>0 ) AS scratch_count, ` +
` (SELECT count(id) FROM python WHERE authorid=${req.query.id} AND state>0 ) AS python_count `;
DB.query(SQL, function (err, data) {
if (err) {
// console.error('数据库操作出错:');
res.locals.scratch_count = 0;
res.locals.python_count = 0;
} else {
res.locals.scratch_count = data[0].scratch_count;
res.locals.python_count = data[0].python_count;
}
SQL = `SELECT id,display_name, motto FROM ow_Users WHERE id = ${req.query.id};`;

DB.query(SQL, function (err, USER) {
if (err || USER.length == 0) {
res.locals.tip = { opt: "flash", msg: "用户不存在" };
res.render("404.ejs");
return;
}
res.locals["user"] = USER[0];
//console.log(USER);
res.render("user.ejs");
});
});

});
//登录、注册、找回密码三合一界面
router.get("/login", function (req, res) {
Expand Down Expand Up @@ -153,7 +129,7 @@ router.post("/login", function (req, res) {
token,
{ maxAge: 604800000 }
);

res.status(200).send({
status: "OK",
userid: parseInt(User["id"]),
Expand Down Expand Up @@ -233,7 +209,7 @@ router.post("/register", function (req, res) {
//console.log(randonpw);
//console.log(email);

pw = I.hash(randonpw)
pw = I.hash(randonpw)
//console.log(pw);
//新用户注册 //loginInfo = [{'t': new Date(),'ip':req.ip,'agent':req.headers["user-agent"]}];
//var display_name = email.substring(email.length-5);
Expand All @@ -246,7 +222,7 @@ router.post("/register", function (req, res) {
res.status(200).send({ status: "再试一次17" });
return;
}
var userid = newUser.insertId;
var userid = newUser.insertId;

const transporter = nodemailer.createTransport({
service: process.env.mailservice, // 邮箱
Expand Down Expand Up @@ -322,7 +298,7 @@ router.post("/register", function (req, res) {
}
}
);

res.status(200).send({ status: "注册成功,请查看邮箱获取账户数据" });
});
});
Expand Down Expand Up @@ -507,9 +483,9 @@ router.get("/tuxiaochao", function (req, res) {
if (!process.env.txckey) {
res.redirect("https://support.qq.com/product/" + process.env.txcid);
}

SQL = `SELECT images FROM ow_Users WHERE id = ${res.locals["userid"]};`;

DB.query(SQL, function (err, USER) {
if (err || USER.length == 0) {
res.locals.tip = { opt: "flash", msg: "用户不存在" };
Expand All @@ -523,7 +499,7 @@ router.get("/tuxiaochao", function (req, res) {
process.env.S3staticurl+'/user/'+USER[0].images+
process.env.txckey;
var cryptostr = cryptojs.MD5(txcinfo).toString();

res.redirect(
"https://support.qq.com/product/" +
process.env.txcid +
Expand All @@ -537,7 +513,7 @@ router.get("/tuxiaochao", function (req, res) {
);

});

});

module.exports = router;
8 changes: 4 additions & 4 deletions views/user.ejs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%- include('html-head.ejs', {pageTitle: user.display_name + '的个人主页' }); %>
<%- include('html-head.ejs', {pageTitle: '用户个人主页' }); %>
<link rel="stylesheet" href="https://unpkg.com/@waline/client@v3/dist/waline.css" />


Expand Down Expand Up @@ -44,10 +44,10 @@
init({
el: "#waline",
serverURL: "<%= process.env.WalineServerURL %>",
path: "user-<%= user.id %>",
path: "user-"+getQueryString("id"),
copyright: false,
reaction: true,
pageview: true,
reaction: true,
pageview: true,
locale: {
reactionTitle: "发表下看法?",
},
Expand Down

0 comments on commit baafded

Please sign in to comment.